-
Notifications
You must be signed in to change notification settings - Fork 571
feat: Implement strict_trace_continuation #5178
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
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -13,19 +13,7 @@ | |
| import pytest | ||
|
|
||
| import sentry_sdk | ||
| from sentry_sdk.transport import Transport | ||
| from sentry_sdk.envelope import Envelope | ||
|
|
||
|
|
||
| class TransportWithOptions(Transport): | ||
| """conftest.TestTransport does not pass in the options so we need this here""" | ||
|
|
||
| def __init__(self, options=None): | ||
| Transport.__init__(self, options) | ||
|
|
||
| def capture_envelope(self, _: Envelope) -> None: | ||
| """No-op capture_envelope for tests""" | ||
| pass | ||
| from tests.conftest import TestTransportWithOptions | ||
|
|
||
|
|
||
| def test_dsc_head_of_trace(sentry_init, capture_envelopes): | ||
|
|
@@ -38,7 +26,7 @@ def test_dsc_head_of_trace(sentry_init, capture_envelopes): | |
| release="[email protected]", | ||
| environment="canary", | ||
| traces_sample_rate=1.0, | ||
| transport=TransportWithOptions, | ||
| transport=TestTransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
|
|
@@ -94,7 +82,7 @@ def test_dsc_head_of_trace_uses_custom_org_id(sentry_init, capture_envelopes): | |
| release="[email protected]", | ||
| environment="canary", | ||
| traces_sample_rate=1.0, | ||
| transport=TransportWithOptions, | ||
| transport=TestTransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
|
|
@@ -122,7 +110,7 @@ def test_dsc_continuation_of_trace(sentry_init, capture_envelopes): | |
| release="[email protected]", | ||
| environment="canary", | ||
| traces_sample_rate=1.0, | ||
| transport=TransportWithOptions, | ||
| transport=TestTransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
|
|
@@ -200,7 +188,7 @@ def my_traces_sampler(sampling_context): | |
| release="[email protected]", | ||
| environment="canary", | ||
| traces_sampler=my_traces_sampler, | ||
| transport=TransportWithOptions, | ||
| transport=TestTransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
|
|
@@ -270,7 +258,7 @@ def test_dsc_issue(sentry_init, capture_envelopes): | |
| dsn="https://[email protected]/12312012", | ||
| release="[email protected]", | ||
| environment="canary", | ||
| transport=TransportWithOptions, | ||
| transport=TestTransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
|
|
@@ -322,7 +310,7 @@ def test_dsc_issue_with_tracing(sentry_init, capture_envelopes): | |
| release="[email protected]", | ||
| environment="canary", | ||
| traces_sample_rate=1.0, | ||
| transport=TransportWithOptions, | ||
| transport=TestTransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
|
|
@@ -394,7 +382,7 @@ def test_dsc_issue_twp(sentry_init, capture_envelopes, traces_sample_rate): | |
| release="[email protected]", | ||
| environment="canary", | ||
| traces_sample_rate=traces_sample_rate, | ||
| transport=TransportWithOptions, | ||
| transport=TestTransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,8 +1,13 @@ | ||
| import pytest | ||
| from dataclasses import asdict, dataclass | ||
| from typing import Optional, List | ||
|
|
||
| from sentry_sdk.tracing_utils import _should_be_included, Baggage | ||
| import pytest | ||
| from sentry_sdk.tracing_utils import ( | ||
| _should_be_included, | ||
| _should_continue_trace, | ||
| Baggage, | ||
| ) | ||
| from tests.conftest import TestTransportWithOptions | ||
|
|
||
|
|
||
| def id_function(val): | ||
|
|
@@ -146,3 +151,130 @@ def test_strip_sentry_baggage(header, expected): | |
| ) | ||
| def test_baggage_repr(baggage, expected_repr): | ||
| assert repr(baggage) == expected_repr | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ( | ||
| "baggage_header", | ||
| "dsn", | ||
| "explicit_org_id", | ||
| "strict_trace_continuation", | ||
| "should_continue_trace", | ||
| ), | ||
| ( | ||
| # continue cases when strict_trace_continuation=False | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700, sentry-org_id=1234", | ||
| "https://[email protected]/12312012", | ||
| None, | ||
| False, | ||
| True, | ||
| ), | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700", | ||
| "https://[email protected]/12312012", | ||
| None, | ||
| False, | ||
| True, | ||
| ), | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700, sentry-org_id=1234", | ||
| None, | ||
| None, | ||
| False, | ||
| True, | ||
| ), | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700, sentry-org_id=1234", | ||
| None, | ||
| "1234", | ||
| False, | ||
| True, | ||
| ), | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700, sentry-org_id=1234", | ||
| "https://mysecret@not_org_id.ingest.sentry.io/12312012", | ||
| None, | ||
| False, | ||
| True, | ||
| ), | ||
| # start new cases when strict_trace_continuation=False | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700, sentry-org_id=1234", | ||
| "https://[email protected]/12312012", | ||
| None, | ||
| False, | ||
| False, | ||
| ), | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700, sentry-org_id=1234", | ||
| "https://[email protected]/12312012", | ||
| "9999", | ||
| False, | ||
| False, | ||
| ), | ||
| # continue cases when strict_trace_continuation=True | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700, sentry-org_id=1234", | ||
| "https://[email protected]/12312012", | ||
| None, | ||
| True, | ||
| True, | ||
| ), | ||
| ("sentry-trace_id=771a43a4192642f0b136d5159a501700", None, None, True, True), | ||
| # start new cases when strict_trace_continuation=True | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700", | ||
| "https://[email protected]/12312012", | ||
| None, | ||
| True, | ||
| False, | ||
| ), | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700, sentry-org_id=1234", | ||
| None, | ||
| None, | ||
| True, | ||
| False, | ||
| ), | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700, sentry-org_id=1234", | ||
| "https://mysecret@not_org_id.ingest.sentry.io/12312012", | ||
| None, | ||
| True, | ||
| False, | ||
| ), | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700, sentry-org_id=1234", | ||
| "https://[email protected]/12312012", | ||
| None, | ||
| True, | ||
| False, | ||
| ), | ||
| ( | ||
| "sentry-trace_id=771a43a4192642f0b136d5159a501700, sentry-org_id=1234", | ||
| "https://[email protected]/12312012", | ||
| "9999", | ||
| True, | ||
| False, | ||
| ), | ||
| ), | ||
| ) | ||
| def test_should_continue_trace( | ||
| sentry_init, | ||
| baggage_header, | ||
| dsn, | ||
| explicit_org_id, | ||
| strict_trace_continuation, | ||
| should_continue_trace, | ||
| ): | ||
| sentry_init( | ||
| dsn=dsn, | ||
| org_id=explicit_org_id, | ||
| strict_trace_continuation=strict_trace_continuation, | ||
| traces_sample_rate=1.0, | ||
| transport=TestTransportWithOptions, | ||
| ) | ||
|
|
||
| baggage = Baggage.from_incoming_header(baggage_header) if baggage_header else None | ||
| assert _should_continue_trace(baggage) == should_continue_trace | ||
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.
Uh oh!
There was an error while loading. Please reload this page.