diff --git a/src/sentry/integrations/github/webhook.py b/src/sentry/integrations/github/webhook.py index 7bee3f156b988e..f05c8e179eafb9 100644 --- a/src/sentry/integrations/github/webhook.py +++ b/src/sentry/integrations/github/webhook.py @@ -14,6 +14,7 @@ from django.views.decorators.csrf import csrf_exempt from django.views.generic import View from rest_framework.request import Request +from sentry_sdk import configure_scope from sentry import options from sentry.constants import ObjectStatus @@ -36,6 +37,23 @@ logger = logging.getLogger("sentry.webhooks") +def clear_tags_and_context_if_already_set() -> None: + """Clear org tags and context since it should not be set""" + reset_values = False + with configure_scope() as scope: + for tag in ["organization", "organization.slug"]: + if tag in scope._tags: + reset_values = True + del scope._tags[tag] + + if "organization" in scope._contexts: + reset_values = True + del scope._contexts["organization"] + + if reset_values: + logger.info("We've reset the context and tags.") + + class Webhook: provider = "github" @@ -456,6 +474,7 @@ def get_secret(self) -> str | None: raise NotImplementedError def handle(self, request: Request) -> HttpResponse: + clear_tags_and_context_if_already_set() secret = self.get_secret() if secret is None: