Skip to content

Commit 11ed72e

Browse files
committed
tests
1 parent 94c5aac commit 11ed72e

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

tests/integrations/stdlib/test_httplib.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,13 @@ def test_outgoing_trace_headers(sentry_init, monkeypatch):
140140

141141
sentry_init(traces_sample_rate=1.0)
142142

143-
headers = {}
144-
headers["baggage"] = (
145-
"other-vendor-value-1=foo;bar;baz, sentry-trace_id=771a43a4192642f0b136d5159a501700, "
146-
"sentry-public_key=49d0f7386ad645858ae85020e393bef3, sentry-sample_rate=0.01337, "
147-
"sentry-user_id=Am%C3%A9lie, other-vendor-value-2=foo;bar;"
148-
)
143+
headers = {
144+
"baggage": (
145+
"other-vendor-value-1=foo;bar;baz, sentry-trace_id=771a43a4192642f0b136d5159a501700, "
146+
"sentry-public_key=49d0f7386ad645858ae85020e393bef3, sentry-sample_rate=0.01337, "
147+
"sentry-user_id=Am%C3%A9lie, other-vendor-value-2=foo;bar;"
148+
),
149+
}
149150

150151
transaction = Transaction.continue_from_headers(headers)
151152

@@ -175,7 +176,7 @@ def test_outgoing_trace_headers(sentry_init, monkeypatch):
175176
expected_outgoing_baggage = (
176177
"sentry-trace_id=771a43a4192642f0b136d5159a501700,"
177178
"sentry-public_key=49d0f7386ad645858ae85020e393bef3,"
178-
"sentry-sample_rate=0.01337,"
179+
"sentry-sample_rate=1.0,"
179180
"sentry-user_id=Am%C3%A9lie"
180181
)
181182

tests/test_dsc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_dsc_continuation_of_trace(sentry_init, capture_envelopes):
118118

119119
assert "sample_rate" in envelope_trace_header
120120
assert type(envelope_trace_header["sample_rate"]) == str
121-
assert envelope_trace_header["sample_rate"] == "0.01337"
121+
assert envelope_trace_header["sample_rate"] == "1.0"
122122

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

139139

140-
def test_dsc_continuation_of_trace_sample_rate_changed(sentry_init, capture_envelopes):
140+
def test_dsc_continuation_of_trace_sample_rate_changed_in_traces_sampler(
141+
sentry_init, capture_envelopes
142+
):
141143
"""
142144
Another service calls our service and passes tracing information to us.
143145
Our service is continuing the trace, but modifies the sample rate.

tests/tracing/test_integration_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_continue_from_headers(sentry_init, capture_envelopes, sampled, sample_r
132132
"public_key": "49d0f7386ad645858ae85020e393bef3",
133133
"trace_id": "771a43a4192642f0b136d5159a501700",
134134
"user_id": "Amelie",
135-
"sample_rate": "0.01337",
135+
"sample_rate": str(sample_rate),
136136
}
137137

138138
assert message_payload["message"] == "hello"

tests/tracing/test_sampling.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,16 @@ def test_passes_parent_sampling_decision_in_sampling_context(
198198
transaction = Transaction.continue_from_headers(
199199
headers={"sentry-trace": sentry_trace_header}, name="dogpark"
200200
)
201-
spy = mock.Mock(wraps=transaction)
202-
start_transaction(transaction=spy)
203-
204-
# there's only one call (so index at 0) and kwargs are always last in a call
205-
# tuple (so index at -1)
206-
sampling_context = spy._set_initial_sampling_decision.mock_calls[0][-1][
207-
"sampling_context"
208-
]
209-
assert "parent_sampled" in sampling_context
210-
# because we passed in a spy, attribute access requires unwrapping
211-
assert sampling_context["parent_sampled"]._mock_wraps is parent_sampling_decision
201+
202+
def mock_set_initial_sampling_decision(_, sampling_context):
203+
assert "parent_sampled" in sampling_context
204+
assert sampling_context["parent_sampled"] is parent_sampling_decision
205+
206+
with mock.patch(
207+
"sentry_sdk.tracing.Transaction._set_initial_sampling_decision",
208+
mock_set_initial_sampling_decision,
209+
):
210+
start_transaction(transaction=transaction)
212211

213212

214213
def test_passes_custom_sampling_context_from_start_transaction_to_traces_sampler(

0 commit comments

Comments
 (0)