Skip to content

Commit

Permalink
Do not add trace headers (sentry-trace and baggage) to HTTP reque…
Browse files Browse the repository at this point in the history
…sts to Sentry (#2240)
  • Loading branch information
antonpirker committed Jul 12, 2023
1 parent 994a45b commit 7a9b1b7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sentry_sdk/tracing_utils.py
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
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://bla@xxx.sentry.io/12312012")

assert should_propagate_trace(hub, url) == expected_propagation_decision


@pytest.mark.parametrize(
"dsn,url,expected_propagation_decision",
[
(
"https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012",
"http://example.com",
True,
),
(
"https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012",
"https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012",
False,
),
(
"https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012",
"http://squirrelchasers.ingest.sentry.io/12312012",
False,
),
(
"https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012",
"http://ingest.sentry.io/12312012",
True,
),
(
"https://abc@localsentry.example.com/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

0 comments on commit 7a9b1b7

Please sign in to comment.