1+ from typing import cast
2+
13from opentelemetry import trace
24from opentelemetry .context import (
35 Context ,
46 get_current ,
7+ get_value ,
58 set_value ,
69)
710from opentelemetry .propagators .textmap import (
2124from sentry_sdk .integrations .opentelemetry .consts import (
2225 SENTRY_BAGGAGE_KEY ,
2326 SENTRY_TRACE_KEY ,
24- )
25- from sentry_sdk .integrations .opentelemetry .span_processor import (
26- SentrySpanProcessor ,
27+ SENTRY_SCOPES_KEY ,
2728)
2829from sentry_sdk .tracing import (
2930 BAGGAGE_HEADER_NAME ,
3536
3637if TYPE_CHECKING :
3738 from typing import Optional , Set
39+ from sentry_sdk .integrations .opentelemetry .scope import PotelScope
3840
3941
4042class SentryPropagator (TextMapPropagator ):
@@ -47,6 +49,7 @@ def extract(self, carrier, context=None, getter=default_getter):
4749 if context is None :
4850 context = get_current ()
4951
52+ # TODO-neel-potel cleanup with continue_trace / isolation_scope
5053 sentry_trace = getter .get (carrier , SENTRY_TRACE_HEADER_NAME )
5154 if not sentry_trace :
5255 return context
@@ -89,27 +92,15 @@ def inject(self, carrier, context=None, setter=default_setter):
8992 if context is None :
9093 context = get_current ()
9194
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
10699
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 )
113104
114105 @property
115106 def fields (self ):
0 commit comments