|
8 | 8 | from sentry_sdk.consts import MATCH_ALL
|
9 | 9 | from sentry_sdk.tracing import Span, Transaction
|
10 | 10 | from sentry_sdk.tracing_utils import should_propagate_trace
|
| 11 | +from sentry_sdk.utils import Dsn |
11 | 12 |
|
12 | 13 | try:
|
13 | 14 | from unittest import mock # python 3.3 and above
|
@@ -305,5 +306,50 @@ def test_should_propagate_trace(
|
305 | 306 | hub = MagicMock()
|
306 | 307 | hub.client = MagicMock()
|
307 | 308 | hub.client.options = {"trace_propagation_targets": trace_propagation_targets}
|
| 309 | + hub.client.transport = MagicMock() |
| 310 | + hub.client.transport.parsed_dsn = Dsn("https://bla@xxx.sentry.io/12312012") |
308 | 311 |
|
309 | 312 | assert should_propagate_trace(hub, url) == expected_propagation_decision
|
| 313 | + |
| 314 | + |
| 315 | +@pytest.mark.parametrize( |
| 316 | + "dsn,url,expected_propagation_decision", |
| 317 | + [ |
| 318 | + ( |
| 319 | + "https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012", |
| 320 | + "http://example.com", |
| 321 | + True, |
| 322 | + ), |
| 323 | + ( |
| 324 | + "https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012", |
| 325 | + "https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012", |
| 326 | + False, |
| 327 | + ), |
| 328 | + ( |
| 329 | + "https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012", |
| 330 | + "http://squirrelchasers.ingest.sentry.io/12312012", |
| 331 | + False, |
| 332 | + ), |
| 333 | + ( |
| 334 | + "https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012", |
| 335 | + "http://ingest.sentry.io/12312012", |
| 336 | + True, |
| 337 | + ), |
| 338 | + ( |
| 339 | + "https://abc@localsentry.example.com/12312012", |
| 340 | + "http://localsentry.example.com", |
| 341 | + False, |
| 342 | + ), |
| 343 | + ], |
| 344 | +) |
| 345 | +def test_should_propagate_trace_to_sentry( |
| 346 | + sentry_init, dsn, url, expected_propagation_decision |
| 347 | +): |
| 348 | + sentry_init( |
| 349 | + dsn=dsn, |
| 350 | + traces_sample_rate=1.0, |
| 351 | + ) |
| 352 | + |
| 353 | + Hub.current.client.transport.parsed_dsn = Dsn(dsn) |
| 354 | + |
| 355 | + assert should_propagate_trace(Hub.current, url) == expected_propagation_decision |
0 commit comments