Skip to content

Commit 981da49

Browse files
committed
Move downsampling after checking for valid sample rate
1 parent 6c39b60 commit 981da49

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

sentry_sdk/integrations/opentelemetry/sampler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,18 @@ def should_sample(
143143
# Check if there is a traces_sample_rate
144144
sample_rate = client.options.get("traces_sample_rate")
145145

146-
# Down-sample in case of back pressure monitor says so
147-
# TODO: this should only be done for transactions (aka root spans)
148-
if client.monitor:
149-
sample_rate /= 2**client.monitor.downsample_factor
150-
151146
# If the sample rate is invalid, drop the span
152147
if not is_valid_sample_rate(sample_rate, source=self.__class__.__name__):
153148
logger.warning(
154149
f"[Tracing] Discarding {name} because of invalid sample rate."
155150
)
156151
return dropped_result(parent_span_context, attributes)
157152

153+
# Down-sample in case of back pressure monitor says so
154+
# TODO: this should only be done for transactions (aka root spans)
155+
if client.monitor:
156+
sample_rate /= 2**client.monitor.downsample_factor
157+
158158
# Roll the dice on sample rate
159159
sample_rate = float(cast("Union[bool, float, int]", sample_rate))
160160
sampled = random.random() < sample_rate

0 commit comments

Comments
 (0)