2025-12-01
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from collections.abc import Set
|
||||
from copy import deepcopy
|
||||
|
||||
import sentry_sdk
|
||||
from sentry_sdk.consts import OP
|
||||
from sentry_sdk.integrations import (
|
||||
@@ -9,7 +11,7 @@ from sentry_sdk.integrations import (
|
||||
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
|
||||
from sentry_sdk.integrations.logging import ignore_logger
|
||||
from sentry_sdk.scope import should_send_default_pii
|
||||
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TRANSACTION_SOURCE_ROUTE
|
||||
from sentry_sdk.tracing import TransactionSource, SOURCE_FOR_STYLE
|
||||
from sentry_sdk.utils import (
|
||||
ensure_integration_enabled,
|
||||
event_from_exception,
|
||||
@@ -85,8 +87,18 @@ class SentryLitestarASGIMiddleware(SentryAsgiMiddleware):
|
||||
transaction_style="endpoint",
|
||||
mechanism_type="asgi",
|
||||
span_origin=span_origin,
|
||||
asgi_version=3,
|
||||
)
|
||||
|
||||
def _capture_request_exception(self, exc):
|
||||
# type: (Exception) -> None
|
||||
"""Avoid catching exceptions from request handlers.
|
||||
|
||||
Those exceptions are already handled in Litestar.after_exception handler.
|
||||
We still catch exceptions from application lifespan handlers.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def patch_app_init():
|
||||
# type: () -> None
|
||||
@@ -107,7 +119,6 @@ def patch_app_init():
|
||||
*(kwargs.get("after_exception") or []),
|
||||
]
|
||||
|
||||
SentryLitestarASGIMiddleware.__call__ = SentryLitestarASGIMiddleware._run_asgi3 # type: ignore
|
||||
middleware = kwargs.get("middleware") or []
|
||||
kwargs["middleware"] = [SentryLitestarASGIMiddleware, *middleware]
|
||||
old__init__(self, *args, **kwargs)
|
||||
@@ -213,9 +224,7 @@ def patch_http_route_handle():
|
||||
return await old_handle(self, scope, receive, send)
|
||||
|
||||
sentry_scope = sentry_sdk.get_isolation_scope()
|
||||
request = scope["app"].request_class(
|
||||
scope=scope, receive=receive, send=send
|
||||
) # type: Request[Any, Any]
|
||||
request = scope["app"].request_class(scope=scope, receive=receive, send=send) # type: Request[Any, Any]
|
||||
extracted_request_data = ConnectionDataExtractor(
|
||||
parse_body=True, parse_query=True
|
||||
)(request)
|
||||
@@ -249,11 +258,11 @@ def patch_http_route_handle():
|
||||
|
||||
if not tx_name:
|
||||
tx_name = _DEFAULT_TRANSACTION_NAME
|
||||
tx_info = {"source": TRANSACTION_SOURCE_ROUTE}
|
||||
tx_info = {"source": TransactionSource.ROUTE}
|
||||
|
||||
event.update(
|
||||
{
|
||||
"request": request_info,
|
||||
"request": deepcopy(request_info),
|
||||
"transaction": tx_name,
|
||||
"transaction_info": tx_info,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user