Skip to content

Commit 7bd8455

Browse files
committed
fix: improve the check whether we are dealing with an AI span, using same logic as in Relay
1 parent 91776d8 commit 7bd8455

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

sentry_sdk/tracing.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,15 @@ def finish(
677677

678678
scope = scope or sentry_sdk.get_current_scope()
679679

680-
# Copy conversation_id from scope to span data if this is a gen_ai span
680+
# Copy conversation_id from scope to span data if this is an AI span
681681
conversation_id = scope.get_conversation_id()
682-
if conversation_id and any(key.startswith("gen_ai.") for key in self._data):
683-
self.set_data("gen_ai.conversation.id", conversation_id)
682+
if conversation_id:
683+
has_ai_op = "gen_ai.operation.name" in self._data
684+
is_ai_span_op = self.op is not None and (
685+
self.op.startswith("ai.") or self.op.startswith("gen_ai.")
686+
)
687+
if has_ai_op or is_ai_span_op:
688+
self.set_data("gen_ai.conversation.id", conversation_id)
684689

685690
maybe_create_breadcrumbs_from_span(scope, self)
686691

0 commit comments

Comments
 (0)