Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
request_body_within_bounds,
)
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.scope import should_send_default_pii, Scope
from sentry_sdk.sessions import track_session
from sentry_sdk.traces import (
SOURCE_FOR_STYLE as SEGMENT_SOURCE_FOR_STYLE,
Expand Down Expand Up @@ -139,9 +139,7 @@ async def sentry_app_handle(
span_ctx: "ContextManager[Union[Span, StreamedSpan]]"
if is_span_streaming_enabled:
sentry_sdk.traces.continue_trace(headers)
sentry_sdk.get_current_scope().set_custom_sampling_context(
{"aiohttp_request": request}
)
Scope.set_custom_sampling_context({"aiohttp_request": request})

header_attributes: "dict[str, Any]" = {}
for header, header_value in _filter_headers(
Expand Down
9 changes: 3 additions & 6 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
capture_internal_exceptions,
qualname_from_function,
)
from sentry_sdk.scope import Scope

from typing import TYPE_CHECKING

Expand Down Expand Up @@ -257,9 +258,7 @@ async def _run_app(
):
sentry_sdk.traces.continue_trace(_get_headers(scope))

sentry_scope.set_custom_sampling_context(
{"asgi_scope": scope}
)
Scope.set_custom_sampling_context({"asgi_scope": scope})

attributes["sentry.op"] = f"{ty}.server"
segment = sentry_sdk.traces.start_span(
Expand All @@ -270,9 +269,7 @@ async def _run_app(
else:
sentry_sdk.traces.new_trace()

sentry_scope.set_custom_sampling_context(
{"asgi_scope": scope}
)
Scope.set_custom_sampling_context({"asgi_scope": scope})

attributes["sentry.op"] = OP.HTTP_SERVER
segment = sentry_sdk.traces.start_span(
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.scope import should_send_default_pii, Scope
from sentry_sdk.traces import StreamedSpan, _get_current_streamed_span
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, Span, TransactionSource
from sentry_sdk.tracing_utils import Baggage, has_span_streaming_enabled
Expand Down Expand Up @@ -361,7 +361,7 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any":
headers = args[3].get("headers") or {}
if span_streaming:
sentry_sdk.traces.continue_trace(headers)
scope.set_custom_sampling_context(custom_sampling_context)
Scope.set_custom_sampling_context(custom_sampling_context)
span = sentry_sdk.traces.start_span(
name=task_name,
parent_span=None, # make this a segment
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
_filter_headers,
nullcontext,
)
from sentry_sdk.scope import should_send_default_pii, use_isolation_scope
from sentry_sdk.scope import should_send_default_pii, use_isolation_scope, Scope
from sentry_sdk.sessions import track_session
from sentry_sdk.traces import StreamedSpan, SegmentSource
from sentry_sdk.tracing import Span, TransactionSource
Expand Down Expand Up @@ -132,7 +132,7 @@ def __call__(
sentry_sdk.traces.continue_trace(
dict(_get_headers(environ))
)
scope.set_custom_sampling_context({"wsgi_environ": environ})
Scope.set_custom_sampling_context({"wsgi_environ": environ})

span_ctx = sentry_sdk.traces.start_span(
name=_DEFAULT_TRANSACTION_NAME,
Expand Down
5 changes: 3 additions & 2 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,11 @@ def get_active_propagation_context(self) -> "PropagationContext":
isolation_scope._propagation_context = PropagationContext()
return isolation_scope._propagation_context

@classmethod
def set_custom_sampling_context(
self, custom_sampling_context: "dict[str, Any]"
cls, custom_sampling_context: "dict[str, Any]"
) -> None:
self.get_current_scope().get_active_propagation_context()._set_custom_sampling_context(
cls.get_current_scope().get_active_propagation_context()._set_custom_sampling_context(
custom_sampling_context
)

Expand Down
Loading