Skip to content

feat(quart): Add span streaming support to Quart integration#6502

Open
ericapisani wants to merge 3 commits into
py-2514-gate-asgi-values-behind-piifrom
py-2352-migrate-quart
Open

feat(quart): Add span streaming support to Quart integration#6502
ericapisani wants to merge 3 commits into
py-2514-gate-asgi-values-behind-piifrom
py-2352-migrate-quart

Conversation

@ericapisani
Copy link
Copy Markdown
Member

Add span streaming support for the Quart integration when the
trace_lifecycle stream experiment is enabled. Sets HTTP request
attributes (method, headers, URL, query, client IP) on the segment
span and uses the correct source constant from sentry_sdk.traces
for span-first mode.

Depends on #6501
being merged first.

Fixes PY-2352
Fixes #6050

Add span streaming support for the Quart integration when the
trace_lifecycle stream experiment is enabled. Sets HTTP request
attributes (method, headers, URL, query, client IP) on the segment
span and uses the correct source constant from sentry_sdk.traces
for span-first mode.

Depends on #6501
being merged first.

Fixes PY-2352
Fixes #6050
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Jun 4, 2026

PY-2352

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

Codecov Results 📊

88506 passed | ⏭️ 6022 skipped | Total: 94528 | Pass Rate: 93.63% | Execution Time: 297m 57s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +80
Passed Tests 📈 +80
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2474 uncovered lines.
✅ Project coverage is 89.38%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/quart.py 100.00% ⚠️ 3 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.37%    89.38%    +0.01%
==========================================
  Files          192       192         —
  Lines        23285     23306       +21
  Branches      8002      8016       +14
==========================================
+ Hits         20811     20832       +21
- Misses        2474      2474         —
- Partials      1309      1312        +3

Generated by Codecov Action

@ericapisani ericapisani marked this pull request as ready for review June 4, 2026 14:11
@ericapisani ericapisani requested a review from a team as a code owner June 4, 2026 14:11
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 44efa73. Configure here.

Comment thread sentry_sdk/integrations/quart.py Outdated
Comment thread sentry_sdk/integrations/quart.py
Comment on lines 123 to 125
current_scope = sentry_sdk.get_current_scope()
if current_scope.transaction is not None:
current_scope.transaction.update_active_thread()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We'll need a streaming counterpart for this piece of code, something like:

client = sentry_sdk.get_client()

if has_span_streaming_enabled(client.options):
    span = get_current_span()
    if span is not None:
        span._segment._update_active_thread()

)
segment.set_attribute(
"user.ip_address", request_websocket.access_route[0]
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should also set user.id if we have it (essentially port _add_user_to_event).

It's one of the attributes that should be set on all spans, not just the segment, so it should be set on the scope.

Maybe extract the code that fetches the user id from _add_user_to_event to a helper func, get rid of _add_user_to_event and set the user id in the event processor directly, and in the streaming path set it on the current scope?

def _fetch_user_id() -> None:
    if quart_auth is None:
        return

    user = quart_auth.current_user
    if user is None:
        return

    try:
        return quart_auth.current_user._auth_id
    except Exception:
        return None

and then here

user_id = _fetch_user_id()
if user_id is not None:
    sentry_sdk.get_current_scope().set_attribute("user.id", user_id)

and in the event processor

user_id = _fetch_user_id()
if user_id is not None:
    user_info = event.setdefault("user", {})
    user_info["id"] = user_id

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please also add a test for this if there is none.

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