Skip to content

Commit 4516e8e

Browse files
committed
.
1 parent 030423c commit 4516e8e

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

sentry_sdk/tracing_utils.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import contextlib
22
import inspect
3-
import math
43
import os
54
import re
65
import sys
@@ -867,13 +866,9 @@ def _generate_sample_rand(
867866
raise ValueError("Invalid interval: lower must be less than upper")
868867

869868
rng = Random(trace_id)
870-
sample_rand = upper
871-
while sample_rand >= upper:
872-
sample_rand = rng.uniform(lower, upper)
869+
sample_rand_scaled = rng.randrange(int(lower * 1000000), int(upper * 1000000))
873870

874-
# Round down to exactly six decimal-digit precision.
875-
# Using floor to ensure we always round down, similar to ROUND_DOWN
876-
return math.floor(sample_rand * 1000000) / 1000000
871+
return sample_rand_scaled / 1000000
877872

878873

879874
def _sample_rand_range(parent_sampled, sample_rate):

sentry_sdk/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,9 @@ def try_convert(convert_func, value):
19351935
given function. Return None if the conversion fails, i.e. if the function
19361936
raises an exception.
19371937
"""
1938+
if isinstance(value, convert_func):
1939+
return value
1940+
19381941
try:
19391942
return convert_func(value)
19401943
except Exception:

0 commit comments

Comments
 (0)