1
+ from typing import cast
2
+
1
3
from opentelemetry import trace
2
4
from opentelemetry .context import (
3
5
Context ,
4
6
get_current ,
7
+ get_value ,
5
8
set_value ,
6
9
)
7
10
from opentelemetry .propagators .textmap import (
21
24
from sentry_sdk .integrations .opentelemetry .consts import (
22
25
SENTRY_BAGGAGE_KEY ,
23
26
SENTRY_TRACE_KEY ,
24
- )
25
- from sentry_sdk .integrations .opentelemetry .span_processor import (
26
- SentrySpanProcessor ,
27
+ SENTRY_SCOPES_KEY ,
27
28
)
28
29
from sentry_sdk .tracing import (
29
30
BAGGAGE_HEADER_NAME ,
35
36
36
37
if TYPE_CHECKING :
37
38
from typing import Optional , Set
39
+ from sentry_sdk .integrations .opentelemetry .scope import PotelScope
38
40
39
41
40
42
class SentryPropagator (TextMapPropagator ):
@@ -47,6 +49,7 @@ def extract(self, carrier, context=None, getter=default_getter):
47
49
if context is None :
48
50
context = get_current ()
49
51
52
+ # TODO-neel-potel cleanup with continue_trace / isolation_scope
50
53
sentry_trace = getter .get (carrier , SENTRY_TRACE_HEADER_NAME )
51
54
if not sentry_trace :
52
55
return context
@@ -89,27 +92,15 @@ def inject(self, carrier, context=None, setter=default_setter):
89
92
if context is None :
90
93
context = get_current ()
91
94
92
- current_span = trace .get_current_span (context )
93
- current_span_context = current_span .get_span_context ()
94
-
95
- if not current_span_context .is_valid :
96
- return
97
-
98
- span_id = trace .format_span_id (current_span_context .span_id )
99
-
100
- span_map = SentrySpanProcessor ().otel_span_map
101
- sentry_span = span_map .get (span_id , None )
102
- if not sentry_span :
103
- return
104
-
105
- setter .set (carrier , SENTRY_TRACE_HEADER_NAME , sentry_span .to_traceparent ())
95
+ scopes = get_value (SENTRY_SCOPES_KEY , context )
96
+ if scopes :
97
+ scopes = cast ("tuple[PotelScope, PotelScope]" , scopes )
98
+ (current_scope , _ ) = scopes
106
99
107
- if sentry_span .containing_transaction :
108
- baggage = sentry_span .containing_transaction .get_baggage ()
109
- if baggage :
110
- baggage_data = baggage .serialize ()
111
- if baggage_data :
112
- setter .set (carrier , BAGGAGE_HEADER_NAME , baggage_data )
100
+ # TODO-neel-potel check trace_propagation_targets
101
+ # TODO-neel-potel test propagator works with twp
102
+ for (key , value ) in current_scope .iter_trace_propagation_headers ():
103
+ setter .set (carrier , key , value )
113
104
114
105
@property
115
106
def fields (self ):
0 commit comments