def event_processor(event, hint): # type: (Dict[str, Any], Dict[str, Any]) -> Dict[str, Any] # if the request is gone we are fine not logging the data from # it. This might happen if the processor is pushed away to # another thread. request = weak_request() if request is None: return event try: if integration.transaction_style == "function_name": event["transaction"] = transaction_from_function( resolve(request.path).func) elif integration.transaction_style == "url": event["transaction"] = LEGACY_RESOLVER.resolve(request.path) except Exception: pass with capture_internal_exceptions(): DjangoRequestExtractor(request).extract_into_event(event) if _should_send_default_pii(): with capture_internal_exceptions(): _set_user_info(request, event) return event
def _before_get_response(request): # type: (WSGIRequest) -> None hub = Hub.current integration = hub.get_integration(DjangoIntegration) if integration is None: return _patch_drf() with hub.configure_scope() as scope: # Rely on WSGI middleware to start a trace try: if integration.transaction_style == "function_name": fn = resolve(request.path).func scope.transaction = transaction_from_function( getattr(fn, "view_class", fn) ) elif integration.transaction_style == "url": scope.transaction = LEGACY_RESOLVER.resolve(request.path_info) except Exception: pass scope.add_event_processor( _make_event_processor(weakref.ref(request), integration) )
def _attempt_resolve_again(request, scope): # type: (WSGIRequest, Scope) -> None """ Some django middlewares overwrite request.urlconf so we need to respect that contract, so we try to resolve the url again. """ if not hasattr(request, "urlconf"): return try: scope.transaction = LEGACY_RESOLVER.resolve( request.path_info, urlconf=request.urlconf, ) except Exception: pass
def sentry_patched_get_response(self, request): # type: (Any, WSGIRequest) -> Union[HttpResponse, BaseException] hub = Hub.current integration = hub.get_integration(DjangoIntegration) if integration is not None: _patch_drf() with hub.configure_scope() as scope: # Rely on WSGI middleware to start a trace try: if integration.transaction_style == "function_name": scope.transaction = transaction_from_function( resolve(request.path).func ) elif integration.transaction_style == "url": scope.transaction = LEGACY_RESOLVER.resolve(request.path) except Exception: pass scope.add_event_processor( _make_event_processor(weakref.ref(request), integration) ) return old_get_response(self, request)