Skip to content

fix(flask): Set user data on scope at request start#6566

Draft
ericapisani wants to merge 2 commits into
masterfrom
py-2528-set-user-data-on-flask
Draft

fix(flask): Set user data on scope at request start#6566
ericapisani wants to merge 2 commits into
masterfrom
py-2528-set-user-data-on-flask

Conversation

@ericapisani

Copy link
Copy Markdown
Member

Previously, Flask user data (id, email, username) was only set via the _add_user_to_event event processor, which runs at event capture time. Under span streaming, spans are sent before an error event is captured, so user attributes were missing from those spans.

This refactors the user property logic into a shared _get_flask_user_properties() helper and calls it in _request_started to set user data directly on the isolation scope. The event processor continues to use the same helper to keep behavior consistent for non-streaming cases. Tests are extended to cover both span streaming and non-streaming paths.

Fixes GH-6565
Refs PY-2528

Extract _get_flask_user_properties() and call it during _request_started
so that user data (id, email, username) is available on the scope early
enough to be propagated to streamed spans, not only to error events.

The event processor _add_user_to_event now delegates to the same helper,
keeping behavior consistent between the two code paths.
@linear-code

linear-code Bot commented Jun 12, 2026

Copy link
Copy Markdown

PY-2528

@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

90696 passed | ⏭️ 6031 skipped | Total: 96727 | Pass Rate: 93.76% | Execution Time: 310m 45s

📊 Comparison with Base Branch

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

All tests are passing successfully.

✅ Patch coverage is 90.63%. Project has 2421 uncovered lines.
❌ Project coverage is 89.75%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/flask.py 90.63% ⚠️ 3 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    89.77%    89.75%    -0.02%
==========================================
  Files          192       192         —
  Lines        23615     23630       +15
  Branches      8130      8140       +10
==========================================
+ Hits         21201     21209        +8
- Misses        2414      2421        +7
- Partials      1340      1340         —

Generated by Codecov Action

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.

Ensure user data is set on all spans within Flask

1 participant