-
Notifications
You must be signed in to change notification settings - Fork 565
fix(openai-agents): also emit spans for MCP tool calls done by the LLM #4875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
6cb7b43
96df8c1
99b1ddb
b219cd8
3012e3a
94a3695
5802750
c485fde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import sentry_sdk | ||
from sentry_sdk.ai.utils import set_data_normalized | ||
from sentry_sdk.consts import SPANDATA | ||
from sentry_sdk.consts import SPANDATA, SPANSTATUS, OP | ||
from sentry_sdk.integrations import DidNotEnable | ||
from sentry_sdk.scope import should_send_default_pii | ||
from sentry_sdk.tracing_utils import set_span_errored | ||
|
@@ -156,3 +156,23 @@ def _set_output_data(span, result): | |
set_data_normalized( | ||
span, SPANDATA.GEN_AI_RESPONSE_TEXT, output_messages["response"] | ||
) | ||
|
||
|
||
def _create_mcp_execute_tool_spans(span, result): | ||
# type: (sentry_sdk.tracing.Span, agents.Result) -> None | ||
for output in result.output: | ||
if output.__class__.__name__ == "McpCall": | ||
with sentry_sdk.start_span( | ||
op=OP.GEN_AI_EXECUTE_TOOL, | ||
description=f"execute_tool {output.name}", | ||
start_timestamp=span.start_timestamp, | ||
) as execute_tool_span: | ||
execute_tool_span.set_tag(SPANDATA.GEN_AI_TOOL_TYPE, "mcp") | ||
execute_tool_span.set_tag(SPANDATA.GEN_AI_TOOL_NAME, output.name) | ||
if should_send_default_pii(): | ||
execute_tool_span.set_data( | ||
SPANDATA.GEN_AI_TOOL_INPUT, output.arguments | ||
) | ||
span.set_data(SPANDATA.GEN_AI_TOOL_OUTPUT, output.output) | ||
constantinius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if output.error: | ||
execute_tool_span.set_status(SPANSTATUS.ERROR) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: MCP Tool Spans Lack Agent Context DataThe Additional Locations (1) |
Uh oh!
There was an error while loading. Please reload this page.