Skip to content

Tread SystemExit(0) not as a span status of 'internal_error' #4094

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 2 commits into from
Feb 25, 2025
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
3 changes: 0 additions & 3 deletions sentry_sdk/integrations/opentelemetry/span_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ def _span_to_json(self, span):
}
)

if status:
span_json.setdefault("tags", {})["status"] = status

if parent_span_id:
span_json["parent_span_id"] = parent_span_id

Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
_serialize_span_attribute,
get_current_thread_meta,
logger,
should_be_treated_as_error,
)

from typing import TYPE_CHECKING, cast
Expand Down Expand Up @@ -424,7 +425,7 @@ def __enter__(self):

def __exit__(self, ty, value, tb):
# type: (Optional[Any], Optional[Any], Optional[Any]) -> None
if value is not None:
if value is not None and should_be_treated_as_error(ty, value):
self.set_status(SPANSTATUS.INTERNAL_ERROR)
else:
status_unset = (
Expand Down
1 change: 0 additions & 1 deletion sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,6 @@ def datetime_from_isoformat(value):
return result.astimezone(timezone.utc)


# TODO-neel-potel use in span status
def should_be_treated_as_error(ty, value):
# type: (Any, Any) -> bool
if ty == SystemExit and hasattr(value, "code") and value.code in (0, None):
Expand Down
11 changes: 5 additions & 6 deletions tests/tracing/test_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ def test_basic(sentry_init, capture_events, sample_rate):

span1, span2 = event["spans"]
parent_span = event
assert span1["tags"]["status"] == "internal_error"
assert span1["status"] == "internal_error"
assert span1["op"] == "foo"
assert span1["description"] == "foodesc"
assert span2["tags"]["status"] == "ok"
assert span2["status"] == "ok"
assert span2["op"] == "bar"
assert span2["description"] == "bardesc"
assert parent_span["transaction"] == "hi"
Expand Down Expand Up @@ -253,8 +252,8 @@ def test_non_error_exceptions(
sentry_init(traces_sample_rate=1.0)
events = capture_events()

with start_span(name="hi") as span:
span.set_status(SPANSTATUS.OK)
with start_span(name="hi") as root_span:
root_span.set_status(SPANSTATUS.OK)
with pytest.raises(exception_cls):
with start_span(op="foo", name="foodesc"):
raise exception_cls(exception_value)
Expand All @@ -264,7 +263,7 @@ def test_non_error_exceptions(

span = event["spans"][0]
assert "status" not in span.get("tags", {})
assert "status" not in event["tags"]
assert "status" not in event.get("tags", {})
assert event["contexts"]["trace"]["status"] == "ok"


Expand All @@ -289,5 +288,5 @@ def test_good_sysexit_doesnt_fail_transaction(

span = event["spans"][0]
assert "status" not in span.get("tags", {})
assert "status" not in event["tags"]
assert "status" not in event.get("tags", {})
assert event["contexts"]["trace"]["status"] == "ok"
Loading