Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/grpc/aio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/grpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 6 additions & 17 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -506,19 +503,16 @@ 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).

:param headers: The dictionary with the HTTP headers to pull information from.
: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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions tests/integrations/stdlib/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -187,14 +186,15 @@ 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, "
"sentry-user_id=Am%C3%A9lie, sentry-sample_rand=0.132521102938283, other-vendor-value-2=foo;bar;"
),
}

transaction = Transaction.continue_from_headers(headers)
transaction = continue_trace(headers)

with start_transaction(
transaction=transaction,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 9 additions & 12 deletions tests/tracing/test_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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",
}

Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this differs from the old implementation in that baggage is now None for this case instead of empty and mutable, but the head SDK population semantic is the same, so this is fine.

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"):
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions tests/tracing/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down