Conversation
Adds span streaming support to the httpx integration by adding a new
code path that uses `start_span` from `sentry_sdk.traces` when
`_experiments={"trace_lifecycle": "stream"}` is enabled. The existing
legacy path is preserved unchanged.
Test coverage is updated to:
- Rename span-data-asserting tests with a `_legacy` suffix
- Fix broken mock targets in duration threshold tests (`start_span` →
`legacy_start_span` after the rename introduced two names)
- Add `_span_streaming` variants for all tests that assert on span data,
using `capture_items("span")` and `span["attributes"]` instead of
`event["spans"][*]["data"]`
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 8.92s All tests are passing successfully. ❌ Patch coverage is 2.86%. Project has 15091 uncovered lines. Files with missing lines (3)
Generated by Codecov Action |
Codecov Results 📊Generated by Codecov Action |
|
bugbot run |
There was a problem hiding this comment.
TY! Left some comments, the gist:
- Any attributes we set on the span in streaming mode need to be in Sentry Conventions. I've tried to point out some that need changing but please go through the rest too and double check 🙏🏻
- I'd remove all of the
start_timestamp_monotonic_mschanges. I don't really see the benefit over just using thestart_timestampand removing it makes the new and oldadd_http_request_sourcesimilar enough that we can unify them.
Remove start_timestamp_monotonic_ns from StreamedSpan and NoOpStreamedSpan, and simplify the end timestamp fallback in add_http_request_source to use datetime.now(timezone.utc) directly. The monotonic-based calculation added complexity without meaningful benefit over the UTC fallback. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 19eeac5. Configure here.
| # Needs to happen within the context manager as we want to attach the | ||
| # final data before the span finishes and is sent for ingesting. | ||
| with capture_internal_exceptions(): | ||
| add_http_request_source(streamed_span) |
There was a problem hiding this comment.
URL attributes lost on request exception in streaming path
Medium Severity
In the streaming span path, URL-related attributes (url.full, url.query, url.fragment) are accumulated in a local attributes dict but only flushed to the span via streamed_span.set_attributes(attributes) after real_send completes. If real_send raises an exception, the __exit__ handler fires and the span ends without those attributes ever being set, losing known-before-request URL metadata. The legacy path doesn't have this problem because it calls span.set_data() for URL info before the request is made. The same issue exists in both the sync and async client paths.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 19eeac5. Configure here.


Migrates the httpx integration to the span-first (streaming span) architecture.
When
_experiments={"trace_lifecycle": "stream"}is enabled, the integrationnow uses
StreamedSpanviasentry_sdk.traces.start_spaninstead of the legacySpan-based (transactions) path. The legacy path remains unchanged for backwards compatibility.Supporting changes:
add_http_request_source_for_streamed_span()added totracing_utils— aStreamedSpan-compatible variant that must be called inside the span contextmanager so source data is attached before the span is flushed
add_source()updated to dispatch betweenset_data/set_attributedependingon span type
start_timestamp_monotonic_nsproperty added toStreamedSpanandNoOpStreamedSpanto support the request source duration threshold checkPart of the broader span-first integration migration.
Fixes PY-2330
Fixes #6028