Skip to content

Commit 3682891

Browse files
committed
Deprecate continue_from_headers
1 parent c3d389e commit 3682891

File tree

6 files changed

+23
-39
lines changed

6 files changed

+23
-39
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: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,7 @@ def continue_from_environ(
489489
490490
:param environ: The ASGI/WSGI environ to pull information from.
491491
"""
492-
if cls is Span:
493-
logger.warning(
494-
"Deprecated: use Transaction.continue_from_environ "
495-
"instead of Span.continue_from_environ."
496-
)
492+
logger.warning("Deprecated: use sentry_sdk.continue_trace instead.")
497493
return Transaction.continue_from_headers(EnvironHeaders(environ), **kwargs)
498494

499495
@classmethod
@@ -513,12 +509,7 @@ def continue_from_headers(
513509
:param _sample_rand: If provided, we override the sample_rand value from the
514510
incoming headers with this value. (internal use only)
515511
"""
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-
)
512+
logger.warning("Deprecated: use sentry_sdk.continue_trace instead.")
522513

523514
# TODO-neel move away from this kwargs stuff, it's confusing and opaque
524515
# make more explicit
@@ -572,15 +563,12 @@ def from_traceparent(
572563
):
573564
# type: (...) -> Optional[Transaction]
574565
"""
575-
DEPRECATED: Use :py:meth:`sentry_sdk.tracing.Span.continue_from_headers`.
566+
DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`.
576567
577568
Create a ``Transaction`` with the given params, then add in data pulled from
578569
the given ``sentry-trace`` header value before returning the ``Transaction``.
579570
"""
580-
logger.warning(
581-
"Deprecated: Use Transaction.continue_from_headers(headers, **kwargs) "
582-
"instead of from_traceparent(traceparent, **kwargs)"
583-
)
571+
logger.warning("Deprecated: use sentry_sdk.continue_trace instead.")
584572

585573
if not traceparent:
586574
return None

tests/integrations/stdlib/test_httplib.py

Lines changed: 4 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
@@ -194,7 +193,7 @@ def test_outgoing_trace_headers(sentry_init, monkeypatch):
194193
),
195194
}
196195

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

199198
with start_transaction(
200199
transaction=transaction,
@@ -239,7 +238,7 @@ def test_outgoing_trace_headers_head_sdk(sentry_init, monkeypatch):
239238

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

244243
with start_transaction(transaction=transaction, name="Head SDK tx") as transaction:
245244
HTTPSConnection("www.squirrelchasers.com").request("GET", "/top-chasers")
@@ -351,7 +350,7 @@ def test_option_trace_propagation_targets(
351350
)
352351
}
353352

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

356355
with start_transaction(
357356
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)