Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,14 @@ def _create_llm_span(
span, GenAIAttributes.GEN_AI_OPERATION_NAME, operation_name
)

# Detach any existing holder's token before creating the suppression
# token. The ordering matters: if we detach after attaching the
# suppression, ContextVar.reset() restores context to before the span,
# wiping the suppression flag and causing duplicate downstream spans.
existing_holder = self.spans.get(run_id)
if existing_holder is not None and existing_holder.token is not None:
self._safe_detach_context(existing_holder.token)

# we already have an LLM span by this point,
# so skip any downstream instrumentation from here
try:
Expand Down
Loading