Skip to content

feat(wsgi): Migrate to span first - #5988

Merged
sentrivana merged 33 commits into
masterfrom
ivana/migrate-wsgi-to-span-first
Apr 14, 2026
Merged

feat(wsgi): Migrate to span first#5988
sentrivana merged 33 commits into
masterfrom
ivana/migrate-wsgi-to-span-first

Conversation

@sentrivana

@sentrivanasentrivana commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Description

Make the WSGI integration span first ready.

Also, set an additional attribute (user.ip_address) in ASGI.

Recommended to review with Ignore whitespace on.

Issues

Reminders

Base automatically changed from ivana/migrate-asgi-event-processor to masterApril 13, 2026 13:41
@github-actions

github-actionsBot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

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


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@github-actions

github-actionsBot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

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

All tests are passing successfully.

❌ Patch coverage is 7.81%. Project has 15327 uncovered lines.

Files with missing lines (3)
FilePatch %Lines
scope.py65.78%⚠️ 297 Missing and 74 partials
wsgi.py17.84%⚠️ 152 Missing
_asgi_common.py13.70%⚠️ 63 Missing

Generated by Codecov Action

@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

49 passed | ⏭️ 3 skipped | Total: 52 | Pass Rate: 94.23% | Execution Time: 12.36s

📊 Comparison with Base Branch

MetricChange
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 7.81%. Project has 15640 uncovered lines.
❌ Project coverage is 26.7%. Comparing base (base) to head (head).

Files with missing lines (5)
FilePatch %Lines
scope.py61.75%⚠️ 332 Missing and 73 partials
asgi.py15.38%⚠️ 176 Missing
wsgi.py20.65%⚠️ 123 Missing
_wsgi_common.py23.75%⚠️ 122 Missing
_asgi_common.py13.70%⚠️ 63 Missing
Coverage diff
@@ Coverage Diff @@## main #PR +/-##
==========================================
- Coverage 26.75% 26.70% -0.05%
==========================================
Files 191 191 —
Lines 21281 21336 +55
Branches 7006 7036 +30
==========================================
+ Hits 5692 5696 +4- Misses 15589 15640 +51- Partials 490 490 —

Generated by Codecov Action

Comment threadsentry_sdk/integrations/wsgi.py Outdated
Comment threadsentry_sdk/integrations/_wsgi_common.py Outdated
return event_processor


def _get_request_attributes(

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

This is essentially a port of the event processor

Comment threadsentry_sdk/scope.py
self, custom_sampling_context: "dict[str, Any]"
) -> None:
self.get_active_propagation_context()._set_custom_sampling_context(
self.get_current_scope().get_active_propagation_context()._set_custom_sampling_context(

@sentrivanasentrivanaApr 14, 2026

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

This change was necessary as we're now always starting spans, regardless of type (segment or child), on the current scope instead of the isolation scope, so we also need to use the propagation context from there.

@linear-code

Copy link
Copy Markdown

@sentrivana
sentrivana marked this pull request as ready for review April 14, 2026 10:02
@sentrivana
sentrivana requested a review from a team as a code ownerApril 14, 2026 10:02

@cursorcursorBot left a comment

Copy link
Copy Markdown

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 54064a5. Configure here.

Comment threadsentry_sdk/integrations/wsgi.py Outdated
@sentrivana
sentrivana merged commit 822b244 into masterApr 14, 2026
167 of 169 checks passed
@sentrivana
sentrivana deleted the ivana/migrate-wsgi-to-span-first branch April 14, 2026 14:37
mgaligniana pushed a commit to mgaligniana/sentry-python that referenced this pull request Aug 9, 2026
### Description
Make the WSGI integration span first ready.
Also, set an additional attribute (`user.ip_address`) in ASGI.
Recommended to review with Ignore whitespace on.
#### Issues
* Closesgetsentry#6072
* Closes
https://linear.app/getsentry/issue/PY-2374/migrate-wsgi-to-span-first
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate wsgi to span first

2 participants

@sentrivana@alexander-alderman-webb