Conversation
…nt span The workflow outbound interceptor marked the temporal:startActivity, temporal:startChildWorkflow, and temporal:startLocalActivity spans current so the outbound header could capture them, and never restored the previous span. Spans created later in the same context, such as the tool calls that follow a model call within an agent turn, were parented to them. Make the span current only while the header is captured; it still stays open until the handle completes.
Contributor
Author
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.
In a workflow-hosted agent loop, spans created after a model call within the same turn (tool calls, handoffs, guardrails) appeared nested under the model call's
temporal:startActivityspan instead of as siblings under the turn, in both the OpenAI platform and OpenTelemetry tracing modes. The workflow outbound interceptor started that span withmark_as_current=Trueso the outbound header could capture its id, and nothing restored the previous current span; the done callback only finishes the span, and it may run in a different contextvars context, so resetting there is not safe. This change makes the span current only while the header is captured, using the Agents SDK's set/reset token pair, and still leaves it open until the handle completes. The same applies totemporal:startChildWorkflowandtemporal:startLocalActivity. Adds a tracing test with one tool call that fails without the fix and passes with it; the existing tracing tests still pass.Fixes #1855