You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 462e1b6
Browse filesBrowse the repository at this point in the historyBrowse files
fix: trace_id continuity and o11y alignment for BQ plugin (google#4645)
Fix trace_id fracture between INVOCATION_STARTING and AGENT_STARTING
when no ambient OTel span exists (e.g. Agent Engine, custom runners).
Also align BQ rows with Cloud Trace span IDs when o11y is active.
Changes:
- TraceManager.ensure_invocation_span(): ensures a root span is on the
plugin stack before any events fire, preventing early events from
falling back to invocation_id while later events get OTel hex IDs.
- TraceManager.push_span(): create child spans under existing stack
parent via trace.set_span_in_context() so all spans in an invocation
share the same trace_id (google#4645).
- _resolve_ids() replaces _resolve_span_ids(): 3-layer priority for
trace_id/span_id/parent_span_id resolution:
1. EventData overrides (post-pop callbacks)
2. Ambient OTel span (aligns with Cloud Trace when o11y is active)
3. Plugin's internal span stack (fallback for no-ambient paths)
- EventData.trace_id_override: captured before pop in after_run_callback
so INVOCATION_COMPLETED shares the same trace_id as earlier events.
- on_user_message_callback / before_run_callback: call
ensure_invocation_span() before logging.
- after_run_callback: capture trace_id before pop, pass as override.
Tests:
- TestTraceIdContinuity: 5 tests covering no-ambient, ambient,
cross-turn isolation, completion-event continuity, and full
callback-level integration.
- TestResolveIds: 6 tests replacing TestResolveSpanIds, adding
ambient priority and override-beats-ambient coverage.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
0 commit comments