Skip to content

Commit 9711c99

Browse files
committed
fixes
1 parent be19ff4 commit 9711c99

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

sentry_sdk/integrations/opentelemetry/sampler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ def should_sample(
217217
sample_rand = parent_sample_rand
218218
else:
219219
# We are the head SDK and we need to generate a new sample_rand
220-
sample_rand = cast(Decimal, _generate_sample_rand(str(trace_id), (0, 1)))
220+
sample_rand = _generate_sample_rand(str(trace_id), (0, 1))
221+
222+
if sample_rand is None:
223+
# If we failed to generate a sample_rand, abort
224+
logger.debug(f"[Tracing] Failed to generate a sample_rand, dropping {name}")
225+
return dropped_result(parent_span_context, attributes)
221226

222227
# Explicit sampled value provided at start_span
223228
custom_sampled = cast(

tests/integrations/opentelemetry/test_propagator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ def test_inject_continue_trace(sentry_init):
139139
"HTTP_BAGGAGE": baggage,
140140
}
141141

142-
expected_baggage = baggage + ",sentry-sample_rand=0.002849"
142+
expected_baggage = baggage + ",sentry-sample_rand=0.001111"
143143

144144
with patch(
145145
"sentry_sdk.tracing_utils.Random.uniform",
146-
return_value=0.002849,
146+
return_value=0.001111,
147147
):
148148
with sentry_sdk.continue_trace(incoming_headers):
149149
with sentry_sdk.start_span(name="foo") as span:
@@ -195,12 +195,12 @@ def test_inject_head_sdk(sentry_init):
195195
"sentry-trace_id={trace_id},"
196196
"sentry-sample_rate=1.0,"
197197
"sentry-sampled=true,"
198-
"sentry-sample_rand=0.123456"
198+
"sentry-sample_rand=0.111111"
199199
)
200200

201201
with patch(
202202
"sentry_sdk.tracing_utils.Random.uniform",
203-
return_value=0.123456,
203+
return_value=0.111111,
204204
):
205205
with sentry_sdk.start_span(name="foo") as span:
206206
SentryPropagator().inject(carrier, setter=setter)

tests/integrations/stdlib/test_httplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def test_outgoing_trace_headers(
233233
"sentry-public_key=49d0f7386ad645858ae85020e393bef3,"
234234
"sentry-sample_rate=0.01337,"
235235
"sentry-user_id=Am%C3%A9lie,"
236-
"sentry-sample_rand=0.00337,"
236+
"sentry-sample_rand=0.003370,"
237237
"sentry-sampled=true"
238238
)
239239

tests/tracing/test_sample_rand.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ def test_invalid_sampled_and_sample_rate(sentry_init, incoming):
128128

129129
sample_rate, sampled = incoming
130130

131-
baggage = f"sentry-sample_rate={sample_rate},sentry-sampled={sampled},sentry-trace_id=771a43a4192642f0b136d5159a501700" # noqa: E231
131+
baggage = (
132+
f"sentry-sample_rate={sample_rate}," # noqa: E231
133+
f"sentry-sampled={sampled}," # noqa: E231
134+
"sentry-trace_id=771a43a4192642f0b136d5159a501700"
135+
)
132136
sentry_trace = f"771a43a4192642f0b136d5159a501700-1234567890abcdef-{1 if sampled == 'true' else 0}"
133137

134138
with sentry_sdk.continue_trace(

0 commit comments

Comments
 (0)