@@ -525,15 +525,14 @@ 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- if self ._propagation_context is None :
530- return None
531-
532- baggage = self .get_baggage ()
533- if baggage is not None :
534- self ._propagation_context .baggage = baggage
535528
536- return self ._propagation_context .dynamic_sampling_context
529+ Deprecated: Logic moved to PropagationContext, don't use directly.
530+ """
531+ return (
532+ self ._propagation_context .dynamic_sampling_context
533+ if self ._propagation_context
534+ else None
535+ )
537536
538537 def get_traceparent (self , * args , ** kwargs ):
539538 # type: (Any, Any) -> Optional[str]
@@ -548,15 +547,9 @@ def get_traceparent(self, *args, **kwargs):
548547 return self .span .to_traceparent ()
549548
550549 # 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
557-
558- # Fall back to isolation scope's traceparent. It always has one
559- return self .get_isolation_scope ().get_traceparent ()
550+ propagation_context = self .get_active_propagation_context ()
551+ if propagation_context is not None :
552+ return propagation_context .get_traceparent ()
560553
561554 def get_baggage (self , * args , ** kwargs ):
562555 # type: (Any, Any) -> Optional[Baggage]
@@ -571,11 +564,9 @@ def get_baggage(self, *args, **kwargs):
571564 return self .span .to_baggage ()
572565
573566 # 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 )
576-
577- # Fall back to isolation scope's baggage. It always has one
578- return self .get_isolation_scope ().get_baggage ()
567+ propagation_context = self .get_active_propagation_context ()
568+ if propagation_context is not None :
569+ return propagation_context .get_baggage ()
579570
580571 def get_trace_context (self ):
581572 # type: () -> Dict[str, Any]
@@ -599,7 +590,7 @@ def get_trace_context(self):
599590 "trace_id" : propagation_context .trace_id ,
600591 "span_id" : propagation_context .span_id ,
601592 "parent_span_id" : propagation_context .parent_span_id ,
602- "dynamic_sampling_context" : self . get_dynamic_sampling_context () ,
593+ "dynamic_sampling_context" : propagation_context . dynamic_sampling_context ,
603594 }
604595
605596 def trace_propagation_meta (self , * args , ** kwargs ):
@@ -616,36 +607,25 @@ def trace_propagation_meta(self, *args, **kwargs):
616607
617608 meta = ""
618609
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- )
610+ for name , content in self .iter_trace_propagation_headers ():
611+ meta += f'<meta name="{ name } " content="{ content } ">'
632612
633613 return meta
634614
635615 def iter_headers (self ):
636616 # type: () -> Iterator[Tuple[str, str]]
637617 """
638618 Creates a generator which returns the `sentry-trace` and `baggage` headers from the Propagation Context.
619+ Deprecated: use PropagationContext.iter_headers instead.
639620 """
640621 if self ._propagation_context is not None :
641622 traceparent = self .get_traceparent ()
642623 if traceparent is not None :
643624 yield SENTRY_TRACE_HEADER_NAME , traceparent
644625
645- dsc = self .get_dynamic_sampling_context ()
646- if dsc is not None :
647- baggage = Baggage (dsc ).serialize ()
648- yield BAGGAGE_HEADER_NAME , baggage
626+ baggage = self .get_baggage ()
627+ if baggage is not None :
628+ yield BAGGAGE_HEADER_NAME , baggage .serialize ()
649629
650630 def iter_trace_propagation_headers (self , * args , ** kwargs ):
651631 # type: (Any, Any) -> Generator[Tuple[str, str], None, None]
@@ -671,23 +651,10 @@ def iter_trace_propagation_headers(self, *args, **kwargs):
671651 for header in span .iter_headers ():
672652 yield header
673653 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 ():
654+ propagation_context = self .get_active_propagation_context ()
655+ if propagation_context is not None :
656+ for header in propagation_context .iter_headers ():
678657 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
691658
692659 def get_active_propagation_context (self ):
693660 # type: () -> Optional[PropagationContext]
0 commit comments