File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments