@@ -583,22 +583,23 @@ def _set_initial_sampling_decision(self, sampling_context):
583583 decision, `traces_sample_rate` will be used.
584584 """
585585
586+ # if the user has forced a sampling decision by passing a `sampled`
587+ # value when starting the transaction, go with that
588+ if self .sampled is not None :
589+ return
590+
586591 hub = self .hub or sentry_sdk .Hub .current
587592 client = hub .client
588- options = (client and client .options ) or {}
589593 transaction_description = "{op}transaction <{name}>" .format (
590594 op = ("<" + self .op + "> " if self .op else "" ), name = self .name
591595 )
592596
593- # nothing to do if there's no client or if tracing is disabled
594- if not client or not has_tracing_enabled ( options ) :
597+ # nothing to do if there's no client
598+ if not client :
595599 self .sampled = False
596600 return
597601
598- # if the user has forced a sampling decision by passing a `sampled`
599- # value when starting the transaction, go with that
600- if self .sampled is not None :
601- return
602+ options = client .options
602603
603604 # we would have bailed already if neither `traces_sampler` nor
604605 # `traces_sample_rate` were defined, so one of these should work; prefer
@@ -662,16 +663,6 @@ def _set_initial_sampling_decision(self, sampling_context):
662663 )
663664
664665
665- def has_tracing_enabled (options ):
666- # type: (Dict[str, Any]) -> bool
667- """
668- Returns True if either traces_sample_rate or traces_sampler is
669- non-zero/defined, False otherwise.
670- """
671-
672- return bool (options .get ("traces_sample_rate" ) or options .get ("traces_sampler" ))
673-
674-
675666def _is_valid_sample_rate (rate ):
676667 # type: (Any) -> bool
677668 """
0 commit comments