-
Notifications
You must be signed in to change notification settings - Fork 535
Update sample rate in DSC #4018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
75f64c6
update sample rate in dsc
sentrivana feb2c13
test
sentrivana 1778130
Merge branch 'master' into ivana/update-sample-rate
sentrivana d824113
guard against none
sentrivana 734323e
Merge branch 'master' into ivana/update-sample-rate
sentrivana 94c5aac
meh
sentrivana 11ed72e
tests
sentrivana 19082e8
cleanup
sentrivana f259ede
fix test
sentrivana 2404575
Merge branch 'master' into ivana/update-sample-rate
sentrivana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ | |
This is not tested in this file. | ||
""" | ||
|
||
import random | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
import sentry_sdk | ||
|
@@ -115,7 +118,85 @@ 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 | ||
assert envelope_trace_header["sampled"] == "true" | ||
|
||
assert "release" in envelope_trace_header | ||
assert type(envelope_trace_header["release"]) == str | ||
assert envelope_trace_header["release"] == "[email protected]" | ||
|
||
assert "environment" in envelope_trace_header | ||
assert type(envelope_trace_header["environment"]) == str | ||
assert envelope_trace_header["environment"] == "bird" | ||
|
||
assert "transaction" in envelope_trace_header | ||
assert type(envelope_trace_header["transaction"]) == str | ||
assert envelope_trace_header["transaction"] == "bar" | ||
|
||
|
||
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. | ||
The DSC propagated further should contain the updated sample rate. | ||
""" | ||
|
||
def my_traces_sampler(sampling_context): | ||
return 0.25 | ||
|
||
sentry_init( | ||
dsn="https://[email protected]/12312012", | ||
release="[email protected]", | ||
environment="canary", | ||
traces_sampler=my_traces_sampler, | ||
) | ||
envelopes = capture_envelopes() | ||
|
||
# This is what the upstream service sends us | ||
sentry_trace = "771a43a4192642f0b136d5159a501700-1234567890abcdef-1" | ||
baggage = ( | ||
"other-vendor-value-1=foo;bar;baz, " | ||
"sentry-trace_id=771a43a4192642f0b136d5159a501700, " | ||
"sentry-public_key=frontendpublickey, " | ||
"sentry-sample_rate=1.0, " | ||
"sentry-sampled=true, " | ||
"[email protected], " | ||
"sentry-environment=bird, " | ||
"sentry-transaction=bar, " | ||
"other-vendor-value-2=foo;bar;" | ||
) | ||
incoming_http_headers = { | ||
"HTTP_SENTRY_TRACE": sentry_trace, | ||
"HTTP_BAGGAGE": baggage, | ||
} | ||
|
||
# We continue the incoming trace and start a new transaction | ||
with mock.patch.object(random, "random", return_value=0.2): | ||
transaction = sentry_sdk.continue_trace(incoming_http_headers) | ||
with sentry_sdk.start_transaction(transaction, name="foo"): | ||
pass | ||
|
||
assert len(envelopes) == 1 | ||
|
||
transaction_envelope = envelopes[0] | ||
envelope_trace_header = transaction_envelope.headers["trace"] | ||
|
||
assert "trace_id" in envelope_trace_header | ||
assert type(envelope_trace_header["trace_id"]) == str | ||
assert envelope_trace_header["trace_id"] == "771a43a4192642f0b136d5159a501700" | ||
|
||
assert "public_key" in envelope_trace_header | ||
assert type(envelope_trace_header["public_key"]) == str | ||
assert envelope_trace_header["public_key"] == "frontendpublickey" | ||
|
||
assert "sample_rate" in envelope_trace_header | ||
assert type(envelope_trace_header["sample_rate"]) == str | ||
assert envelope_trace_header["sample_rate"] == "0.25" | ||
|
||
assert "sampled" in envelope_trace_header | ||
assert type(envelope_trace_header["sampled"]) == str | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, the baggage on the transaction is independent from the propagation context? In any case, I'm changing both here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's ok.
transaction._baggage
is for the current transaction and on the scope it is for future transactions. So looks correct.