|
4 | 4 | import sys
|
5 | 5 | import threading
|
6 | 6 | import weakref
|
| 7 | +from importlib import import_module |
7 | 8 |
|
| 9 | +from sentry_sdk._compat import string_types |
8 | 10 | from sentry_sdk._types import TYPE_CHECKING
|
9 | 11 | from sentry_sdk.consts import OP, SPANDATA
|
10 | 12 | from sentry_sdk.hub import Hub, _should_send_default_pii
|
|
32 | 34 | from django import VERSION as DJANGO_VERSION
|
33 | 35 | from django.conf import settings as django_settings
|
34 | 36 | from django.core import signals
|
| 37 | + from django.conf import settings |
35 | 38 |
|
36 | 39 | try:
|
37 | 40 | from django.urls import resolve
|
38 | 41 | except ImportError:
|
39 | 42 | from django.core.urlresolvers import resolve
|
| 43 | + |
| 44 | + try: |
| 45 | + from django.urls import Resolver404 |
| 46 | + except ImportError: |
| 47 | + from django.core.urlresolvers import Resolver404 |
40 | 48 | except ImportError:
|
41 | 49 | raise DidNotEnable("Django not installed")
|
42 | 50 |
|
@@ -370,6 +378,18 @@ def _set_transaction_name_and_source(scope, transaction_style, request):
|
370 | 378 | transaction_name,
|
371 | 379 | source=source,
|
372 | 380 | )
|
| 381 | + except Resolver404: |
| 382 | + urlconf = import_module(settings.ROOT_URLCONF) |
| 383 | + # This exception only gets thrown when transaction_style is `function_name` |
| 384 | + # So we don't check here what style is configured |
| 385 | + if hasattr(urlconf, "handler404"): |
| 386 | + handler = urlconf.handler404 |
| 387 | + if isinstance(handler, string_types): |
| 388 | + scope.transaction = handler |
| 389 | + else: |
| 390 | + scope.transaction = transaction_from_function( |
| 391 | + getattr(handler, "view_class", handler) |
| 392 | + ) |
373 | 393 | except Exception:
|
374 | 394 | pass
|
375 | 395 |
|
|
0 commit comments