Skip to content

Do not add trace headers to requests to Sentry #2240

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 5 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,15 @@ def should_propagate_trace(hub, url):
client = hub.client # type: Any
trace_propagation_targets = client.options["trace_propagation_targets"]

if client.transport and client.transport.parsed_dsn:
dsn_url = client.transport.parsed_dsn.netloc
else:
dsn_url = None

is_request_to_sentry = dsn_url and dsn_url in url
if is_request_to_sentry:
return False

return match_regex_list(url, trace_propagation_targets, substring_matching=True)


Expand Down
46 changes: 46 additions & 0 deletions tests/tracing/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from sentry_sdk.consts import MATCH_ALL
from sentry_sdk.tracing import Span, Transaction
from sentry_sdk.tracing_utils import should_propagate_trace
from sentry_sdk.utils import Dsn

try:
from unittest import mock # python 3.3 and above
Expand Down Expand Up @@ -305,5 +306,50 @@ def test_should_propagate_trace(
hub = MagicMock()
hub.client = MagicMock()
hub.client.options = {"trace_propagation_targets": trace_propagation_targets}
hub.client.transport = MagicMock()
hub.client.transport.parsed_dsn = Dsn("https://[email protected]/12312012")

assert should_propagate_trace(hub, url) == expected_propagation_decision


@pytest.mark.parametrize(
"dsn,url,expected_propagation_decision",
[
(
"https://[email protected]/12312012",
"http://example.com",
True,
),
(
"https://[email protected]/12312012",
"https://[email protected]/12312012",
False,
),
(
"https://[email protected]/12312012",
"http://squirrelchasers.ingest.sentry.io/12312012",
False,
),
(
"https://[email protected]/12312012",
"http://ingest.sentry.io/12312012",
True,
),
(
"https://[email protected]/12312012",
"http://localsentry.example.com",
False,
),
],
)
def test_should_propagate_trace_to_sentry(
sentry_init, dsn, url, expected_propagation_decision
):
sentry_init(
dsn=dsn,
traces_sample_rate=1.0,
)

Hub.current.client.transport.parsed_dsn = Dsn(dsn)

assert should_propagate_trace(Hub.current, url) == expected_propagation_decision