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).


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

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 2026

Codecov Results 📊

118 passed | Total: 118 | Pass Rate: 100% | Execution Time: 20.47s

All tests are passing successfully.

❌ Patch coverage is 19.66%. Project has 13950 uncovered lines.

Files with missing lines (179)
File Patch % Lines
langchain.py 3.28% ⚠️ 590 Missing
utils.py 51.75% ⚠️ 441 Missing and 84 partials
tracing_utils.py 31.87% ⚠️ 481 Missing and 31 partials
scope.py 60.09% ⚠️ 350 Missing and 73 partials
__init__.py 5.28% ⚠️ 377 Missing
starlette.py 5.26% ⚠️ 360 Missing
transport.py 23.54% ⚠️ 302 Missing and 2 partials
client.py 55.58% ⚠️ 223 Missing and 60 partials
__init__.py 3.26% ⚠️ 267 Missing
mcp.py 4.85% ⚠️ 255 Missing
transaction_profiler.py 35.52% ⚠️ 216 Missing and 10 partials
strawberry.py 8.02% ⚠️ 218 Missing
langgraph.py 5.29% ⚠️ 215 Missing
span_processor.py 0.00% ⚠️ 205 Missing
traces.py 25.64% ⚠️ 203 Missing
tracing.py 69.47% ⚠️ 145 Missing and 49 partials
continuous_profiler.py 43.45% ⚠️ 177 Missing and 17 partials
aws_lambda.py 16.50% ⚠️ 167 Missing
spark_driver.py 0.00% ⚠️ 166 Missing
sanic.py 9.60% ⚠️ 160 Missing
rust_tracing.py 0.00% ⚠️ 159 Missing
aiohttp.py 10.84% ⚠️ 148 Missing
cloud_resource_context.py 0.00% ⚠️ 145 Missing
ai_client.py 0.00% ⚠️ 145 Missing
utils.py 81.22% ⚠️ 89 Missing and 54 partials
litellm.py 0.00% ⚠️ 138 Missing
litestar.py 9.59% ⚠️ 132 Missing
starlite.py 8.33% ⚠️ 132 Missing
envelope.py 40.40% ⚠️ 118 Missing and 11 partials
asgi.py 19.50% ⚠️ 128 Missing
stdlib.py 33.33% ⚠️ 122 Missing and 5 partials
utils.py 67.92% ⚠️ 85 Missing and 29 partials
falcon.py 8.94% ⚠️ 112 Missing
flask.py 12.50% ⚠️ 112 Missing
spotlight.py 28.47% ⚠️ 103 Missing and 8 partials
cohere.py 12.70% ⚠️ 110 Missing
dramatiq.py 0.00% ⚠️ 110 Missing
agent_run.py 0.00% ⚠️ 110 Missing
arq.py 9.92% ⚠️ 109 Missing
asgi.py 0.00% ⚠️ 109 Missing
hub.py 45.60% ⚠️ 105 Missing and 3 partials
pymongo.py 10.17% ⚠️ 106 Missing
beat.py 8.62% ⚠️ 106 Missing
caching.py 0.00% ⚠️ 106 Missing
asyncpg.py 11.86% ⚠️ 104 Missing
utils.py 0.00% ⚠️ 103 Missing
templates.py 0.00% ⚠️ 100 Missing
utils.py 13.79% ⚠️ 100 Missing
quart.py 16.10% ⚠️ 99 Missing
wsgi.py 22.66% ⚠️ 99 Missing
gcp.py 0.00% ⚠️ 98 Missing
otlp.py 0.00% ⚠️ 97 Missing
sessions.py 27.82% ⚠️ 96 Missing
pyramid.py 13.76% ⚠️ 94 Missing
tornado.py 14.55% ⚠️ 94 Missing
__init__.py 0.00% ⚠️ 93 Missing
openai.py 90.10% ⚠️ 51 Missing and 41 partials
models.py 5.15% ⚠️ 92 Missing
_wsgi_common.py 28.35% ⚠️ 91 Missing
bottle.py 11.65% ⚠️ 91 Missing
middleware.py 0.00% ⚠️ 90 Missing
agent_run.py 0.00% ⚠️ 90 Missing
beam.py 0.00% ⚠️ 84 Missing
logging.py 52.29% ⚠️ 73 Missing and 11 partials
loguru.py 11.58% ⚠️ 84 Missing
ray.py 0.00% ⚠️ 84 Missing
__init__.py 64.02% ⚠️ 77 Missing and 5 partials
asyncio.py 0.00% ⚠️ 80 Missing
invoke_agent.py 0.00% ⚠️ 79 Missing
runner.py 0.00% ⚠️ 77 Missing
session.py 15.56% ⚠️ 76 Missing
clickhouse_driver.py 17.58% ⚠️ 75 Missing
sqlalchemy.py 10.71% ⚠️ 75 Missing
graphene.py 12.94% ⚠️ 74 Missing
pure_eval.py 0.00% ⚠️ 73 Missing
worker.py 22.58% ⚠️ 72 Missing
ariadne.py 14.46% ⚠️ 71 Missing
gql.py 10.13% ⚠️ 71 Missing
fastapi.py 15.85% ⚠️ 69 Missing
transactions.py 0.00% ⚠️ 67 Missing
_queue.py 26.67% ⚠️ 66 Missing
rq.py 15.38% ⚠️ 66 Missing
huey.py 17.72% ⚠️ 65 Missing
api.py 58.82% ⚠️ 63 Missing
boto3.py 14.86% ⚠️ 63 Missing
utils.py 16.00% ⚠️ 63 Missing
chalice.py 16.18% ⚠️ 57 Missing
httpx.py 52.34% ⚠️ 51 Missing and 6 partials
propagator.py 0.00% ⚠️ 57 Missing
server.py 0.00% ⚠️ 56 Missing
spark_worker.py 0.00% ⚠️ 56 Missing
monitoring.py 39.53% ⚠️ 52 Missing and 2 partials
graph_nodes.py 0.00% ⚠️ 52 Missing
gnu_backtrace.py 0.00% ⚠️ 51 Missing
_async_common.py 0.00% ⚠️ 51 Missing
socket.py 0.00% ⚠️ 50 Missing
views.py 0.00% ⚠️ 50 Missing
tools.py 0.00% ⚠️ 49 Missing
caches.py 16.95% ⚠️ 49 Missing
_batcher.py 41.25% ⚠️ 47 Missing
_asgi_common.py 16.67% ⚠️ 45 Missing
signals_handlers.py 0.00% ⚠️ 44 Missing
anthropic.py 91.70% ⚠️ 22 Missing and 21 partials
invoke_agent.py 0.00% ⚠️ 43 Missing
utils.py 22.22% ⚠️ 42 Missing and 1 partials
_span_batcher.py 32.26% ⚠️ 42 Missing
threading.py 62.11% ⚠️ 36 Missing and 6 partials
client.py 0.00% ⚠️ 40 Missing
_sync_common.py 22.00% ⚠️ 39 Missing
executing.py 0.00% ⚠️ 38 Missing
client.py 0.00% ⚠️ 38 Missing
serializer.py 86.02% ⚠️ 26 Missing and 11 partials
serverless.py 0.00% ⚠️ 36 Missing
server.py 0.00% ⚠️ 35 Missing
huggingface_hub.py 95.29% ⚠️ 9 Missing and 24 partials
sys_exit.py 0.00% ⚠️ 32 Missing
launchdarkly.py 0.00% ⚠️ 31 Missing
trytond.py 0.00% ⚠️ 30 Missing
tools.py 0.00% ⚠️ 30 Missing
integration.py 0.00% ⚠️ 30 Missing
error_tracing.py 0.00% ⚠️ 29 Missing
scrubber.py 76.81% ⚠️ 16 Missing and 10 partials
redis_cluster.py 26.47% ⚠️ 25 Missing
_werkzeug.py 11.11% ⚠️ 24 Missing
typer.py 0.00% ⚠️ 24 Missing
tasks.py 0.00% ⚠️ 24 Missing
_compat.py 41.03% ⚠️ 23 Missing
__init__.py 84.78% ⚠️ 14 Missing and 9 partials
statsig.py 0.00% ⚠️ 23 Missing
execute_tool.py 0.00% ⚠️ 23 Missing
queries.py 25.81% ⚠️ 23 Missing
logger.py 43.59% ⚠️ 22 Missing
decorator.py 37.14% ⚠️ 22 Missing
ai_client.py 15.38% ⚠️ 22 Missing
_log_batcher.py 0.00% ⚠️ 21 Missing
attachments.py 27.59% ⚠️ 21 Missing
unraisablehook.py 0.00% ⚠️ 21 Missing
__init__.py 8.70% ⚠️ 21 Missing
openfeature.py 0.00% ⚠️ 20 Missing
execute_tool.py 0.00% ⚠️ 20 Missing
unleash.py 0.00% ⚠️ 19 Missing
_lru_cache.py 43.33% ⚠️ 17 Missing and 1 partials
monitor.py 80.33% ⚠️ 12 Missing and 6 partials
streaming.py 93.33% ⚠️ 4 Missing and 14 partials
model_request.py 0.00% ⚠️ 18 Missing
utils.py 0.00% ⚠️ 16 Missing
atexit.py 56.25% ⚠️ 14 Missing and 1 partials
excepthook.py 56.25% ⚠️ 14 Missing and 1 partials
redis.py 25.00% ⚠️ 15 Missing
feature_flags.py 56.25% ⚠️ 14 Missing
_init_implementation.py 45.83% ⚠️ 13 Missing
dedupe.py 77.50% ⚠️ 9 Missing and 4 partials
__init__.py 27.78% ⚠️ 13 Missing
types.py 0.00% ⚠️ 12 Missing
redis_py_cluster_legacy.py 26.67% ⚠️ 11 Missing
_types.py 66.67% ⚠️ 10 Missing
api.py 37.50% ⚠️ 10 Missing
utils.py 41.18% ⚠️ 10 Missing
metrics.py 47.06% ⚠️ 9 Missing
__init__.py 72.41% ⚠️ 8 Missing and 1 partials
_metrics_batcher.py 65.00% ⚠️ 7 Missing
_openai_completions_api.py 91.30% ⚠️ 2 Missing and 5 partials
handoff.py 0.00% ⚠️ 7 Missing
consts.py 0.00% ⚠️ 7 Missing
rb.py 30.00% ⚠️ 7 Missing
debug.py 91.30% ⚠️ 2 Missing and 2 partials
__init__.py 20.00% ⚠️ 4 Missing
__init__.py 0.00% ⚠️ 4 Missing
__init__.py 0.00% ⚠️ 3 Missing
__init__.py 40.00% ⚠️ 3 Missing
__init__.py 0.00% ⚠️ 3 Missing
__init__.py 0.00% ⚠️ 3 Missing
__init__.py 0.00% ⚠️ 3 Missing
consts.py 99.43% ⚠️ 2 Missing
argv.py 100.00% ⚠️ 2 partials
modules.py 94.12% ⚠️ 1 Missing and 1 partials
agent_workflow.py 71.43% ⚠️ 2 Missing
consts.py 0.00% ⚠️ 1 Missing
consts.py 0.00% ⚠️ 1 Missing

Generated by Codecov Action

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.
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