Server IP : 184.107.3.203 / Your IP : 216.73.216.51 Web Server : Apache System : Linux dedicated2.avenfashion.com.ph 4.18.0-553.40.1.el8_10.x86_64 #1 SMP Mon Feb 10 12:11:18 EST 2025 x86_64 User : adminteladeoro ( 1015) PHP Version : 8.2.28 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /opt/imunify360/venv/lib/python3.11/site-packages/sentry_sdk/integrations/django/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
""" Instrumentation for Django 3.0 Since this file contains `async def` it is conditionally imported in `sentry_sdk.integrations.django` (depending on the existence of `django.core.handlers.asgi`. """ from sentry_sdk import Hub, _functools from sentry_sdk._types import MYPY from sentry_sdk.integrations.asgi import SentryAsgiMiddleware if MYPY: from typing import Any from typing import Union from django.http.response import HttpResponse def patch_django_asgi_handler_impl(cls): # type: (Any) -> None from sentry_sdk.integrations.django import DjangoIntegration old_app = cls.__call__ async def sentry_patched_asgi_handler(self, scope, receive, send): # type: (Any, Any, Any, Any) -> Any if Hub.current.get_integration(DjangoIntegration) is None: return await old_app(self, scope, receive, send) middleware = SentryAsgiMiddleware( old_app.__get__(self, cls), unsafe_context_data=True )._run_asgi3 return await middleware(scope, receive, send) cls.__call__ = sentry_patched_asgi_handler def patch_get_response_async(cls, _before_get_response): # type: (Any, Any) -> None old_get_response_async = cls.get_response_async async def sentry_patched_get_response_async(self, request): # type: (Any, Any) -> Union[HttpResponse, BaseException] _before_get_response(request) return await old_get_response_async(self, request) cls.get_response_async = sentry_patched_get_response_async def patch_channels_asgi_handler_impl(cls): # type: (Any) -> None from sentry_sdk.integrations.django import DjangoIntegration old_app = cls.__call__ async def sentry_patched_asgi_handler(self, receive, send): # type: (Any, Any, Any) -> Any if Hub.current.get_integration(DjangoIntegration) is None: return await old_app(self, receive, send) middleware = SentryAsgiMiddleware( lambda _scope: old_app.__get__(self, cls), unsafe_context_data=True ) return await middleware(self.scope)(receive, send) cls.__call__ = sentry_patched_asgi_handler def wrap_async_view(hub, callback): # type: (Hub, Any) -> Any @_functools.wraps(callback) async def sentry_wrapped_callback(request, *args, **kwargs): # type: (Any, *Any, **Any) -> Any with hub.start_span( op="django.view", description=request.resolver_match.view_name ): return await callback(request, *args, **kwargs) return sentry_wrapped_callback