fix(voice): read rootSpanContext live in AudioRecognition#1246
Draft
mrniket wants to merge 4 commits intolivekit:mainfrom
Draft
fix(voice): read rootSpanContext live in AudioRecognition#1246mrniket wants to merge 4 commits intolivekit:mainfrom
mrniket wants to merge 4 commits intolivekit:mainfrom
Conversation
|
53f7c12 to
a9f8057
Compare
Honour otelContext.active() when starting the agent_session span and when building rootSpanContext, so spans the caller created before session.start() become parents of LiveKit spans. Stop calling tracerProvider.register() in setupCloudTracer to avoid replacing the global AsyncLocalStorageContextManager. Fixes livekit#924
register() uses set-once semantics in the OTel API — if a user already called NodeSDK.start(), both the context manager and global provider registrations are safe no-ops. Removing it broke cloud-only users who have no pre-existing OTel setup.
…ng provider Adds contract tests confirming that setupCloudTracer's tracerProvider.register() call is a safe no-op when a user has already registered their own OTel provider via NodeSDK.start(): the user's global context manager and provider are preserved, user spans continue exporting to the user's exporter, and LiveKit spans correctly nest as children of user parent spans via the shared context manager.
AudioRecognition was snapshotting rootSpanContext at construction time, so any mutation of session.rootSpanContext after _startSession (e.g. in an Agent.onEnter hook) was invisible to user_turn spans. Store a live reference to the AgentSession instead, and read rootSpanContext fresh on each span creation. Fixes livekit#924
a9f8057 to
c4333ce
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AudioRecognition was snapshotting
rootSpanContextat construction time,so any mutation of
session.rootSpanContextafter_startSession(e.g. inan
Agent.onEnterhook) was invisible touser_turnspans. This stores alive reference to the
AgentSessioninstead, and readsrootSpanContextfresh on each span creation.
Fixes #924
Changes
audio_recognition.ts: ReplacerootSpanContextsnapshot field with alive
agentSessionreference.ensureUserTurnSpananduserTurnContextnow read
this.agentSession?.rootSpanContexton every call.agent_activity.ts: PassagentSession: this.agentSessionto theAudioRecognitionconstructor instead of the snapshottedrootSpanContext: this.agentSession.rootSpanContext.Test plan
audio_recognition_span.test.ts(4 tests) passes — it constructsAudioRecognitionwithout anagentSession, so the?.fallback toundefinedpreserves current behavior.pnpm test,pnpm lint,pnpm format:checkall pass.