|
8 | 8 | import sentry_sdk |
9 | 9 | from sentry_sdk.tracing_utils import ( |
10 | 10 | _generate_sample_rand, |
11 | | - _sample_rand_range, |
12 | 11 | has_tracing_enabled, |
13 | 12 | ) |
14 | 13 | from sentry_sdk.utils import is_valid_sample_rate, logger |
@@ -211,25 +210,12 @@ def should_sample( |
211 | 210 | parent_sample_rand = get_parent_sample_rand(parent_span_context, trace_id) |
212 | 211 |
|
213 | 212 | 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 |
214 | 215 | sample_rand = parent_sample_rand |
215 | 216 | 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)) |
233 | 219 |
|
234 | 220 | # Explicit sampled value provided at start_span |
235 | 221 | custom_sampled = cast( |
|
0 commit comments