Skip to content

Commit 88cc5b2

Browse files
committed
Refactor get_parent_sampling_decision to remove unnecessary try/rescue and simplify logic
1 parent 57a0192 commit 88cc5b2

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

lib/sentry/opentelemetry/sampler.ex

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,25 @@ if Code.ensure_loaded?(:otel_sampler) do
4545
end
4646

4747
defp get_parent_sampling_decision(ctx, trace_id) do
48-
try do
49-
case :otel_tracer.current_span_ctx(ctx) do
50-
:undefined ->
51-
:no_parent
48+
case :otel_tracer.current_span_ctx(ctx) do
49+
:undefined ->
50+
:no_parent
5251

53-
span_ctx ->
54-
parent_trace_id = :otel_span.trace_id(span_ctx)
52+
span_ctx ->
53+
parent_trace_id = :otel_span.trace_id(span_ctx)
5554

56-
if parent_trace_id == trace_id do
57-
tracestate = :otel_span.tracestate(span_ctx)
58-
parent_sampled = get_tracestate_value(tracestate, @sentry_sampled_key)
55+
if parent_trace_id == trace_id do
56+
tracestate = :otel_span.tracestate(span_ctx)
57+
parent_sampled = get_tracestate_value(tracestate, @sentry_sampled_key)
5958

60-
case parent_sampled do
61-
"true" -> {:inherit, true, tracestate}
62-
"false" -> {:inherit, false, tracestate}
63-
_ -> :no_parent
64-
end
65-
else
66-
:no_parent
59+
case parent_sampled do
60+
"true" -> {:inherit, true, tracestate}
61+
"false" -> {:inherit, false, tracestate}
62+
_ -> :no_parent
6763
end
68-
end
69-
rescue
70-
_ -> :no_parent
64+
else
65+
:no_parent
66+
end
7167
end
7268
end
7369

0 commit comments

Comments
 (0)