-
Notifications
You must be signed in to change notification settings - Fork 572
feat(integration): add gen_ai.conversation.id if available
#5307
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
base: master
Are you sure you want to change the base?
feat(integration): add gen_ai.conversation.id if available
#5307
Conversation
…_ai.conversation.id`
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Documentation 📚
Internal Changes 🔧Release
Other
🤖 This preview updates automatically when you update the PR. |
| ) | ||
|
|
||
| _set_response_model_on_agent_span(agent, response_model) | ||
| update_ai_client_span(span, streaming_response, agent=agent) | ||
| finally: | ||
| span.__exit__(*sys.exc_info()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The _sentry_conversation_id is not propagated to secondary agents during handoffs, causing subsequent spans for that agent to lack the conversation ID and breaking trace continuity.
Severity: HIGH
Suggested Fix
Propagate the _sentry_conversation_id to handoff agents before they are executed. This could be achieved by setting the attribute on the handoff agent object before it is used in _run_single_turn, or by storing the conversation_id in a context that persists across handoffs, ensuring all agents in the chain have access to it.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: sentry_sdk/integrations/openai_agents/patches/models.py#L119-L124
Potential issue: The `_sentry_conversation_id` attribute is set on the initial agent at
the start of an execution run. However, when this agent hands off control to a secondary
agent, the `_sentry_conversation_id` is not propagated. As a result, any subsequent
spans created for the secondary agent, such as `invoke_agent_span`, `ai_client_span`,
and `execute_tool_span`, will be missing the conversation ID. This leads to incomplete
trace data, as the spans from the secondary agent cannot be linked to the overall
conversation.
Did we get this right? 👍 / 👎 to inform future reviews.
Description
Closes https://linear.app/getsentry/issue/TET-1721/openai-agents-add-gen-aiconversationid