diff --git a/sentry_sdk/integrations/grpc/aio/server.py b/sentry_sdk/integrations/grpc/aio/server.py index 381c63103e..7a9eca7671 100644 --- a/sentry_sdk/integrations/grpc/aio/server.py +++ b/sentry_sdk/integrations/grpc/aio/server.py @@ -44,7 +44,7 @@ async def wrapped(request, context): return await handler(request, context) # What if the headers are empty? - transaction = Transaction.continue_from_headers( + transaction = sentry_sdk.continue_trace( dict(context.invocation_metadata()), op=OP.GRPC_SERVER, name=name, diff --git a/sentry_sdk/integrations/grpc/server.py b/sentry_sdk/integrations/grpc/server.py index 0d2792d1b7..cce7e99d27 100644 --- a/sentry_sdk/integrations/grpc/server.py +++ b/sentry_sdk/integrations/grpc/server.py @@ -38,7 +38,7 @@ def behavior(request, context): if name: metadata = dict(context.invocation_metadata()) - transaction = Transaction.continue_from_headers( + transaction = sentry_sdk.continue_trace( metadata, op=OP.GRPC_SERVER, name=name, diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index f0d24ddb39..5a9a053418 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -478,6 +478,8 @@ def continue_from_environ( ): # type: (...) -> Transaction """ + DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`. + Create a Transaction with the given params, then add in data pulled from the ``sentry-trace`` and ``baggage`` headers from the environ (if any) before returning the Transaction. @@ -489,11 +491,6 @@ def continue_from_environ( :param environ: The ASGI/WSGI environ to pull information from. """ - if cls is Span: - logger.warning( - "Deprecated: use Transaction.continue_from_environ " - "instead of Span.continue_from_environ." - ) return Transaction.continue_from_headers(EnvironHeaders(environ), **kwargs) @classmethod @@ -506,6 +503,8 @@ def continue_from_headers( ): # type: (...) -> Transaction """ + DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`. + Create a transaction with the given params (including any data pulled from the ``sentry-trace`` and ``baggage`` headers). @@ -513,12 +512,7 @@ def continue_from_headers( :param _sample_rand: If provided, we override the sample_rand value from the incoming headers with this value. (internal use only) """ - # TODO move this to the Transaction class - if cls is Span: - logger.warning( - "Deprecated: use Transaction.continue_from_headers " - "instead of Span.continue_from_headers." - ) + logger.warning("Deprecated: use sentry_sdk.continue_trace instead.") # TODO-neel move away from this kwargs stuff, it's confusing and opaque # make more explicit @@ -572,16 +566,11 @@ def from_traceparent( ): # type: (...) -> Optional[Transaction] """ - DEPRECATED: Use :py:meth:`sentry_sdk.tracing.Span.continue_from_headers`. + DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`. Create a ``Transaction`` with the given params, then add in data pulled from the given ``sentry-trace`` header value before returning the ``Transaction``. """ - logger.warning( - "Deprecated: Use Transaction.continue_from_headers(headers, **kwargs) " - "instead of from_traceparent(traceparent, **kwargs)" - ) - if not traceparent: return None diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index acb115c6d4..588c3b34f4 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -8,9 +8,8 @@ import pytest -from sentry_sdk import capture_message, start_transaction +from sentry_sdk import capture_message, start_transaction, continue_trace from sentry_sdk.consts import MATCH_ALL, SPANDATA -from sentry_sdk.tracing import Transaction from sentry_sdk.integrations.stdlib import StdlibIntegration from tests.conftest import ApproxDict, create_mock_http_server @@ -187,6 +186,7 @@ def test_outgoing_trace_headers(sentry_init, monkeypatch): sentry_init(traces_sample_rate=1.0) headers = { + "sentry-trace": "771a43a4192642f0b136d5159a501700-1234567890abcdef-1", "baggage": ( "other-vendor-value-1=foo;bar;baz, sentry-trace_id=771a43a4192642f0b136d5159a501700, " "sentry-public_key=49d0f7386ad645858ae85020e393bef3, sentry-sample_rate=0.01337, " @@ -194,7 +194,7 @@ def test_outgoing_trace_headers(sentry_init, monkeypatch): ), } - transaction = Transaction.continue_from_headers(headers) + transaction = continue_trace(headers) with start_transaction( transaction=transaction, @@ -239,7 +239,7 @@ def test_outgoing_trace_headers_head_sdk(sentry_init, monkeypatch): sentry_init(traces_sample_rate=0.5, release="foo") with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=250000): - transaction = Transaction.continue_from_headers({}) + transaction = continue_trace({}) with start_transaction(transaction=transaction, name="Head SDK tx") as transaction: HTTPSConnection("www.squirrelchasers.com").request("GET", "/top-chasers") @@ -351,7 +351,7 @@ def test_option_trace_propagation_targets( ) } - transaction = Transaction.continue_from_headers(headers) + transaction = continue_trace(headers) with start_transaction( transaction=transaction, diff --git a/tests/tracing/test_integration_tests.py b/tests/tracing/test_integration_tests.py index e0ff123b0d..0bd5548980 100644 --- a/tests/tracing/test_integration_tests.py +++ b/tests/tracing/test_integration_tests.py @@ -11,10 +11,10 @@ capture_message, start_span, start_transaction, + continue_trace, ) from sentry_sdk.consts import SPANSTATUS from sentry_sdk.transport import Transport -from sentry_sdk.tracing import Transaction @pytest.mark.parametrize("sample_rate", [0.0, 1.0]) @@ -57,9 +57,7 @@ def test_basic(sentry_init, capture_events, sample_rate): @pytest.mark.parametrize("parent_sampled", [True, False, None]) @pytest.mark.parametrize("sample_rate", [0.0, 1.0]) -def test_continue_from_headers( - sentry_init, capture_envelopes, parent_sampled, sample_rate -): +def test_continue_trace(sentry_init, capture_envelopes, parent_sampled, sample_rate): """ Ensure data is actually passed along via headers, and that they are read correctly. @@ -79,11 +77,12 @@ def test_continue_from_headers( "sentry-trace_id=771a43a4192642f0b136d5159a501700, " "sentry-public_key=49d0f7386ad645858ae85020e393bef3, " "sentry-sample_rate=0.01337, sentry-user_id=Amelie, " + "sentry-sample_rand=0.250000, " "other-vendor-value-2=foo;bar;" ) # child transaction, to prove that we can read 'sentry-trace' header data correctly - child_transaction = Transaction.continue_from_headers(headers, name="WRONG") + child_transaction = continue_trace(headers, name="WRONG") assert child_transaction is not None assert child_transaction.parent_sampled == parent_sampled assert child_transaction.trace_id == old_span.trace_id @@ -98,6 +97,7 @@ def test_continue_from_headers( "public_key": "49d0f7386ad645858ae85020e393bef3", "trace_id": "771a43a4192642f0b136d5159a501700", "user_id": "Amelie", + "sample_rand": "0.250000", "sample_rate": "0.01337", } @@ -143,6 +143,7 @@ def test_continue_from_headers( "public_key": "49d0f7386ad645858ae85020e393bef3", "trace_id": "771a43a4192642f0b136d5159a501700", "user_id": "Amelie", + "sample_rand": "0.250000", "sample_rate": expected_sample_rate, } @@ -172,14 +173,10 @@ def test_dynamic_sampling_head_sdk_creates_dsc( # make sure transaction is sampled for both cases with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=250000): - transaction = Transaction.continue_from_headers({}, name="Head SDK tx") + transaction = continue_trace({}, name="Head SDK tx") - # will create empty mutable baggage baggage = transaction._baggage - assert baggage - assert baggage.mutable - assert baggage.sentry_items == {} - assert baggage.third_party_items == "" + assert baggage is None with start_transaction(transaction): with start_span(op="foo", name="foodesc"): @@ -291,7 +288,7 @@ def capture_event(self, event): def test_trace_propagation_meta_head_sdk(sentry_init): sentry_init(traces_sample_rate=1.0, release="foo") - transaction = Transaction.continue_from_headers({}, name="Head SDK tx") + transaction = continue_trace({}, name="Head SDK tx") meta = None span = None diff --git a/tests/tracing/test_sampling.py b/tests/tracing/test_sampling.py index 63da5a1399..c0f307ecf7 100644 --- a/tests/tracing/test_sampling.py +++ b/tests/tracing/test_sampling.py @@ -5,8 +5,7 @@ import pytest import sentry_sdk -from sentry_sdk import start_span, start_transaction, capture_exception -from sentry_sdk.tracing import Transaction +from sentry_sdk import start_span, start_transaction, capture_exception, continue_trace from sentry_sdk.tracing_utils import Baggage from sentry_sdk.utils import logger @@ -196,8 +195,9 @@ def test_passes_parent_sampling_decision_in_sampling_context( ) ) - transaction = Transaction.continue_from_headers( - headers={"sentry-trace": sentry_trace_header}, name="dogpark" + transaction = sentry_sdk.continue_trace( + {"sentry-trace": sentry_trace_header}, + name="dogpark", ) def mock_set_initial_sampling_decision(_, sampling_context):