feat(quart): Add span streaming support to Quart integration#6502
feat(quart): Add span streaming support to Quart integration#6502ericapisani wants to merge 19 commits into
Conversation
Move http.query and client.address attribute collection inside the should_send_default_pii() check so sensitive values are not captured by default. Fixes PY-2514 Fixes #6499
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
Codecov Results 📊✅ 89523 passed | ⏭️ 6013 skipped | Total: 95536 | Pass Rate: 93.71% | Execution Time: 308m 51s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 92.16%. Project has 2400 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 89.81% 89.79% -0.02%
==========================================
Files 192 192 —
Lines 23460 23497 +37
Branches 8062 8084 +22
==========================================
+ Hits 21069 21097 +28
- Misses 2391 2400 +9
- Partials 1328 1332 +4Generated by Codecov Action |
There was a problem hiding this comment.
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()| SENTRY_PYTHON_TEST_POSTGRES_USER: postgres | ||
| SENTRY_PYTHON_TEST_POSTGRES_PASSWORD: sentry | ||
| SENTRY_PYTHON_TEST_MYSQL_USER: root | ||
| SENTRY_PYTHON_TEST_MYSQL_PASSWORD: sentry |
There was a problem hiding this comment.
Missing MySQL host env variable
Medium Severity
The DB CI job sets SENTRY_PYTHON_TEST_POSTGRES_HOST to postgres for Python 3.6/3.7 container runs but does not set SENTRY_PYTHON_TEST_MYSQL_HOST the same way for the new MySQL service. tests/integrations/aiomysql reads that variable and defaults to localhost, which is unreachable from the job container network.
Reviewed by Cursor Bugbot for commit dde12e6. Configure here.
There was a problem hiding this comment.
I don't know where this came from 🤔
| SENTRY_PYTHON_TEST_POSTGRES_USER: postgres | ||
| SENTRY_PYTHON_TEST_POSTGRES_PASSWORD: sentry | ||
| SENTRY_PYTHON_TEST_MYSQL_USER: root | ||
| SENTRY_PYTHON_TEST_MYSQL_PASSWORD: sentry |
There was a problem hiding this comment.
Missing MySQL host container env
Medium Severity
The new MySQL CI env sets SENTRY_PYTHON_TEST_MYSQL_USER and password but not SENTRY_PYTHON_TEST_MYSQL_HOST. For Python 3.6/3.7 jobs that run inside a service-linked container, tests/integrations/aiomysql defaults to localhost, unlike Postgres and Redis which use the mysql service hostname in that layout.
Reviewed by Cursor Bugbot for commit e5eb0b3. Configure here.
…ython into py-2352-migrate-quart
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 42bbc3f. Configure here.
| segment.set_attribute( | ||
| "user.ip_address", request_websocket.access_route[0] | ||
| ) | ||
| user_properties["ip_address"] = request_websocket.access_route[0] |
There was a problem hiding this comment.
Proxy client IP overwritten
Medium Severity
With span streaming and default PII enabled, the new Quart hook sets client.address, user.ip_address, and scope user ip_address from access_route[0] on the segment after SentryAsgiMiddleware already set client.address via _get_ip (forwarded headers). That overwrites the resolved client IP with the immediate peer address behind proxies.
Reviewed by Cursor Bugbot for commit 42bbc3f. Configure here.
sentrivana
left a comment
There was a problem hiding this comment.
Two small things, please see comments, otherwise LGTM
| segment.set_attribute( | ||
| "client.address", request_websocket.access_route[0] | ||
| ) | ||
| segment.set_attribute( | ||
| "user.ip_address", request_websocket.access_route[0] | ||
| ) |
There was a problem hiding this comment.
These should be set in user_properties instead, like ip_address is -- if they're set on the scope via set_user, they'll be set on all spans (including the segment) automatically
| current_scope = sentry_sdk.get_current_scope() | ||
| existing_user_properties = current_scope._user or {} | ||
| current_scope.set_user( | ||
| {**existing_user_properties, **user_properties} | ||
| ) |
There was a problem hiding this comment.
If we want to merge like this, this should interact with the isolation scope. The top-level set_user API sets the user on the isolation scope, so if there is any user data set by the user, it'll be on the isolation scope.
| current_scope = sentry_sdk.get_current_scope() | |
| existing_user_properties = current_scope._user or {} | |
| current_scope.set_user( | |
| {**existing_user_properties, **user_properties} | |
| ) | |
| isolation_scope = sentry_sdk.get_isolation_scope() | |
| existing_user_properties = isolation_scope._user or {} | |
| isolation_scope.set_user( | |
| {**existing_user_properties, **user_properties} | |
| ) |


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