File tree Expand file tree Collapse file tree 5 files changed +21
-20
lines changed
integrations/opentelemetry Expand file tree Collapse file tree 5 files changed +21
-20
lines changed Original file line number Diff line number Diff line change 11from typing import TYPE_CHECKING
22
33import sentry_sdk
4+ from sentry_sdk .integrations .opentelemetry .scope import setup_scope_context_management
45
56if TYPE_CHECKING :
67 from typing import Any , Optional
@@ -24,6 +25,7 @@ def _init(*args, **kwargs):
2425 """
2526 client = sentry_sdk .Client (* args , ** kwargs )
2627 sentry_sdk .get_global_scope ().set_client (client )
28+ setup_scope_context_management ()
2729 _check_python_deprecations ()
2830
2931
Original file line number Diff line number Diff line change 55"""
66
77from sentry_sdk .integrations import DidNotEnable , Integration
8- from sentry_sdk .integrations .opentelemetry .scope import setup_initial_scopes
98from sentry_sdk .integrations .opentelemetry .propagator import SentryPropagator
109from sentry_sdk .integrations .opentelemetry .span_processor import (
1110 SentrySpanProcessor ,
1211)
13- from sentry_sdk .integrations .opentelemetry .contextvars_context import (
14- SentryContextVarsRuntimeContext ,
15- )
1612from sentry_sdk .integrations .opentelemetry .sampler import SentrySampler
1713from sentry_sdk .utils import logger
1814
@@ -45,7 +41,6 @@ def setup_once():
4541 "Use at your own risk."
4642 )
4743
48- _setup_scope_context_management ()
4944 _setup_sentry_tracing ()
5045 _patch_readable_span ()
5146 # _setup_instrumentors()
@@ -70,14 +65,6 @@ def sentry_patched_readable_span(self):
7065 Span ._readable_span = sentry_patched_readable_span
7166
7267
73- def _setup_scope_context_management ():
74- # type: () -> None
75- import opentelemetry .context
76-
77- opentelemetry .context ._RUNTIME_CONTEXT = SentryContextVarsRuntimeContext ()
78- setup_initial_scopes ()
79-
80-
8168def _setup_sentry_tracing ():
8269 # type: () -> None
8370 provider = TracerProvider (sampler = SentrySampler ())
Original file line number Diff line number Diff line change 22from contextlib import contextmanager
33
44from opentelemetry .context import (
5- Context ,
65 get_value ,
76 set_value ,
87 attach ,
2423 SENTRY_USE_ISOLATION_SCOPE_KEY ,
2524 TRACESTATE_SAMPLED_KEY ,
2625)
26+ from sentry_sdk .integrations .opentelemetry .contextvars_context import (
27+ SentryContextVarsRuntimeContext ,
28+ )
2729from sentry_sdk .integrations .opentelemetry .utils import trace_state_from_baggage
2830from sentry_sdk .scope import Scope , ScopeType
2931from sentry_sdk .tracing import POTelSpan
@@ -152,6 +154,14 @@ def setup_initial_scopes():
152154 attach (set_value (SENTRY_SCOPES_KEY , scopes ))
153155
154156
157+ def setup_scope_context_management ():
158+ # type: () -> None
159+ import opentelemetry .context
160+
161+ opentelemetry .context ._RUNTIME_CONTEXT = SentryContextVarsRuntimeContext ()
162+ setup_initial_scopes ()
163+
164+
155165@contextmanager
156166def isolation_scope ():
157167 # type: () -> Generator[Scope, None, None]
Original file line number Diff line number Diff line change @@ -62,7 +62,10 @@ def benchmark():
6262
6363
6464from sentry_sdk import scope
65- import sentry_sdk .integrations .opentelemetry .scope as potel_scope
65+ from sentry_sdk .integrations .opentelemetry .scope import (
66+ setup_scope_context_management ,
67+ setup_initial_scopes ,
68+ )
6669
6770
6871@pytest .fixture (autouse = True )
@@ -74,7 +77,7 @@ def clean_scopes():
7477 scope ._isolation_scope .set (None )
7578 scope ._current_scope .set (None )
7679
77- potel_scope . setup_initial_scopes ()
80+ setup_initial_scopes ()
7881
7982
8083@pytest .fixture (autouse = True )
@@ -187,6 +190,7 @@ def inner(*a, **kw):
187190 kw .setdefault ("transport" , TestTransport ())
188191 client = sentry_sdk .Client (* a , ** kw )
189192 sentry_sdk .get_global_scope ().set_client (client )
193+ setup_scope_context_management ()
190194
191195 if request .node .get_closest_marker ("forked" ):
192196 # Do not run isolation if the test is already running in
Original file line number Diff line number Diff line change 1515 ScopeType ,
1616 should_send_default_pii ,
1717)
18- from sentry_sdk .integrations .opentelemetry .integration import (
19- _setup_scope_context_management ,
20- )
2118from sentry_sdk .integrations .opentelemetry .scope import (
2219 PotelScope as Scope ,
2320 use_scope ,
2421 use_isolation_scope ,
22+ setup_scope_context_management ,
2523)
2624
2725
3129
3230@pytest .fixture (autouse = True )
3331def setup_otel_scope_management ():
34- _setup_scope_context_management ()
32+ setup_scope_context_management ()
3533
3634
3735def test_copying ():
You can’t perform that action at this time.
0 commit comments