Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Feb 6, 2025
1 parent 94c5aac commit 11ed72e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
15 changes: 8 additions & 7 deletions tests/integrations/stdlib/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ def test_outgoing_trace_headers(sentry_init, monkeypatch):

sentry_init(traces_sample_rate=1.0)

headers = {}
headers["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, other-vendor-value-2=foo;bar;"
)
headers = {
"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, other-vendor-value-2=foo;bar;"
),
}

transaction = Transaction.continue_from_headers(headers)

Expand Down Expand Up @@ -175,7 +176,7 @@ def test_outgoing_trace_headers(sentry_init, monkeypatch):
expected_outgoing_baggage = (
"sentry-trace_id=771a43a4192642f0b136d5159a501700,"
"sentry-public_key=49d0f7386ad645858ae85020e393bef3,"
"sentry-sample_rate=0.01337,"
"sentry-sample_rate=1.0,"
"sentry-user_id=Am%C3%A9lie"
)

Expand Down
6 changes: 4 additions & 2 deletions tests/test_dsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_dsc_continuation_of_trace(sentry_init, capture_envelopes):

assert "sample_rate" in envelope_trace_header
assert type(envelope_trace_header["sample_rate"]) == str
assert envelope_trace_header["sample_rate"] == "0.01337"
assert envelope_trace_header["sample_rate"] == "1.0"

assert "sampled" in envelope_trace_header
assert type(envelope_trace_header["sampled"]) == str
Expand All @@ -137,7 +137,9 @@ def test_dsc_continuation_of_trace(sentry_init, capture_envelopes):
assert envelope_trace_header["transaction"] == "bar"


def test_dsc_continuation_of_trace_sample_rate_changed(sentry_init, capture_envelopes):
def test_dsc_continuation_of_trace_sample_rate_changed_in_traces_sampler(
sentry_init, capture_envelopes
):
"""
Another service calls our service and passes tracing information to us.
Our service is continuing the trace, but modifies the sample rate.
Expand Down
2 changes: 1 addition & 1 deletion tests/tracing/test_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_continue_from_headers(sentry_init, capture_envelopes, sampled, sample_r
"public_key": "49d0f7386ad645858ae85020e393bef3",
"trace_id": "771a43a4192642f0b136d5159a501700",
"user_id": "Amelie",
"sample_rate": "0.01337",
"sample_rate": str(sample_rate),
}

assert message_payload["message"] == "hello"
Expand Down
21 changes: 10 additions & 11 deletions tests/tracing/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,16 @@ def test_passes_parent_sampling_decision_in_sampling_context(
transaction = Transaction.continue_from_headers(
headers={"sentry-trace": sentry_trace_header}, name="dogpark"
)
spy = mock.Mock(wraps=transaction)
start_transaction(transaction=spy)

# there's only one call (so index at 0) and kwargs are always last in a call
# tuple (so index at -1)
sampling_context = spy._set_initial_sampling_decision.mock_calls[0][-1][
"sampling_context"
]
assert "parent_sampled" in sampling_context
# because we passed in a spy, attribute access requires unwrapping
assert sampling_context["parent_sampled"]._mock_wraps is parent_sampling_decision

def mock_set_initial_sampling_decision(_, sampling_context):
assert "parent_sampled" in sampling_context
assert sampling_context["parent_sampled"] is parent_sampling_decision

with mock.patch(
"sentry_sdk.tracing.Transaction._set_initial_sampling_decision",
mock_set_initial_sampling_decision,
):
start_transaction(transaction=transaction)


def test_passes_custom_sampling_context_from_start_transaction_to_traces_sampler(
Expand Down

0 comments on commit 11ed72e

Please sign in to comment.