Skip to content

fix(telemetry): preserve span kinds in SQLite traces - #7504

Open
BichengWang wants to merge 1 commit into
google:mainfrom
BichengWang:BichengWang/pr-round-span-kind-20261011
Open

BichengWang wants to merge 1 commit into
google:mainfrom
BichengWang:BichengWang/pr-round-span-kind-20261011

Conversation

@BichengWang

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

Problem: SQLite trace export drops ReadableSpan.kind. A real OpenTelemetry SDK CLIENT span is reconstructed as INTERNAL after the exporter is shut down and reopened. SERVER, PRODUCER and CONSUMER spans lose their kind as well. This changes persisted tracing semantics, not just the in-memory representation.

Expected: Preserve each span kind across SQLite export and exporter restart.

Solution: Persist the SpanKind name in a non-null column and reconstruct the enum on read. Existing nine-column databases are upgraded in place, with INTERNAL as the historical default; old span rows are retained. Serialize the schema check/add transaction so independent constructors do not race the additive migration. The API docstring documents the upgrade behavior.

Scope: Kind persistence only. Status/events persistence is already addressed by #7486; this PR does not duplicate that change or claim to close #7484. No provider calls or new dependencies.

Testing Plan

Unit Tests:

  • Added regressions for all four non-INTERNAL kinds across exporter restart and for a legacy database retaining original spans while accepting new CLIENT spans.
  • Against upstream main at bca4a425b1b0abccddf8af26735773394a808427: 2 failed, 16 deselected, with actual kind mismatches.
  • SQLite exporter file after the fix: 18 passed.
  • Entire tests/unittests/telemetry suite after formatting: 878 passed, 7 xfailed, no failures. The repository-wide unit suite was not run.
  • Required pre-commit checks on both changed files: passed. Applicable formatters, import sorting, compliance, documentation links, spelling and hygiene hooks passed; no-file hooks skipped.

Manual End-to-End (E2E):
Use an isolated temporary SQLite file, a real TracerProvider with SimpleSpanProcessor and SqliteSpanExporter, and a span with SpanKind.CLIENT plus session_id synthetic-session. Shut the provider/exporter down, reopen the same file with SqliteSpanExporter, and call get_all_spans_for_session.

Observed before:

{"expectedKind":"CLIENT","reloadedKind":"INTERNAL","name":"local-http-request","session":"synthetic-session"}

Observed after:

{"expectedKind":"CLIENT","reloadedKind":"CLIENT","name":"local-http-request","session":"synthetic-session"}

Environment: macOS arm64, Python 3.13.7, OpenTelemetry SDK 1.42.1. No external model/network requests. This exercises the SQLite exporter itself; adk web uses a different in-memory exporter, so no web-UI proof is claimed.

Checklist

  • Read CONTRIBUTING.md and repository contribution skills.
  • Self-reviewed the change and documented compatibility behavior.
  • Added tests proving the fix is effective.
  • New and existing tests in the affected telemetry subsystem pass locally.
  • Manually exercised the changed path with the real SDK and persisted SQLite file.
  • No dependent downstream changes are required.

Additional context

Historical kinds cannot be recovered for already-saved spans; the migration explicitly retains INTERNAL for those rows. Changelog generation is left to release-please via the conventional fix(telemetry) commit. No historical release entry is edited.

Additional real-SQLite smoke: two simultaneous exporter constructors upgraded the same legacy database, both retained its original INTERNAL span, and the kind column was added exactly once.

{"concurrentLegacyInitializers": 2, "legacySpanPreserved": true, "legacyDefaultKind": "INTERNAL", "kindColumnAddedOnce": true}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SqliteSpanExporter drops a span's status and events, so an exception that ended a run is lost (2.11.0)

2 participants