Skip to content

feat(httpx): Migrate to span first#6084

Open
ericapisani wants to merge 4 commits intomasterfrom
ep/span-first-httpx-c35
Open

feat(httpx): Migrate to span first#6084
ericapisani wants to merge 4 commits intomasterfrom
ep/span-first-httpx-c35

Conversation

@ericapisani
Copy link
Copy Markdown
Member

@ericapisani ericapisani commented Apr 16, 2026

Migrates the httpx integration to the span-first (streaming span) architecture.

When _experiments={"trace_lifecycle": "stream"} is enabled, the integration
now uses StreamedSpan via sentry_sdk.traces.start_span instead of the legacy
Span-based (transactions) path. The legacy path remains unchanged for backwards compatibility.

Supporting changes:

  • add_http_request_source_for_streamed_span() added to tracing_utils — a
    StreamedSpan-compatible variant that must be called inside the span context
    manager so source data is attached before the span is flushed
  • add_source() updated to dispatch between set_data/set_attribute depending
    on span type
  • start_timestamp_monotonic_ns property added to StreamedSpan and
    NoOpStreamedSpan to support the request source duration threshold check

Part of the broader span-first integration migration.

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>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 16, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

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


New Features ✨

  • (ci) Cancel in-progress PR workflows on new commit push by joshuarli in #5994
  • (httpx) Migrate to span first by ericapisani in #6084
  • Add db.driver.name spans to database integrations by ericapisani in #6082

Bug Fixes 🐛

  • (google_genai) Redact binary data in inline_data and fix multi-part message extraction by ericapisani in #5977
  • (grpc) Add isolation_scope to async server interceptor by robinvd in #5940
  • (profiler) Stop nulling buffer on teardown by ericapisani in #6075

Internal Changes 🔧

  • (celery) Remove unused NoOpMgr from utils by sentrivana in #6078
  • (pydantic-ai) Remove dead Model.request patch by alexander-alderman-webb in #5956
  • (tests) Replace deprecated enable_tracingwith traces_sample_rate by sentrivana in #6077
  • Set explicit base-branch for codecov action by ericapisani in #5992

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 16, 2026

Codecov Results 📊

13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 12.80s

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 7.56%. Project has 15103 uncovered lines.
❌ Project coverage is 29.55%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
tracing_utils.py 36.64% ⚠️ 486 Missing and 28 partials
traces.py 36.77% ⚠️ 196 Missing
httpx.py 11.21% ⚠️ 103 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    29.61%    29.55%    -0.06%
==========================================
  Files          190       190         —
  Lines        21365     21437       +72
  Branches      7068      7108       +40
==========================================
+ Hits          6327      6334        +7
- Misses       15038     15103       +65
- Partials       477       477         —

Generated by Codecov Action

@github-actions
Copy link
Copy Markdown
Contributor

Codecov Results 📊


Generated by Codecov Action

@ericapisani
Copy link
Copy Markdown
Member Author

bugbot run

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 019fa47. Configure here.

Comment thread sentry_sdk/traces.py
Comment thread sentry_sdk/integrations/httpx.py
@ericapisani ericapisani marked this pull request as ready for review April 16, 2026 20:35
@ericapisani ericapisani requested a review from a team as a code owner April 16, 2026 20:35
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.

1 participant