fix(flask): Set user data on scope at request start#6566
Draft
ericapisani wants to merge 2 commits into
Draft
Conversation
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.
Contributor
Codecov Results 📊✅ 90696 passed | ⏭️ 6031 skipped | Total: 96727 | Pass Rate: 93.76% | Execution Time: 310m 45s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 90.63%. Project has 2421 uncovered lines. Files with missing lines (1)
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, Flask user data (id, email, username) was only set via the
_add_user_to_eventevent 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_startedto 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