Skip to content

Commit d9b7f71

Browse files
committed
remove parent_sampled
1 parent 1b8521b commit d9b7f71

File tree

5 files changed

+3
-42
lines changed

5 files changed

+3
-42
lines changed

MIGRATION_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
1010

1111
- The SDK now supports Python 3.7 and higher.
1212
- `sentry_sdk.start_span` now only takes keyword arguments.
13-
- `sentry_sdk.start_span` no longer takes an explicit `span` argument.
13+
- `sentry_sdk.start_transaction`/`sentry_sdk.start_span` no longer takes the following arguments: `span`, `parent_sampled`.
1414
- The `Span()` constructor does not accept a `hub` parameter anymore.
1515
- `Span.finish()` does not accept a `hub` parameter anymore.
1616
- The `Profile()` constructor does not accept a `hub` parameter anymore.

sentry_sdk/integrations/opentelemetry/consts.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,3 @@ class SentrySpanAttribute:
3131
SOURCE = "sentry.source"
3232
CONTEXT = "sentry.context"
3333
CUSTOM_SAMPLED = "sentry.custom_sampled" # used for saving start_span(sampled=X)
34-
CUSTOM_PARENT_SAMPLED = (
35-
"sentry.custom_parent_sampled" # used for saving start_span(parent_sampled=X)
36-
)

sentry_sdk/integrations/opentelemetry/sampler.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,21 @@ def should_sample(
141141
# Check if there is a traces_sampler
142142
# Traces_sampler is responsible to check parent sampled to have full transactions.
143143
has_traces_sampler = callable(client.options.get("traces_sampler"))
144-
parent_sampled = attributes.get(SentrySpanAttribute.CUSTOM_PARENT_SAMPLED)
145-
if parent_sampled is None:
146-
parent_sampled = get_parent_sampled(parent_span_context, trace_id)
147144

148145
if is_root_span and has_traces_sampler:
149146
sampling_context = {
150147
"transaction_context": {
151148
"name": name,
152149
"op": attributes.get(SentrySpanAttribute.OP),
153150
},
154-
"parent_sampled": parent_sampled,
151+
"parent_sampled": get_parent_sampled(parent_span_context, trace_id),
155152
}
156153
sampling_context.update(attributes)
157154
sample_rate = client.options["traces_sampler"](sampling_context)
158155

159156
else:
160157
# Check if there is a parent with a sampling decision
158+
parent_sampled = get_parent_sampled(parent_span_context, trace_id)
161159
if parent_sampled is not None:
162160
sample_rate = parent_sampled
163161
else:

sentry_sdk/tracing.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,10 +1253,6 @@ def __init__(
12531253
attributes[SentrySpanAttribute.OP] = op
12541254
if sampled is not None:
12551255
attributes[SentrySpanAttribute.CUSTOM_SAMPLED] = sampled
1256-
if parent_sampled is not None:
1257-
attributes[SentrySpanAttribute.CUSTOM_PARENT_SAMPLED] = (
1258-
parent_sampled
1259-
)
12601256

12611257
self._otel_span = tracer.start_span(
12621258
span_name, start_time=start_timestamp, attributes=attributes

tests/tracing/test_sampling.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,6 @@ def test_prefers_traces_sampler_to_traces_sample_rate(
137137
assert transaction.sampled is traces_sampler_return_value
138138

139139

140-
@pytest.mark.parametrize("parent_sampling_decision", [True, False])
141-
def test_ignores_inherited_sample_decision_when_traces_sampler_defined(
142-
sentry_init, parent_sampling_decision
143-
):
144-
# make traces_sampler pick the opposite of the inherited decision, to prove
145-
# that traces_sampler takes precedence
146-
traces_sampler = mock.Mock(return_value=not parent_sampling_decision)
147-
sentry_init(traces_sampler=traces_sampler)
148-
149-
transaction = start_transaction(
150-
name="dogpark", parent_sampled=parent_sampling_decision
151-
)
152-
assert transaction.sampled is not parent_sampling_decision
153-
154-
155140
@pytest.mark.parametrize("explicit_decision", [True, False])
156141
def test_traces_sampler_doesnt_overwrite_explicitly_passed_sampling_decision(
157142
sentry_init, explicit_decision
@@ -165,21 +150,6 @@ def test_traces_sampler_doesnt_overwrite_explicitly_passed_sampling_decision(
165150
assert transaction.sampled is explicit_decision
166151

167152

168-
@pytest.mark.parametrize("parent_sampling_decision", [True, False])
169-
def test_inherits_parent_sampling_decision_when_traces_sampler_undefined(
170-
sentry_init, parent_sampling_decision
171-
):
172-
# make sure the parent sampling decision is the opposite of what
173-
# traces_sample_rate would produce, to prove the inheritance takes
174-
# precedence
175-
sentry_init(traces_sample_rate=0.5)
176-
mock_random_value = 0.25 if parent_sampling_decision is False else 0.75
177-
178-
with mock.patch.object(random, "random", return_value=mock_random_value):
179-
span = start_span(name="dogpark", parent_sampled=parent_sampling_decision)
180-
assert span.sampled is parent_sampling_decision
181-
182-
183153
@pytest.mark.parametrize("parent_sampling_decision", [True, False])
184154
def test_passes_parent_sampling_decision_in_sampling_context(
185155
sentry_init, parent_sampling_decision

0 commit comments

Comments
 (0)