Skip to content

Commit b528f32

Browse files
authored
Deprecate continue_from_headers (#5160)
### Description `continue_trace` should be the only recommended way of continuing upstream traces now.
1 parent 4e44da6 commit b528f32

File tree

6 files changed

+26
-40
lines changed

6 files changed

+26
-40
lines changed

sentry_sdk/integrations/grpc/aio/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def wrapped(request, context):
4444
return await handler(request, context)
4545

4646
# What if the headers are empty?
47-
transaction = Transaction.continue_from_headers(
47+
transaction = sentry_sdk.continue_trace(
4848
dict(context.invocation_metadata()),
4949
op=OP.GRPC_SERVER,
5050
name=name,

sentry_sdk/integrations/grpc/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def behavior(request, context):
3838
if name:
3939
metadata = dict(context.invocation_metadata())
4040

41-
transaction = Transaction.continue_from_headers(
41+
transaction = sentry_sdk.continue_trace(
4242
metadata,
4343
op=OP.GRPC_SERVER,
4444
name=name,

sentry_sdk/tracing.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ def continue_from_environ(
478478
):
479479
# type: (...) -> Transaction
480480
"""
481+
DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`.
482+
481483
Create a Transaction with the given params, then add in data pulled from
482484
the ``sentry-trace`` and ``baggage`` headers from the environ (if any)
483485
before returning the Transaction.
@@ -489,11 +491,6 @@ def continue_from_environ(
489491
490492
:param environ: The ASGI/WSGI environ to pull information from.
491493
"""
492-
if cls is Span:
493-
logger.warning(
494-
"Deprecated: use Transaction.continue_from_environ "
495-
"instead of Span.continue_from_environ."
496-
)
497494
return Transaction.continue_from_headers(EnvironHeaders(environ), **kwargs)
498495

499496
@classmethod
@@ -506,19 +503,16 @@ def continue_from_headers(
506503
):
507504
# type: (...) -> Transaction
508505
"""
506+
DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`.
507+
509508
Create a transaction with the given params (including any data pulled from
510509
the ``sentry-trace`` and ``baggage`` headers).
511510
512511
:param headers: The dictionary with the HTTP headers to pull information from.
513512
:param _sample_rand: If provided, we override the sample_rand value from the
514513
incoming headers with this value. (internal use only)
515514
"""
516-
# TODO move this to the Transaction class
517-
if cls is Span:
518-
logger.warning(
519-
"Deprecated: use Transaction.continue_from_headers "
520-
"instead of Span.continue_from_headers."
521-
)
515+
logger.warning("Deprecated: use sentry_sdk.continue_trace instead.")
522516

523517
# TODO-neel move away from this kwargs stuff, it's confusing and opaque
524518
# make more explicit
@@ -572,16 +566,11 @@ def from_traceparent(
572566
):
573567
# type: (...) -> Optional[Transaction]
574568
"""
575-
DEPRECATED: Use :py:meth:`sentry_sdk.tracing.Span.continue_from_headers`.
569+
DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`.
576570
577571
Create a ``Transaction`` with the given params, then add in data pulled from
578572
the given ``sentry-trace`` header value before returning the ``Transaction``.
579573
"""
580-
logger.warning(
581-
"Deprecated: Use Transaction.continue_from_headers(headers, **kwargs) "
582-
"instead of from_traceparent(traceparent, **kwargs)"
583-
)
584-
585574
if not traceparent:
586575
return None
587576

tests/integrations/stdlib/test_httplib.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
import pytest
1010

11-
from sentry_sdk import capture_message, start_transaction
11+
from sentry_sdk import capture_message, start_transaction, continue_trace
1212
from sentry_sdk.consts import MATCH_ALL, SPANDATA
13-
from sentry_sdk.tracing import Transaction
1413
from sentry_sdk.integrations.stdlib import StdlibIntegration
1514

1615
from tests.conftest import ApproxDict, create_mock_http_server
@@ -187,14 +186,15 @@ def test_outgoing_trace_headers(sentry_init, monkeypatch):
187186
sentry_init(traces_sample_rate=1.0)
188187

189188
headers = {
189+
"sentry-trace": "771a43a4192642f0b136d5159a501700-1234567890abcdef-1",
190190
"baggage": (
191191
"other-vendor-value-1=foo;bar;baz, sentry-trace_id=771a43a4192642f0b136d5159a501700, "
192192
"sentry-public_key=49d0f7386ad645858ae85020e393bef3, sentry-sample_rate=0.01337, "
193193
"sentry-user_id=Am%C3%A9lie, sentry-sample_rand=0.132521102938283, other-vendor-value-2=foo;bar;"
194194
),
195195
}
196196

197-
transaction = Transaction.continue_from_headers(headers)
197+
transaction = continue_trace(headers)
198198

199199
with start_transaction(
200200
transaction=transaction,
@@ -239,7 +239,7 @@ def test_outgoing_trace_headers_head_sdk(sentry_init, monkeypatch):
239239

240240
sentry_init(traces_sample_rate=0.5, release="foo")
241241
with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=250000):
242-
transaction = Transaction.continue_from_headers({})
242+
transaction = continue_trace({})
243243

244244
with start_transaction(transaction=transaction, name="Head SDK tx") as transaction:
245245
HTTPSConnection("www.squirrelchasers.com").request("GET", "/top-chasers")
@@ -351,7 +351,7 @@ def test_option_trace_propagation_targets(
351351
)
352352
}
353353

354-
transaction = Transaction.continue_from_headers(headers)
354+
transaction = continue_trace(headers)
355355

356356
with start_transaction(
357357
transaction=transaction,

tests/tracing/test_integration_tests.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
capture_message,
1212
start_span,
1313
start_transaction,
14+
continue_trace,
1415
)
1516
from sentry_sdk.consts import SPANSTATUS
1617
from sentry_sdk.transport import Transport
17-
from sentry_sdk.tracing import Transaction
1818

1919

2020
@pytest.mark.parametrize("sample_rate", [0.0, 1.0])
@@ -57,9 +57,7 @@ def test_basic(sentry_init, capture_events, sample_rate):
5757

5858
@pytest.mark.parametrize("parent_sampled", [True, False, None])
5959
@pytest.mark.parametrize("sample_rate", [0.0, 1.0])
60-
def test_continue_from_headers(
61-
sentry_init, capture_envelopes, parent_sampled, sample_rate
62-
):
60+
def test_continue_trace(sentry_init, capture_envelopes, parent_sampled, sample_rate):
6361
"""
6462
Ensure data is actually passed along via headers, and that they are read
6563
correctly.
@@ -79,11 +77,12 @@ def test_continue_from_headers(
7977
"sentry-trace_id=771a43a4192642f0b136d5159a501700, "
8078
"sentry-public_key=49d0f7386ad645858ae85020e393bef3, "
8179
"sentry-sample_rate=0.01337, sentry-user_id=Amelie, "
80+
"sentry-sample_rand=0.250000, "
8281
"other-vendor-value-2=foo;bar;"
8382
)
8483

8584
# child transaction, to prove that we can read 'sentry-trace' header data correctly
86-
child_transaction = Transaction.continue_from_headers(headers, name="WRONG")
85+
child_transaction = continue_trace(headers, name="WRONG")
8786
assert child_transaction is not None
8887
assert child_transaction.parent_sampled == parent_sampled
8988
assert child_transaction.trace_id == old_span.trace_id
@@ -98,6 +97,7 @@ def test_continue_from_headers(
9897
"public_key": "49d0f7386ad645858ae85020e393bef3",
9998
"trace_id": "771a43a4192642f0b136d5159a501700",
10099
"user_id": "Amelie",
100+
"sample_rand": "0.250000",
101101
"sample_rate": "0.01337",
102102
}
103103

@@ -143,6 +143,7 @@ def test_continue_from_headers(
143143
"public_key": "49d0f7386ad645858ae85020e393bef3",
144144
"trace_id": "771a43a4192642f0b136d5159a501700",
145145
"user_id": "Amelie",
146+
"sample_rand": "0.250000",
146147
"sample_rate": expected_sample_rate,
147148
}
148149

@@ -172,14 +173,10 @@ def test_dynamic_sampling_head_sdk_creates_dsc(
172173

173174
# make sure transaction is sampled for both cases
174175
with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=250000):
175-
transaction = Transaction.continue_from_headers({}, name="Head SDK tx")
176+
transaction = continue_trace({}, name="Head SDK tx")
176177

177-
# will create empty mutable baggage
178178
baggage = transaction._baggage
179-
assert baggage
180-
assert baggage.mutable
181-
assert baggage.sentry_items == {}
182-
assert baggage.third_party_items == ""
179+
assert baggage is None
183180

184181
with start_transaction(transaction):
185182
with start_span(op="foo", name="foodesc"):
@@ -291,7 +288,7 @@ def capture_event(self, event):
291288
def test_trace_propagation_meta_head_sdk(sentry_init):
292289
sentry_init(traces_sample_rate=1.0, release="foo")
293290

294-
transaction = Transaction.continue_from_headers({}, name="Head SDK tx")
291+
transaction = continue_trace({}, name="Head SDK tx")
295292
meta = None
296293
span = None
297294

tests/tracing/test_sampling.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import pytest
66

77
import sentry_sdk
8-
from sentry_sdk import start_span, start_transaction, capture_exception
9-
from sentry_sdk.tracing import Transaction
8+
from sentry_sdk import start_span, start_transaction, capture_exception, continue_trace
109
from sentry_sdk.tracing_utils import Baggage
1110
from sentry_sdk.utils import logger
1211

@@ -196,8 +195,9 @@ def test_passes_parent_sampling_decision_in_sampling_context(
196195
)
197196
)
198197

199-
transaction = Transaction.continue_from_headers(
200-
headers={"sentry-trace": sentry_trace_header}, name="dogpark"
198+
transaction = sentry_sdk.continue_trace(
199+
{"sentry-trace": sentry_trace_header},
200+
name="dogpark",
201201
)
202202

203203
def mock_set_initial_sampling_decision(_, sampling_context):

0 commit comments

Comments
 (0)