-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(metrics): add global tags to sentry_sdk tags as well #102795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🔍 Existing Issues For ReviewYour pull request is modifying functions with the following pre-existing issues: 📄 File: src/sentry/runner/commands/run.py
|
src/sentry/metrics/middleware.py
Outdated
|
|
||
| def _add_global_tags(_all_threads: bool = False, **tags: TagValue) -> list[Tags]: | ||
| def _add_global_tags( | ||
| _all_threads: bool = False, set_sentry_tags: bool = False, **tags: TagValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| _all_threads: bool = False, set_sentry_tags: bool = False, **tags: TagValue | |
| _all_threads: bool = False, _set_sentry_tags: bool = False, **tags: TagValue |
there is a convention to name all parameters with underscores so they don't collide with actual tags
16aa284 to
dc65c6d
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #102795 +/- ##
===========================================
- Coverage 80.58% 79.78% -0.81%
===========================================
Files 8938 8962 +24
Lines 391188 405154 +13966
Branches 24884 24884
===========================================
+ Hits 315234 323244 +8010
- Misses 75584 81540 +5956
Partials 370 370 |
| See docstring of `add_global_tags` for how those two methods interact. | ||
| """ | ||
| stack = _add_global_tags(_all_threads=_all_threads, **tags) | ||
| stack = _add_global_tags(all_threads=all_threads, set_sentry_tags=set_sentry_tags, tags=tags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Sentry Tags Escape Global Context Scope
The global_tags context manager doesn't revert sentry_sdk tags when set_sentry_tags=True is used. When exiting the context, only the metrics tag stack is cleaned up (line 110), but tags set via sentry_sdk.set_tags() (line 69) remain permanently set. This creates inconsistent behavior where metric tags are scoped but sentry tags leak beyond the context, violating the documented promise to "revert all tag changes upon exit."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't be bothered to figure out how to revert sentry tags. it's difficult to do cross-thread and APIs keep getting deprecated
This PR adds the option to also configure tags set in the metrics backend via
add_global_tagsto also be set in the sentry_sdk.