feat(quart): Add span streaming support to Quart integration#6502
feat(quart): Add span streaming support to Quart integration#6502ericapisani wants to merge 9 commits into
Conversation
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 📊✅ 89394 passed | ⏭️ 6013 skipped | Total: 95407 | Pass Rate: 93.7% | Execution Time: 301m 18s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 91.11%. Project has 2393 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 89.80% 89.81% +0.01%
==========================================
Files 192 192 —
Lines 23453 23487 +34
Branches 8060 8082 +22
==========================================
+ Hits 21061 21094 +33
- Misses 2392 2393 +1
- Partials 1329 1331 +2Generated 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()| ) | ||
| segment.set_attribute( | ||
| "user.ip_address", request_websocket.access_route[0] | ||
| ) |
There was a problem hiding this comment.
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 Noneand 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_idThere was a problem hiding this comment.
Please also add a test for this if there is none or add to an existing one.
There was a problem hiding this comment.
Sounds good. Regarding needing to set the user.id on the scope - would that mean that we also need to make an adjustment for the user.ip_address as well? I noticed it also appears in that list that you had linked 👀
| 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.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e5eb0b3. Configure here.
| 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.


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