Skip to content

Commit 1a35a5e

Browse files
committed
ruff
1 parent d00c0f6 commit 1a35a5e

3 files changed

Lines changed: 54 additions & 31 deletions

File tree

sentry_sdk/scope.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ def start_streamed_span(
13621362
trace_id=parent_span.trace_id,
13631363
parent_span_id=parent_span.span_id,
13641364
parent_sampled=parent_span.sampled,
1365-
unsampled_reason=parent_span._unsampled_reason
1365+
unsampled_reason=parent_span._unsampled_reason,
13661366
)
13671367

13681368
return StreamedSpan(
@@ -1376,7 +1376,9 @@ def start_streamed_span(
13761376
parent_sampled=parent_span.sampled,
13771377
)
13781378

1379-
def _update_sample_rate(self, sample_rate: float, sampled: "Optional[bool]") -> None:
1379+
def _update_sample_rate(
1380+
self, sample_rate: float, sampled: "Optional[bool]"
1381+
) -> None:
13801382
# If we had to adjust the sample rate when setting the sampling decision
13811383
# for a span, it needs to be updated in the propagation context too
13821384
propagation_context = self.get_active_propagation_context()

sentry_sdk/tracing_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,9 @@ def _make_sampling_decision(
15801580
sample_rate = client.options["traces_sampler"](sampling_context)
15811581
else:
15821582
if propagation_context.parent_sampled is not None:
1583-
sample_rate = propagation_context._sample_rate() or propagation_context.parent_sampled
1583+
sample_rate = (
1584+
propagation_context._sample_rate() or propagation_context.parent_sampled
1585+
)
15841586
else:
15851587
sample_rate = client.options["traces_sample_rate"]
15861588

tests/tracing/test_span_streaming.py

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ def test_continue_trace_no_sample_rand(sentry_init, capture_items):
916916
# traces_sample_rate=None means tracing without performance: don't make
917917
# any sampling decisions; defer downstream
918918
None,
919-
)
919+
),
920920
)
921921
def test_outgoing_traceparent_and_baggage_head_sdk(sentry_init, traces_sample_rate):
922922
sentry_init(
@@ -945,7 +945,11 @@ def test_outgoing_traceparent_and_baggage_head_sdk(sentry_init, traces_sample_ra
945945
span_id = span.span_id
946946
assert traceparent == f"{trace_id}-{span_id}-0"
947947
elif expected_sampled is None:
948-
span_id = sentry_sdk.get_isolation_scope().get_active_propagation_context().span_id
948+
span_id = (
949+
sentry_sdk.get_isolation_scope()
950+
.get_active_propagation_context()
951+
.span_id
952+
)
949953
assert traceparent == f"{trace_id}-{span_id}"
950954

951955
baggage = sentry_sdk.get_baggage()
@@ -976,9 +980,11 @@ def test_outgoing_traceparent_and_baggage_head_sdk(sentry_init, traces_sample_ra
976980
# any sampling decisions on our end, propagate existing ones
977981
(None, False),
978982
(None, True),
979-
)
983+
),
980984
)
981-
def test_outgoing_traceparent_and_baggage_incoming_trace(sentry_init, traces_sample_rate, parent_sampled):
985+
def test_outgoing_traceparent_and_baggage_incoming_trace(
986+
sentry_init, traces_sample_rate, parent_sampled
987+
):
982988
"""The SDK respects a positive/negative incoming sampling decision."""
983989
sentry_init(
984990
traces_sample_rate=traces_sample_rate,
@@ -994,23 +1000,29 @@ def test_outgoing_traceparent_and_baggage_incoming_trace(sentry_init, traces_sam
9941000

9951001
if parent_sampled is True:
9961002
incoming_sentry_trace = f"{trace_id}-{parent_span_id}-1"
997-
incoming_baggage.update({
998-
"sentry-sample_rate": "0.75",
999-
"sentry-sample_rand": "0.500000",
1000-
"sentry-sampled": "true",
1001-
})
1003+
incoming_baggage.update(
1004+
{
1005+
"sentry-sample_rate": "0.75",
1006+
"sentry-sample_rand": "0.500000",
1007+
"sentry-sampled": "true",
1008+
}
1009+
)
10021010
elif parent_sampled is False:
10031011
incoming_sentry_trace = f"{trace_id}-{parent_span_id}-0"
1004-
incoming_baggage.update({
1005-
"sentry-sample_rate": "0.75",
1006-
"sentry-sample_rand": "0.800000",
1007-
"sentry-sampled": "false",
1008-
})
1012+
incoming_baggage.update(
1013+
{
1014+
"sentry-sample_rate": "0.75",
1015+
"sentry-sample_rand": "0.800000",
1016+
"sentry-sampled": "false",
1017+
}
1018+
)
10091019

10101020
sentry_sdk.traces.continue_trace(
10111021
{
10121022
"sentry-trace": incoming_sentry_trace,
1013-
"baggage": ",".join(sorted([f"{k}={v}" for k,v in incoming_baggage.items()])),
1023+
"baggage": ",".join(
1024+
sorted([f"{k}={v}" for k, v in incoming_baggage.items()])
1025+
),
10141026
}
10151027
)
10161028

@@ -1024,7 +1036,9 @@ def test_outgoing_traceparent_and_baggage_incoming_trace(sentry_init, traces_sam
10241036
# (it doesn't even make sense to start a span explicitly as we do in
10251037
# this test since tracing is turned off, but nothing should break
10261038
# either)
1027-
span_id = sentry_sdk.get_current_scope().get_active_propagation_context().span_id
1039+
span_id = (
1040+
sentry_sdk.get_current_scope().get_active_propagation_context().span_id
1041+
)
10281042
assert traceparent == f"{trace_id}-{span_id}"
10291043
else:
10301044
span_id = span.span_id
@@ -1048,9 +1062,11 @@ def test_outgoing_traceparent_and_baggage_incoming_trace(sentry_init, traces_sam
10481062
# traces_sample_rate=None means tracing without performance: don't make
10491063
# any sampling decisions on our end, propagate existing ones
10501064
None,
1051-
)
1065+
),
10521066
)
1053-
def test_outgoing_traceparent_and_baggage_incoming_trace_deferred(sentry_init, traces_sample_rate):
1067+
def test_outgoing_traceparent_and_baggage_incoming_trace_deferred(
1068+
sentry_init, traces_sample_rate
1069+
):
10541070
"""The SDK handles a deferred incoming sampling decision correctly."""
10551071
sentry_init(
10561072
traces_sample_rate=traces_sample_rate,
@@ -1067,15 +1083,14 @@ def test_outgoing_traceparent_and_baggage_incoming_trace_deferred(sentry_init, t
10671083
trace_id = "0af7651916cd43dd8448eb211c80319c"
10681084
parent_span_id = "b7ad6b7169203331"
10691085

1070-
incoming_baggage = {
1071-
"sentry-trace_id": trace_id,
1072-
"sentry-sample_rand": "0.500000"
1073-
}
1086+
incoming_baggage = {"sentry-trace_id": trace_id, "sentry-sample_rand": "0.500000"}
10741087

10751088
sentry_sdk.traces.continue_trace(
10761089
{
10771090
"sentry-trace": f"{trace_id}-{parent_span_id}-",
1078-
"baggage": ",".join(sorted([f"{k}={v}" for k,v in incoming_baggage.items()])),
1091+
"baggage": ",".join(
1092+
sorted([f"{k}={v}" for k, v in incoming_baggage.items()])
1093+
),
10791094
}
10801095
)
10811096

@@ -1089,7 +1104,9 @@ def test_outgoing_traceparent_and_baggage_incoming_trace_deferred(sentry_init, t
10891104
# (it doesn't even make sense to start a span explicitly as we do in
10901105
# this test since tracing is turned off, but nothing should break
10911106
# either)
1092-
span_id = sentry_sdk.get_current_scope().get_active_propagation_context().span_id
1107+
span_id = (
1108+
sentry_sdk.get_current_scope().get_active_propagation_context().span_id
1109+
)
10931110
else:
10941111
span_id = span.span_id
10951112

@@ -1107,10 +1124,12 @@ def test_outgoing_traceparent_and_baggage_incoming_trace_deferred(sentry_init, t
11071124
# If our sample rate is not None, we're expected to have made
11081125
# a sampling decision
11091126
expected_baggage = incoming_baggage
1110-
expected_baggage.update({
1111-
"sentry-sample_rate": str(traces_sample_rate),
1112-
"sentry-sampled": "true" if expected_sampled else "false",
1113-
})
1127+
expected_baggage.update(
1128+
{
1129+
"sentry-sample_rate": str(traces_sample_rate),
1130+
"sentry-sampled": "true" if expected_sampled else "false",
1131+
}
1132+
)
11141133
assert baggage_items == expected_baggage
11151134
else:
11161135
# If tracing is off, we should have deferred the decision further

0 commit comments

Comments
 (0)