Skip to content

Commit 6abb38c

Browse files
committed
simplify logic in sampler
1 parent 8830e34 commit 6abb38c

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

sentry_sdk/integrations/opentelemetry/sampler.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import sentry_sdk
99
from sentry_sdk.tracing_utils import (
1010
_generate_sample_rand,
11-
_sample_rand_range,
1211
has_tracing_enabled,
1312
)
1413
from sentry_sdk.utils import is_valid_sample_rate, logger
@@ -211,25 +210,12 @@ def should_sample(
211210
parent_sample_rand = get_parent_sample_rand(parent_span_context, trace_id)
212211

213212
if parent_sample_rand is not None:
213+
# We have a sample_rand on the incoming trace or we already backfilled
214+
# it in PropagationContext
214215
sample_rand = parent_sample_rand
215216
else:
216-
lower, upper = _sample_rand_range(parent_sampled, parent_sample_rate)
217-
218-
try:
219-
sample_rand = _generate_sample_rand(str(trace_id), (lower, upper))
220-
except ValueError:
221-
# ValueError is raised if the interval is invalid, i.e. lower >= upper.
222-
# lower >= upper might happen if the incoming trace's sampled flag
223-
# and sample_rate are inconsistent, e.g. sample_rate=0.0 but sampled=True.
224-
# We cannot generate a sensible sample_rand value in this case.
225-
logger.debug(
226-
f"Could not generate sample_rand, since parent_sampled={parent_sampled} "
227-
f"and sample_rate={sample_rate}."
228-
)
229-
logger.warning(
230-
f"[Tracing] Discarding {name} because of invalid sample rate/sampled."
231-
)
232-
return dropped_result(parent_span_context, attributes)
217+
# There is no sample_rand yet, generate a new one
218+
sample_rand = _generate_sample_rand(str(trace_id), (0, 1))
233219

234220
# Explicit sampled value provided at start_span
235221
custom_sampled = cast(

0 commit comments

Comments
 (0)