Skip to content

Commit 96df8c1

Browse files
committed
fix(openai-agents): improve span handling in MCP tool execution
1 parent 6cb7b43 commit 96df8c1

File tree

1 file changed

+7
-5
lines changed
  • sentry_sdk/integrations/openai_agents

1 file changed

+7
-5
lines changed

sentry_sdk/integrations/openai_agents/utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,13 @@ def _create_mcp_execute_tool_spans(span, result):
166166
op=OP.GEN_AI_EXECUTE_TOOL,
167167
description=f"execute_tool {output.name}",
168168
start_timestamp=span.start_timestamp,
169-
) as span:
170-
span.set_tag(SPANDATA.GEN_AI_TOOL_TYPE, "mcp")
171-
span.set_tag(SPANDATA.GEN_AI_TOOL_NAME, output.name)
169+
) as execute_tool_span:
170+
execute_tool_span.set_tag(SPANDATA.GEN_AI_TOOL_TYPE, "mcp")
171+
execute_tool_span.set_tag(SPANDATA.GEN_AI_TOOL_NAME, output.name)
172172
if should_send_default_pii():
173-
span.set_data(SPANDATA.GEN_AI_TOOL_INPUT, output.arguments)
173+
execute_tool_span.set_data(
174+
SPANDATA.GEN_AI_TOOL_INPUT, output.arguments
175+
)
174176
span.set_data(SPANDATA.GEN_AI_TOOL_OUTPUT, output.output)
175177
if output.error:
176-
span.set_status(SPANSTATUS.ERROR)
178+
execute_tool_span.set_status(SPANSTATUS.ERROR)

0 commit comments

Comments
 (0)