-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore: Investigating org slug already set to a different value #45134
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3e7f3fd
WIP
armenzg 444417a
Reduce changes
armenzg 4c65157
Report error
armenzg f215b69
Set tag and use error instead of exception
armenzg 2baf267
Do not import Scope
armenzg 1443006
Merge branch 'master' into armenzg/detect-unmatching-tags
armenzg 3654afe
Too many arguments
armenzg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import copy | ||
| import inspect | ||
| import logging | ||
| import random | ||
|
|
||
| import sentry_sdk | ||
|
|
@@ -18,6 +19,8 @@ | |
| from sentry.utils.db import DjangoAtomicIntegration | ||
| from sentry.utils.rust import RustInfoIntegration | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| UNSAFE_FILES = ( | ||
| "sentry/event_manager.py", | ||
| "sentry/tasks/process_buffer.py", | ||
|
|
@@ -445,11 +448,38 @@ def _kwargs_into_scope(self, scope, extra=None, tags=None, fingerprint=None, req | |
| scope.fingerprint = fingerprint | ||
|
|
||
|
|
||
| def check_tag(tag_key: str, expected_value: str) -> bool: | ||
| """Detect a tag already set and being different than what we expect. | ||
|
|
||
| This function checks if a tag has been already been set and if it differs | ||
| from what we want to set it to. | ||
| """ | ||
| with configure_scope() as scope: | ||
| if scope._tags and tag_key in scope._tags and scope._tags[tag_key] != expected_value: | ||
| extra = { | ||
| f"previous_{tag_key}": scope._tags[tag_key], | ||
| f"new_{tag_key}": expected_value, | ||
| } | ||
| logger.warning(f"Tag already set and different ({tag_key}).", extra=extra) | ||
| # This can be used to find errors that may have been mistagged | ||
| scope.set_tag("possible_mistag", True) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what I believe would help most. |
||
| return True | ||
|
|
||
|
|
||
| # We have some events being tagged with organization.slug even when we don't have such info | ||
| def log_if_tags_already_set(org_id: int, org_slug: str) -> None: | ||
| """If the tags are already set and differ, report them as a Sentry error.""" | ||
| if check_tag("organization", org_id) or check_tag("organization.slug", org_slug): | ||
| logger.error("Intentional error for investigation. See WOR-2464.") | ||
|
|
||
|
|
||
| def bind_organization_context(organization): | ||
| helper = settings.SENTRY_ORGANIZATION_CONTEXT_HELPER | ||
|
|
||
| # XXX(dcramer): this is duplicated in organizationContext.jsx on the frontend | ||
| with sentry_sdk.configure_scope() as scope: | ||
| log_if_tags_already_set(organization.id, organization.slug) | ||
|
|
||
| scope.set_tag("organization", organization.id) | ||
| scope.set_tag("organization.slug", organization.slug) | ||
| scope.set_context("organization", {"id": organization.id, "slug": organization.slug}) | ||
|
|
||
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.
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.
The main difference with #45039 is that we also check for the tags being different (
scope._tags[tag_key] != expected_value).