Skip to content

Commit 33d6f1b

Browse files
committed
chore: Remove start_span(sampled=X)
1 parent a2ce2bb commit 33d6f1b

File tree

6 files changed

+9
-58
lines changed

6 files changed

+9
-58
lines changed

MIGRATION_GUIDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
156156
- `profiles_sample_rate` and `profiler_mode` were removed from options available via `_experiments`. Use the top-level `profiles_sample_rate` and `profiler_mode` options instead.
157157
- `Transport.capture_event` has been removed. Use `Transport.capture_envelope` instead.
158158
- Function transports are no longer supported. Subclass the `Transport` instead.
159+
- `start_transaction` (`start_span`) no longer takes an explicit `sampled` argument.
159160

160161
### Deprecated
161162

sentry_sdk/integrations/opentelemetry/consts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@ class SentrySpanAttribute:
3030
NAME = "sentry.name"
3131
SOURCE = "sentry.source"
3232
CONTEXT = "sentry.context"
33-
CUSTOM_SAMPLED = "sentry.custom_sampled" # used for saving start_span(sampled=X)

sentry_sdk/integrations/opentelemetry/sampler.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,6 @@ def should_sample(
156156

157157
sample_rate = None
158158

159-
# Explicit sampled value provided at start_span
160-
custom_sampled = cast(
161-
"Optional[bool]", attributes.get(SentrySpanAttribute.CUSTOM_SAMPLED)
162-
)
163-
if custom_sampled is not None:
164-
if is_root_span:
165-
sample_rate = float(custom_sampled)
166-
if sample_rate > 0:
167-
return sampled_result(
168-
parent_span_context, attributes, sample_rate=sample_rate
169-
)
170-
else:
171-
return dropped_result(
172-
parent_span_context, attributes, sample_rate=sample_rate
173-
)
174-
else:
175-
logger.debug(
176-
f"[Tracing] Ignoring sampled param for non-root span {name}"
177-
)
178-
179159
# Check if there is a traces_sampler
180160
# Traces_sampler is responsible to check parent sampled to have full transactions.
181161
has_traces_sampler = callable(client.options.get("traces_sampler"))

sentry_sdk/tracing.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from sentry_sdk.utils import (
2121
_serialize_span_attribute,
2222
get_current_thread_meta,
23-
logger,
2423
should_be_treated_as_error,
2524
)
2625

@@ -364,8 +363,6 @@ def __init__(
364363
attributes[SentrySpanAttribute.OP] = op
365364
if source is not None:
366365
attributes[SentrySpanAttribute.SOURCE] = source
367-
if sampled is not None:
368-
attributes[SentrySpanAttribute.CUSTOM_SAMPLED] = sampled
369366

370367
parent_context = None
371368
if parent_span is not None:

tests/integrations/sqlalchemy/test_sqlalchemy.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class Address(Base):
111111
Session = sessionmaker(bind=engine) # noqa: N806
112112
session = Session()
113113

114-
with sentry_sdk.start_span(name="test_transaction", sampled=True):
114+
with sentry_sdk.start_span(name="test_transaction"):
115115
with session.begin_nested():
116116
session.query(Person).first()
117117

@@ -185,7 +185,7 @@ class Address(Base):
185185
Session = sessionmaker(bind=engine) # noqa: N806
186186
session = Session()
187187

188-
with sentry_sdk.start_span(name="test_transaction", sampled=True):
188+
with sentry_sdk.start_span(name="test_transaction"):
189189
with session.begin_nested():
190190
session.query(Person).first()
191191

@@ -304,7 +304,7 @@ def test_query_source_disabled(sentry_init, capture_events):
304304

305305
events = capture_events()
306306

307-
with sentry_sdk.start_span(name="test_transaction", sampled=True):
307+
with sentry_sdk.start_span(name="test_transaction"):
308308
Base = declarative_base() # noqa: N806
309309

310310
class Person(Base):
@@ -356,7 +356,7 @@ def test_query_source_enabled(sentry_init, capture_events, enable_db_query_sourc
356356

357357
events = capture_events()
358358

359-
with sentry_sdk.start_span(name="test_transaction", sampled=True):
359+
with sentry_sdk.start_span(name="test_transaction"):
360360
Base = declarative_base() # noqa: N806
361361

362362
class Person(Base):
@@ -403,7 +403,7 @@ def test_query_source(sentry_init, capture_events):
403403
)
404404
events = capture_events()
405405

406-
with sentry_sdk.start_span(name="test_transaction", sampled=True):
406+
with sentry_sdk.start_span(name="test_transaction"):
407407
Base = declarative_base() # noqa: N806
408408

409409
class Person(Base):
@@ -473,7 +473,7 @@ def test_query_source_with_module_in_search_path(sentry_init, capture_events):
473473
query_first_model_from_session,
474474
)
475475

476-
with sentry_sdk.start_span(name="test_transaction", sampled=True):
476+
with sentry_sdk.start_span(name="test_transaction"):
477477
Base = declarative_base() # noqa: N806
478478

479479
class Person(Base):
@@ -531,7 +531,7 @@ def test_no_query_source_if_duration_too_short(sentry_init, capture_events):
531531
)
532532
events = capture_events()
533533

534-
with sentry_sdk.start_span(name="test_transaction", sampled=True):
534+
with sentry_sdk.start_span(name="test_transaction"):
535535
Base = declarative_base() # noqa: N806
536536

537537
class Person(Base):
@@ -599,7 +599,7 @@ def test_query_source_if_duration_over_threshold(sentry_init, capture_events):
599599
)
600600
events = capture_events()
601601

602-
with sentry_sdk.start_span(name="test_transaction", sampled=True):
602+
with sentry_sdk.start_span(name="test_transaction"):
603603
Base = declarative_base() # noqa: N806
604604

605605
class Person(Base):

tests/tracing/test_sampling.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ def test_sampling_decided_only_for_root_spans(sentry_init):
2323
assert root_span2.sampled is not None
2424

2525

26-
@pytest.mark.parametrize("sampled", [True, False])
27-
def test_nested_span_sampling_override(sentry_init, sampled):
28-
sentry_init(traces_sample_rate=1.0)
29-
30-
with start_span(name="outer", sampled=sampled) as outer_span:
31-
assert outer_span.sampled is sampled
32-
with start_span(name="inner", sampled=(not sampled)) as inner_span:
33-
# won't work because the child span inherits the sampling decision
34-
# from the parent
35-
assert inner_span.sampled is sampled
36-
assert outer_span.sampled is sampled
37-
38-
3926
def test_no_double_sampling(sentry_init, capture_events):
4027
# Transactions should not be subject to the global/error sample rate.
4128
# Only the traces_sample_rate should apply.
@@ -146,19 +133,6 @@ def test_ignores_inherited_sample_decision_when_traces_sampler_defined(
146133
assert span.sampled is not parent_sampling_decision
147134

148135

149-
@pytest.mark.parametrize("explicit_decision", [True, False])
150-
def test_traces_sampler_doesnt_overwrite_explicitly_passed_sampling_decision(
151-
sentry_init, explicit_decision
152-
):
153-
# make traces_sampler pick the opposite of the explicit decision, to prove
154-
# that the explicit decision takes precedence
155-
traces_sampler = mock.Mock(return_value=not explicit_decision)
156-
sentry_init(traces_sampler=traces_sampler)
157-
158-
with start_span(name="dogpark", sampled=explicit_decision) as span:
159-
assert span.sampled is explicit_decision
160-
161-
162136
@pytest.mark.parametrize("parent_sampling_decision", [True, False])
163137
def test_inherits_parent_sampling_decision_when_traces_sampler_undefined(
164138
sentry_init, parent_sampling_decision

0 commit comments

Comments
 (0)