Skip to content

Commit

Permalink
fix(django): Fix 404 Handler handler being labeled as "generic ASGI r…
Browse files Browse the repository at this point in the history
…equest"
  • Loading branch information
BeryJu committed Jun 21, 2023
1 parent c26f35a commit af4a72d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import threading
import weakref
from importlib import import_module

from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.consts import OP, SPANDATA
Expand Down Expand Up @@ -32,6 +33,8 @@
from django import VERSION as DJANGO_VERSION
from django.conf import settings as django_settings
from django.core import signals
from django.urls.exceptions import Resolver404
from django.conf import settings

try:
from django.urls import resolve
Expand Down Expand Up @@ -370,6 +373,15 @@ def _set_transaction_name_and_source(scope, transaction_style, request):
transaction_name,
source=source,
)
except Resolver404:
urlconf = import_module(settings.ROOT_URLCONF)
# This exception only gets thrown when transaction_style is `function_name`
# So we don't check here what style is configured
if hasattr(urlconf, "handler404"):
handler = getattr(urlconf, "handler404")
scope.transaction = transaction_from_function(
getattr(handler, "view_class", handler)
)
except Exception:
pass

Expand Down

0 comments on commit af4a72d

Please sign in to comment.