Skip to content

Conversation

@sentrivana
Copy link
Contributor

@sentrivana sentrivana commented Jan 15, 2026

Introduce a new start_span() API with a simpler and more intuitive signature to eventually replace the original start_span() and start_transaction() APIs.

Additionally, introduce a new streaming mode (sentry_sdk.init(_experiments={"trace_lifecycle": "stream"})) that will send spans as they finish, rather than by transaction.

import sentry_sdk

sentry_sdk.init(
    _experiments={"trace_lifecycle": "stream"},
)

with sentry_sdk.traces.start_span(name="my_span"):
    ...

The new API MUST be used with the new streaming mode, and the old API MUST be used in the legacy non-streaming (static) mode.

Migration guide: getsentry/sentry-docs#16072

Notes

  • The diff is huge mostly because I've optimized for easy removal of legacy code in the next major, deliberately duplicating a lot. I'll of course split it up to reviewable PRs once ready.
    • Chose to go with a new file and a new span class so that we can just remove the old Span and drop the new StreamedSpan in tracing.py as a replacement.
  • The batcher for spans is a bit different from the logs and metrics batchers because it needs to batch by trace_id (we can't send spans from different traces in the same envelope).

Release Plan

  • There will be prereleases for internal testing.
  • We'll release the new API in a minor version as opt-in.
  • In the next major, we'll drop the legacy API.

Project

https://linear.app/getsentry/project/span-first-sdk-python-727da28dd037/overview

@github-actions
Copy link
Contributor

github-actions bot commented Jan 15, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

Span Streaming

  • fix(span-streaming): Always preserialize attributes by sentrivana in #5407
  • fix(span-streaming): Warn about thread usage if any batcher is active by sentrivana in #5408

Other

  • fix(anthropic): Token reporting by alexander-alderman-webb in #5403
  • fix(openai): Token reporting by alexander-alderman-webb in #5406
  • fix(openai-agents): Inject propagation headers for HostedMCPTool when streaming by alexander-alderman-webb in #5405
  • fix: Adapt to new packaging in toxgen by sentrivana in #5382

Internal Changes 🔧

Fastmcp

  • test(fastmcp): Wrap prompt in Message by alexander-alderman-webb in #5411
  • test(fastmcp): Remove test_fastmcp_without_request_context() by alexander-alderman-webb in #5412
  • test(fastmcp): Use AsyncClient for SSE by alexander-alderman-webb in #5400
  • test(fastmcp): Use TestClient for Streamable HTTP by alexander-alderman-webb in #5384
  • test(fastmcp): Simulate stdio transport with memory streams by alexander-alderman-webb in #5333

Mcp

  • test(mcp): Use AsyncClient for SSE by alexander-alderman-webb in #5396
  • test(mcp): Use TestClient for Streamable HTTP by alexander-alderman-webb in #5383
  • test(mcp): Remove unused stdio helpers by alexander-alderman-webb in #5409

Other

  • ci: 🤖 Update test matrix with new releases (02/02) by github-actions in #5413
  • ci: Update tox and pin packaging version for tox by alexander-alderman-webb in #5381

Other

  • [do not merge] feat: Span streaming & new span API by sentrivana in #5317

🤖 This preview updates automatically when you update the PR.

sentrivana added a commit that referenced this pull request Jan 30, 2026
…5397)

- Add a new experimental `trace_lifecycle` option (used in follow up PRs)
- Add a new util function for checking which mode the SDK is in

Chipping away at #5317 to
transform it into reviewable and mergeable PRs.
sentrivana added a commit that referenced this pull request Feb 2, 2026
- Add a specialized `SpanBatcher` that batches and sends spans by trace
ID. Hook it up to the client.
- Add a skeleton of a new `StreamedSpan` class that will eventually
replace the current `Span` class.

Chipping away at #5317 to
transform it into reviewable and mergeable PRs.
sentrivana added a commit that referenced this pull request Feb 2, 2026
…and attributes (#5399)

- Add streamed spans to telemetry pipeline
- Add attributes and associated API to `StreamedSpan` since they're used
in the pipeline
- Add span name too, to round up the basic span API

Chipping away at #5317 to
transform it into reviewable and mergeable PRs.
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.

2 participants