@@ -525,14 +525,12 @@ def get_dynamic_sampling_context(self):
525525 """
526526 Returns the Dynamic Sampling Context from the Propagation Context.
527527 If not existing, creates a new one.
528+
529+ Deprecated: Logic moved to PropagationContext, don't use directly.
528530 """
529531 if self ._propagation_context is None :
530532 return None
531533
532- baggage = self .get_baggage ()
533- if baggage is not None :
534- self ._propagation_context .baggage = baggage
535-
536534 return self ._propagation_context .dynamic_sampling_context
537535
538536 def get_traceparent (self , * args , ** kwargs ):
@@ -547,16 +545,13 @@ def get_traceparent(self, *args, **kwargs):
547545 if has_tracing_enabled (client .options ) and self .span is not None :
548546 return self .span .to_traceparent ()
549547
550- # If this scope has a propagation context, return traceparent from there
551- if self ._propagation_context is not None :
552- traceparent = "%s-%s" % (
553- self ._propagation_context .trace_id ,
554- self ._propagation_context .span_id ,
555- )
556- return traceparent
548+ # else return traceparent from the propagation context
549+ propagation_context = self .get_active_propagation_context ()
550+ if propagation_context is not None :
551+ return propagation_context .get_traceparent ()
557552
558- # Fall back to isolation scope's traceparent. It always has one
559- return self . get_isolation_scope (). get_traceparent ()
553+ # TODO-neel will never happen
554+ return None
560555
561556 def get_baggage (self , * args , ** kwargs ):
562557 # type: (Any, Any) -> Optional[Baggage]
@@ -570,12 +565,13 @@ def get_baggage(self, *args, **kwargs):
570565 if has_tracing_enabled (client .options ) and self .span is not None :
571566 return self .span .to_baggage ()
572567
573- # If this scope has a propagation context, return baggage from there
574- if self ._propagation_context is not None :
575- return self ._propagation_context .baggage or Baggage .from_options (self )
568+ # else return baggage from the propagation context
569+ propagation_context = self .get_active_propagation_context ()
570+ if propagation_context is not None :
571+ return propagation_context .get_baggage ()
576572
577- # Fall back to isolation scope's baggage. It always has one
578- return self . get_isolation_scope (). get_baggage ()
573+ # TODO-neel will never happen
574+ return None
579575
580576 def get_trace_context (self ):
581577 # type: () -> Dict[str, Any]
@@ -599,7 +595,7 @@ def get_trace_context(self):
599595 "trace_id" : propagation_context .trace_id ,
600596 "span_id" : propagation_context .span_id ,
601597 "parent_span_id" : propagation_context .parent_span_id ,
602- "dynamic_sampling_context" : self . get_dynamic_sampling_context () ,
598+ "dynamic_sampling_context" : propagation_context . dynamic_sampling_context ,
603599 }
604600
605601 def trace_propagation_meta (self , * args , ** kwargs ):
@@ -616,36 +612,19 @@ def trace_propagation_meta(self, *args, **kwargs):
616612
617613 meta = ""
618614
619- sentry_trace = self .get_traceparent ()
620- if sentry_trace is not None :
621- meta += '<meta name="%s" content="%s">' % (
622- SENTRY_TRACE_HEADER_NAME ,
623- sentry_trace ,
624- )
625-
626- baggage = self .get_baggage ()
627- if baggage is not None :
628- meta += '<meta name="%s" content="%s">' % (
629- BAGGAGE_HEADER_NAME ,
630- baggage .serialize (),
631- )
615+ for name , content in self .iter_trace_propagation_headers ():
616+ meta += f'<meta name="{ name } " content="{ content } ">'
632617
633618 return meta
634619
635620 def iter_headers (self ):
636621 # type: () -> Iterator[Tuple[str, str]]
637622 """
638623 Creates a generator which returns the `sentry-trace` and `baggage` headers from the Propagation Context.
624+ Deprecated: use PropagationContext.iter_headers instead.
639625 """
640626 if self ._propagation_context is not None :
641- traceparent = self .get_traceparent ()
642- if traceparent is not None :
643- yield SENTRY_TRACE_HEADER_NAME , traceparent
644-
645- dsc = self .get_dynamic_sampling_context ()
646- if dsc is not None :
647- baggage = Baggage (dsc ).serialize ()
648- yield BAGGAGE_HEADER_NAME , baggage
627+ yield from self ._propagation_context .iter_headers ()
649628
650629 def iter_trace_propagation_headers (self , * args , ** kwargs ):
651630 # type: (Any, Any) -> Generator[Tuple[str, str], None, None]
@@ -671,23 +650,10 @@ def iter_trace_propagation_headers(self, *args, **kwargs):
671650 for header in span .iter_headers ():
672651 yield header
673652 else :
674- # If this scope has a propagation context, return headers from there
675- # (it could be that self is not the current scope nor the isolation scope)
676- if self ._propagation_context is not None :
677- for header in self .iter_headers ():
653+ propagation_context = self .get_active_propagation_context ()
654+ if propagation_context is not None :
655+ for header in propagation_context .iter_headers ():
678656 yield header
679- else :
680- # otherwise try headers from current scope
681- current_scope = self .get_current_scope ()
682- if current_scope ._propagation_context is not None :
683- for header in current_scope .iter_headers ():
684- yield header
685- else :
686- # otherwise fall back to headers from isolation scope
687- isolation_scope = self .get_isolation_scope ()
688- if isolation_scope ._propagation_context is not None :
689- for header in isolation_scope .iter_headers ():
690- yield header
691657
692658 def get_active_propagation_context (self ):
693659 # type: () -> Optional[PropagationContext]
0 commit comments