diff --git a/sentry_sdk/integrations/_wsgi_common.py b/sentry_sdk/integrations/_wsgi_common.py index cf1a365209..16a7639189 100644 --- a/sentry_sdk/integrations/_wsgi_common.py +++ b/sentry_sdk/integrations/_wsgi_common.py @@ -1,5 +1,4 @@ import json -from contextlib import contextmanager from copy import deepcopy import sentry_sdk @@ -18,7 +17,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from typing import Any, Dict, Iterator, Mapping, MutableMapping, Optional, Union + from typing import Any, Dict, Mapping, MutableMapping, Optional, Union from sentry_sdk._types import Event, HttpStatusCodeRange @@ -52,12 +51,6 @@ ) -# This noop context manager can be replaced with "from contextlib import nullcontext" when we drop Python 3.6 support -@contextmanager -def nullcontext() -> "Iterator[None]": - yield - - def request_body_within_bounds( client: "Optional[sentry_sdk.client.BaseClient]", content_length: int ) -> bool: diff --git a/sentry_sdk/integrations/asgi.py b/sentry_sdk/integrations/asgi.py index 8b1ff5e2a3..a360d7af36 100644 --- a/sentry_sdk/integrations/asgi.py +++ b/sentry_sdk/integrations/asgi.py @@ -24,7 +24,6 @@ ) from sentry_sdk.integrations._wsgi_common import ( DEFAULT_HTTP_METHODS_TO_CAPTURE, - nullcontext, ) from sentry_sdk.scope import Scope, should_send_default_pii from sentry_sdk.sessions import track_session @@ -49,6 +48,7 @@ capture_internal_exceptions, event_from_exception, logger, + nullcontext, qualname_from_function, reraise, transaction_from_function, diff --git a/sentry_sdk/integrations/asyncio.py b/sentry_sdk/integrations/asyncio.py index 4b3f6d330e..bf30a69e67 100644 --- a/sentry_sdk/integrations/asyncio.py +++ b/sentry_sdk/integrations/asyncio.py @@ -4,7 +4,6 @@ import sentry_sdk from sentry_sdk.consts import OP from sentry_sdk.integrations import DidNotEnable, Integration -from sentry_sdk.integrations._wsgi_common import nullcontext from sentry_sdk.traces import StreamedSpan from sentry_sdk.tracing import Span from sentry_sdk.tracing_utils import has_span_streaming_enabled @@ -13,6 +12,7 @@ event_from_exception, is_internal_task, logger, + nullcontext, reraise, ) diff --git a/sentry_sdk/integrations/mcp.py b/sentry_sdk/integrations/mcp.py index 79381fe06e..dbfaa912c3 100644 --- a/sentry_sdk/integrations/mcp.py +++ b/sentry_sdk/integrations/mcp.py @@ -15,11 +15,10 @@ from sentry_sdk.ai.utils import _set_span_data_attribute, get_start_span_function from sentry_sdk.consts import OP, SPANDATA from sentry_sdk.integrations import DidNotEnable, Integration -from sentry_sdk.integrations._wsgi_common import nullcontext from sentry_sdk.scope import should_send_default_pii from sentry_sdk.traces import StreamedSpan from sentry_sdk.tracing_utils import has_span_streaming_enabled -from sentry_sdk.utils import package_version, safe_serialize +from sentry_sdk.utils import nullcontext, package_version, safe_serialize MCP_PACKAGE_VERSION = package_version("mcp") diff --git a/sentry_sdk/integrations/wsgi.py b/sentry_sdk/integrations/wsgi.py index e776ed915a..168b889b60 100644 --- a/sentry_sdk/integrations/wsgi.py +++ b/sentry_sdk/integrations/wsgi.py @@ -9,7 +9,6 @@ from sentry_sdk.integrations._wsgi_common import ( DEFAULT_HTTP_METHODS_TO_CAPTURE, _filter_headers, - nullcontext, ) from sentry_sdk.scope import Scope, should_send_default_pii, use_isolation_scope from sentry_sdk.sessions import track_session @@ -20,6 +19,7 @@ ContextVar, capture_internal_exceptions, event_from_exception, + nullcontext, reraise, ) diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 0963015351..5aa533dea0 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -2176,3 +2176,9 @@ def serialize_attribute(val: "AttributeValue") -> "SerializedAttributeValue": # Coerce to string if we don't know what to do with the value. This should # never happen as we pre-format early in format_attribute, but let's be safe. return {"value": safe_repr(val), "type": "string"} + + +# This noop context manager can be replaced with "from contextlib import nullcontext" when we drop Python 3.6 support +@contextmanager +def nullcontext() -> "Iterator[None]": + yield