Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(
attach_stacktrace=False, # type: bool
ca_certs=None, # type: Optional[str]
propagate_traces=True, # type: bool
traces_sample_rate=0.0, # type: float
traces_sample_rate=None, # type: Optional[float]
traces_sampler=None, # type: Optional[TracesSampler]
auto_enabling_integrations=True, # type: bool
_experiments={}, # type: Experiments # noqa: B006
Expand Down
28 changes: 20 additions & 8 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,23 +583,22 @@ def _set_initial_sampling_decision(self, sampling_context):
decision, `traces_sample_rate` will be used.
"""

# if the user has forced a sampling decision by passing a `sampled`
# value when starting the transaction, go with that
if self.sampled is not None:
return

hub = self.hub or sentry_sdk.Hub.current
client = hub.client
options = (client and client.options) or {}
transaction_description = "{op}transaction <{name}>".format(
op=("<" + self.op + "> " if self.op else ""), name=self.name
)

# nothing to do if there's no client
if not client:
# nothing to do if there's no client or if tracing is disabled
if not client or not has_tracing_enabled(options):
self.sampled = False
return

options = client.options
# if the user has forced a sampling decision by passing a `sampled`
# value when starting the transaction, go with that
if self.sampled is not None:
return

# we would have bailed already if neither `traces_sampler` nor
# `traces_sample_rate` were defined, so one of these should work; prefer
Expand Down Expand Up @@ -663,6 +662,19 @@ def _set_initial_sampling_decision(self, sampling_context):
)


def has_tracing_enabled(options):
# type: (Dict[str, Any]) -> bool
"""
Returns True if either traces_sample_rate or traces_sampler is
non-zero/defined, False otherwise.
"""

return bool(
options.get("traces_sample_rate") is not None
or options.get("traces_sampler") is not None
)


def _is_valid_sample_rate(rate):
# type: (Any) -> bool
"""
Expand Down