|
1 |
| -import weakref |
2 | 1 | import gc
|
| 2 | +import random |
3 | 3 | import re
|
| 4 | +import sys |
| 5 | +import weakref |
| 6 | + |
4 | 7 | import pytest
|
5 |
| -import random |
6 | 8 |
|
7 | 9 | import sentry_sdk
|
8 | 10 | from sentry_sdk import (
|
@@ -297,3 +299,55 @@ def test_trace_propagation_meta_head_sdk(sentry_init):
|
297 | 299 | assert 'meta name="baggage"' in baggage
|
298 | 300 | baggage_content = re.findall('content="([^"]*)"', baggage)[0]
|
299 | 301 | assert baggage_content == transaction.get_baggage().serialize()
|
| 302 | + |
| 303 | + |
| 304 | +@pytest.mark.parametrize( |
| 305 | + "exception_cls,exception_value", |
| 306 | + [ |
| 307 | + (SystemExit, 0), |
| 308 | + ], |
| 309 | +) |
| 310 | +def test_non_error_exceptions( |
| 311 | + sentry_init, capture_events, exception_cls, exception_value |
| 312 | +): |
| 313 | + sentry_init(traces_sample_rate=1.0) |
| 314 | + events = capture_events() |
| 315 | + |
| 316 | + with start_transaction(name="hi") as transaction: |
| 317 | + transaction.set_status(SPANSTATUS.OK) |
| 318 | + with pytest.raises(exception_cls): |
| 319 | + with start_span(op="foo", name="foodesc"): |
| 320 | + raise exception_cls(exception_value) |
| 321 | + |
| 322 | + assert len(events) == 1 |
| 323 | + event = events[0] |
| 324 | + |
| 325 | + span = event["spans"][0] |
| 326 | + assert "status" not in span.get("tags", {}) |
| 327 | + assert "status" not in event["tags"] |
| 328 | + assert event["contexts"]["trace"]["status"] == "ok" |
| 329 | + |
| 330 | + |
| 331 | +@pytest.mark.parametrize("exception_value", [None, 0, False]) |
| 332 | +def test_good_sysexit_doesnt_fail_transaction( |
| 333 | + sentry_init, capture_events, exception_value |
| 334 | +): |
| 335 | + sentry_init(traces_sample_rate=1.0) |
| 336 | + events = capture_events() |
| 337 | + |
| 338 | + with start_transaction(name="hi") as transaction: |
| 339 | + transaction.set_status(SPANSTATUS.OK) |
| 340 | + with pytest.raises(SystemExit): |
| 341 | + with start_span(op="foo", name="foodesc"): |
| 342 | + if exception_value is not False: |
| 343 | + sys.exit(exception_value) |
| 344 | + else: |
| 345 | + sys.exit() |
| 346 | + |
| 347 | + assert len(events) == 1 |
| 348 | + event = events[0] |
| 349 | + |
| 350 | + span = event["spans"][0] |
| 351 | + assert "status" not in span.get("tags", {}) |
| 352 | + assert "status" not in event["tags"] |
| 353 | + assert event["contexts"]["trace"]["status"] == "ok" |
0 commit comments