2025-12-01
This commit is contained in:
+15
-4
@@ -7,8 +7,8 @@ from importlib import import_module
|
||||
import sentry_sdk
|
||||
from sentry_sdk.consts import OP, SPANDATA
|
||||
from sentry_sdk.scope import add_global_event_processor, should_send_default_pii
|
||||
from sentry_sdk.serializer import add_global_repr_processor
|
||||
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TRANSACTION_SOURCE_URL
|
||||
from sentry_sdk.serializer import add_global_repr_processor, add_repr_sequence_type
|
||||
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TransactionSource
|
||||
from sentry_sdk.tracing_utils import add_query_source, record_sql_queries
|
||||
from sentry_sdk.utils import (
|
||||
AnnotatedValue,
|
||||
@@ -269,6 +269,7 @@ class DjangoIntegration(Integration):
|
||||
patch_views()
|
||||
patch_templates()
|
||||
patch_signals()
|
||||
add_template_context_repr_sequence()
|
||||
|
||||
if patch_caching is not None:
|
||||
patch_caching()
|
||||
@@ -398,7 +399,7 @@ def _set_transaction_name_and_source(scope, transaction_style, request):
|
||||
|
||||
if transaction_name is None:
|
||||
transaction_name = request.path_info
|
||||
source = TRANSACTION_SOURCE_URL
|
||||
source = TransactionSource.URL
|
||||
else:
|
||||
source = SOURCE_FOR_STYLE[transaction_style]
|
||||
|
||||
@@ -584,7 +585,7 @@ class DjangoRequestExtractor(RequestExtractor):
|
||||
# type: () -> Optional[Dict[str, Any]]
|
||||
try:
|
||||
return self.request.data
|
||||
except AttributeError:
|
||||
except Exception:
|
||||
return RequestExtractor.parsed_body(self)
|
||||
|
||||
|
||||
@@ -745,3 +746,13 @@ def _set_db_data(span, cursor_or_db):
|
||||
server_socket_address = connection_params.get("unix_socket")
|
||||
if server_socket_address is not None:
|
||||
span.set_data(SPANDATA.SERVER_SOCKET_ADDRESS, server_socket_address)
|
||||
|
||||
|
||||
def add_template_context_repr_sequence():
|
||||
# type: () -> None
|
||||
try:
|
||||
from django.template.context import BaseContext
|
||||
|
||||
add_repr_sequence_type(BaseContext)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
+3
-3
@@ -155,7 +155,7 @@ def patch_channels_asgi_handler_impl(cls):
|
||||
http_methods_to_capture=integration.http_methods_to_capture,
|
||||
)
|
||||
|
||||
return await middleware(self.scope)(receive, send)
|
||||
return await middleware(self.scope)(receive, send) # type: ignore
|
||||
|
||||
cls.__call__ = sentry_patched_asgi_handler
|
||||
|
||||
@@ -237,9 +237,9 @@ def _asgi_middleware_mixin_factory(_check_middleware_span):
|
||||
middleware_span = _check_middleware_span(old_method=f)
|
||||
|
||||
if middleware_span is None:
|
||||
return await f(*args, **kwargs)
|
||||
return await f(*args, **kwargs) # type: ignore
|
||||
|
||||
with middleware_span:
|
||||
return await f(*args, **kwargs)
|
||||
return await f(*args, **kwargs) # type: ignore
|
||||
|
||||
return SentryASGIMixin
|
||||
|
||||
+16
-3
@@ -45,7 +45,8 @@ def _patch_cache_method(cache, method_name, address, port):
|
||||
):
|
||||
# type: (CacheHandler, str, Callable[..., Any], tuple[Any, ...], dict[str, Any], Optional[str], Optional[int]) -> Any
|
||||
is_set_operation = method_name.startswith("set")
|
||||
is_get_operation = not is_set_operation
|
||||
is_get_method = method_name == "get"
|
||||
is_get_many_method = method_name == "get_many"
|
||||
|
||||
op = OP.CACHE_PUT if is_set_operation else OP.CACHE_GET
|
||||
description = _get_span_description(method_name, args, kwargs)
|
||||
@@ -69,8 +70,20 @@ def _patch_cache_method(cache, method_name, address, port):
|
||||
span.set_data(SPANDATA.CACHE_KEY, key)
|
||||
|
||||
item_size = None
|
||||
if is_get_operation:
|
||||
if value:
|
||||
if is_get_many_method:
|
||||
if value != {}:
|
||||
item_size = len(str(value))
|
||||
span.set_data(SPANDATA.CACHE_HIT, True)
|
||||
else:
|
||||
span.set_data(SPANDATA.CACHE_HIT, False)
|
||||
elif is_get_method:
|
||||
default_value = None
|
||||
if len(args) >= 2:
|
||||
default_value = args[1]
|
||||
elif "default" in kwargs:
|
||||
default_value = kwargs["default"]
|
||||
|
||||
if value != default_value:
|
||||
item_size = len(str(value))
|
||||
span.set_data(SPANDATA.CACHE_HIT, True)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user