-
Notifications
You must be signed in to change notification settings - Fork 571
Add org_id support #5166
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
Add org_id support #5166
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| SentrySpanProcessor, | ||
| link_trace_context_to_error_event, | ||
| ) | ||
| from sentry_sdk.utils import Dsn | ||
| from sentry_sdk.tracing import Span, Transaction | ||
| from sentry_sdk.tracing_utils import extract_sentrytrace_data | ||
|
|
||
|
|
@@ -23,7 +24,7 @@ def test_is_sentry_span(): | |
|
|
||
| client = MagicMock() | ||
| client.options = {"instrumenter": "otel"} | ||
| client.dsn = "https://[email protected]/123456" | ||
| client.parsed_dsn = Dsn("https://[email protected]/123456") | ||
| sentry_sdk.get_global_scope().set_client(client) | ||
|
|
||
| assert not span_processor._is_sentry_span(otel_span) | ||
|
|
||
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,7 +13,19 @@ | |
| import pytest | ||
|
|
||
| import sentry_sdk | ||
| import sentry_sdk.client | ||
| 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 | ||
|
|
||
|
|
||
| def test_dsc_head_of_trace(sentry_init, capture_envelopes): | ||
|
|
@@ -22,10 +34,11 @@ def test_dsc_head_of_trace(sentry_init, capture_envelopes): | |
| and sends a transaction event to Sentry. | ||
| """ | ||
| sentry_init( | ||
| dsn="https://mysecret@bla.ingest.sentry.io/12312012", | ||
| dsn="https://mysecret@o1234.ingest.sentry.io/12312012", | ||
| release="[email protected]", | ||
| environment="canary", | ||
| traces_sample_rate=1.0, | ||
| transport=TransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
|
|
@@ -45,6 +58,10 @@ def test_dsc_head_of_trace(sentry_init, capture_envelopes): | |
| assert type(envelope_trace_header["public_key"]) == str | ||
| assert envelope_trace_header["public_key"] == "mysecret" | ||
|
|
||
| assert "org_id" in envelope_trace_header | ||
| assert type(envelope_trace_header["org_id"]) == str | ||
| assert envelope_trace_header["org_id"] == "1234" | ||
|
|
||
| assert "sample_rate" in envelope_trace_header | ||
| assert type(envelope_trace_header["sample_rate"]) == str | ||
| assert envelope_trace_header["sample_rate"] == "1.0" | ||
|
|
@@ -66,16 +83,46 @@ def test_dsc_head_of_trace(sentry_init, capture_envelopes): | |
| assert envelope_trace_header["transaction"] == "foo" | ||
|
|
||
|
|
||
| def test_dsc_head_of_trace_uses_custom_org_id(sentry_init, capture_envelopes): | ||
| """ | ||
| Our service is the head of the trace (it starts a new trace) | ||
| and sends a transaction event to Sentry. | ||
| """ | ||
| sentry_init( | ||
| dsn="https://[email protected]/12312012", | ||
| org_id="9999", | ||
| release="[email protected]", | ||
| environment="canary", | ||
| traces_sample_rate=1.0, | ||
| transport=TransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
| # We start a new transaction | ||
| with sentry_sdk.start_transaction(name="foo"): | ||
| pass | ||
|
|
||
| assert len(envelopes) == 1 | ||
|
|
||
| transaction_envelope = envelopes[0] | ||
| envelope_trace_header = transaction_envelope.headers["trace"] | ||
|
|
||
| assert "org_id" in envelope_trace_header | ||
| assert type(envelope_trace_header["org_id"]) == str | ||
| assert envelope_trace_header["org_id"] == "9999" | ||
|
|
||
|
|
||
| def test_dsc_continuation_of_trace(sentry_init, capture_envelopes): | ||
| """ | ||
| Another service calls our service and passes tracing information to us. | ||
| Our service is continuing the trace and sends a transaction event to Sentry. | ||
| """ | ||
| sentry_init( | ||
| dsn="https://mysecret@bla.ingest.sentry.io/12312012", | ||
| dsn="https://mysecret@o1234.ingest.sentry.io/12312012", | ||
| release="[email protected]", | ||
| environment="canary", | ||
| traces_sample_rate=1.0, | ||
| transport=TransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
|
|
@@ -149,10 +196,11 @@ def my_traces_sampler(sampling_context): | |
| return 0.25 | ||
|
|
||
| sentry_init( | ||
| dsn="https://mysecret@bla.ingest.sentry.io/12312012", | ||
| dsn="https://mysecret@o1234.ingest.sentry.io/12312012", | ||
| release="[email protected]", | ||
| environment="canary", | ||
| traces_sampler=my_traces_sampler, | ||
| transport=TransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
|
|
@@ -219,9 +267,10 @@ def test_dsc_issue(sentry_init, capture_envelopes): | |
| Our service is a standalone service that does not have tracing enabled. Just uses Sentry for error reporting. | ||
| """ | ||
| sentry_init( | ||
| dsn="https://mysecret@bla.ingest.sentry.io/12312012", | ||
| dsn="https://mysecret@o1234.ingest.sentry.io/12312012", | ||
| release="[email protected]", | ||
| environment="canary", | ||
| transport=TransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
|
|
@@ -244,6 +293,10 @@ def test_dsc_issue(sentry_init, capture_envelopes): | |
| assert type(envelope_trace_header["public_key"]) == str | ||
| assert envelope_trace_header["public_key"] == "mysecret" | ||
|
|
||
| assert "org_id" in envelope_trace_header | ||
| assert type(envelope_trace_header["org_id"]) == str | ||
| assert envelope_trace_header["org_id"] == "1234" | ||
|
|
||
| assert "sample_rate" not in envelope_trace_header | ||
|
|
||
| assert "sampled" not in envelope_trace_header | ||
|
|
@@ -265,10 +318,11 @@ def test_dsc_issue_with_tracing(sentry_init, capture_envelopes): | |
| Envelopes containing errors also have the same DSC than the transaction envelopes. | ||
| """ | ||
| sentry_init( | ||
| dsn="https://mysecret@bla.ingest.sentry.io/12312012", | ||
| dsn="https://mysecret@o1234.ingest.sentry.io/12312012", | ||
| release="[email protected]", | ||
| environment="canary", | ||
| traces_sample_rate=1.0, | ||
| transport=TransportWithOptions, | ||
| ) | ||
| envelopes = capture_envelopes() | ||
|
|
||
|
|
@@ -294,6 +348,10 @@ def test_dsc_issue_with_tracing(sentry_init, capture_envelopes): | |
| assert type(envelope_trace_header["public_key"]) == str | ||
| assert envelope_trace_header["public_key"] == "mysecret" | ||
|
|
||
| assert "org_id" in envelope_trace_header | ||
| assert type(envelope_trace_header["org_id"]) == str | ||
| assert envelope_trace_header["org_id"] == "1234" | ||
|
|
||
| assert "sample_rate" in envelope_trace_header | ||
| assert envelope_trace_header["sample_rate"] == "1.0" | ||
| assert type(envelope_trace_header["sample_rate"]) == str | ||
|
|
@@ -332,10 +390,11 @@ def test_dsc_issue_twp(sentry_init, capture_envelopes, traces_sample_rate): | |
| (This test would be service B in this scenario) | ||
| """ | ||
| sentry_init( | ||
| dsn="https://mysecret@bla.ingest.sentry.io/12312012", | ||
| dsn="https://mysecret@o1234.ingest.sentry.io/12312012", | ||
| release="[email protected]", | ||
| environment="canary", | ||
| traces_sample_rate=traces_sample_rate, | ||
| transport=TransportWithOptions, | ||
| ) | ||
| 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 |
|---|---|---|
|
|
@@ -119,6 +119,18 @@ def test_parse_dsn_paths(given, expected_envelope): | |
| assert auth.get_api_url(EndpointType.ENVELOPE) == expected_envelope | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "given,expected", | ||
| [ | ||
| ("https://[email protected]/123", None), | ||
| ("https://[email protected]/123", "1234"), | ||
| ], | ||
| ) | ||
| def test_parse_dsn_org_id(given, expected): | ||
| dsn = Dsn(given) | ||
| assert dsn.org_id == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "dsn", | ||
| [ | ||
|
|
||
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.