@@ -583,23 +583,22 @@ 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-
591586 hub = self .hub or sentry_sdk .Hub .current
592587 client = hub .client
588+ options = (client and client .options ) or {}
593589 transaction_description = "{op}transaction <{name}>" .format (
594590 op = ("<" + self .op + "> " if self .op else "" ), name = self .name
595591 )
596592
597- # nothing to do if there's no client
598- if not client :
593+ # nothing to do if there's no client or if tracing is disabled
594+ if not client or not has_tracing_enabled ( options ) :
599595 self .sampled = False
600596 return
601597
602- options = client .options
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
603602
604603 # we would have bailed already if neither `traces_sampler` nor
605604 # `traces_sample_rate` were defined, so one of these should work; prefer
@@ -663,6 +662,19 @@ def _set_initial_sampling_decision(self, sampling_context):
663662 )
664663
665664
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 (
673+ options .get ("traces_sample_rate" ) is not None
674+ or options .get ("traces_sampler" ) is not None
675+ )
676+
677+
666678def _is_valid_sample_rate (rate ):
667679 # type: (Any) -> bool
668680 """
0 commit comments