Skip to content

feat(mcp): Migrate to span first#6131

Merged
ericapisani merged 6 commits intomasterfrom
ep/py-2340-mcp-span-first-84l
Apr 27, 2026
Merged

feat(mcp): Migrate to span first#6131
ericapisani merged 6 commits intomasterfrom
ep/py-2340-mcp-span-first-84l

Conversation

@ericapisani
Copy link
Copy Markdown
Member

@ericapisani ericapisani commented Apr 23, 2026

Add span streaming support to the MCP integration.

Refs PY-2340
Fixes #6038

Add span streaming support to the MCP integration. When span streaming
is enabled, start spans via sentry_sdk.traces.start_span and set data
via set_attribute; otherwise fall back to the existing transaction-based
flow and set_data.

Introduce _set_span_data_attribute in sentry_sdk.ai.utils to branch on
StreamedSpan vs Span so handlers can write attributes uniformly in both
modes.

Refs PY-2340
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Apr 23, 2026

@ericapisani ericapisani marked this pull request as ready for review April 23, 2026 19:06
@ericapisani ericapisani requested a review from a team as a code owner April 23, 2026 19:06
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

Codecov Results 📊

5 passed | Total: 5 | Pass Rate: 100% | Execution Time: 1.09s

All tests are passing successfully.

❌ Patch coverage is 12.50%. Project has 17018 uncovered lines.

Files with missing lines (1)
File Patch % Lines
mcp.py 5.86% ⚠️ 257 Missing

Generated by Codecov Action

Comment thread sentry_sdk/ai/utils.py
Comment thread tests/integrations/mcp/test_mcp.py
Comment thread tests/integrations/mcp/test_mcp.py
ericapisani and others added 2 commits April 24, 2026 09:49
The non-streaming branches of test_prompt_handler_with_error and
test_resource_handler_with_error only verified error-event fields,
leaving span status and transaction shape unchecked. Mirror the
streaming-branch assertions and the tool-handler test pattern so
regressions in classic-mode error handling for prompts and resources
are caught.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@alexander-alderman-webb alexander-alderman-webb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👌

@ericapisani ericapisani merged commit 7f0f463 into master Apr 27, 2026
166 of 168 checks passed
@ericapisani ericapisani deleted the ep/py-2340-mcp-span-first-84l branch April 27, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate mcp to span first

2 participants