Skip to content

Commit adab5ac

Browse files
authored
Remove unsupported SPANSTATUS.(ERROR|UNSET) (#5146)
### Description The new `ERROR` and `UNSET` statuses introduced in #4820 are [not supported by relay](https://github.com/getsentry/relay/blob/8e6c963cdd79dc9ba2bebc21518a3553f70feeb3/relay-base-schema/src/spans.rs#L19-L94) and caused a regression. #### Issues * resolves: #5060 * resolves: PY-1961
1 parent 7e06f3f commit adab5ac

File tree

13 files changed

+34
-37
lines changed

13 files changed

+34
-37
lines changed

sentry_sdk/consts.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,20 +864,18 @@ class SPANSTATUS:
864864
CANCELLED = "cancelled"
865865
DATA_LOSS = "data_loss"
866866
DEADLINE_EXCEEDED = "deadline_exceeded"
867-
ERROR = "error" # OTel status code: https://opentelemetry.io/docs/concepts/signals/traces/#span-status
868867
FAILED_PRECONDITION = "failed_precondition"
869868
INTERNAL_ERROR = "internal_error"
870869
INVALID_ARGUMENT = "invalid_argument"
871870
NOT_FOUND = "not_found"
872-
OK = "ok" # HTTP 200 and OTel status code: https://opentelemetry.io/docs/concepts/signals/traces/#span-status
871+
OK = "ok"
873872
OUT_OF_RANGE = "out_of_range"
874873
PERMISSION_DENIED = "permission_denied"
875874
RESOURCE_EXHAUSTED = "resource_exhausted"
876875
UNAUTHENTICATED = "unauthenticated"
877876
UNAVAILABLE = "unavailable"
878877
UNIMPLEMENTED = "unimplemented"
879878
UNKNOWN_ERROR = "unknown_error"
880-
UNSET = "unset" # OTel status code: https://opentelemetry.io/docs/concepts/signals/traces/#span-status
881879

882880

883881
class OP:

sentry_sdk/integrations/anthropic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def _sentry_patched_create_sync(*args, **kwargs):
381381
return _execute_sync(f, *args, **kwargs)
382382
finally:
383383
span = sentry_sdk.get_current_span()
384-
if span is not None and span.status == SPANSTATUS.ERROR:
384+
if span is not None and span.status == SPANSTATUS.INTERNAL_ERROR:
385385
with capture_internal_exceptions():
386386
span.__exit__(None, None, None)
387387

@@ -420,7 +420,7 @@ async def _sentry_patched_create_async(*args, **kwargs):
420420
return await _execute_async(f, *args, **kwargs)
421421
finally:
422422
span = sentry_sdk.get_current_span()
423-
if span is not None and span.status == SPANSTATUS.ERROR:
423+
if span is not None and span.status == SPANSTATUS.INTERNAL_ERROR:
424424
with capture_internal_exceptions():
425425
span.__exit__(None, None, None)
426426

sentry_sdk/integrations/google_genai/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def new_iterator():
107107
yield chunk
108108
except Exception as exc:
109109
_capture_exception(exc)
110-
chat_span.set_status(SPANSTATUS.ERROR)
110+
chat_span.set_status(SPANSTATUS.INTERNAL_ERROR)
111111
raise
112112
finally:
113113
# Accumulate all chunks and set final response data on spans
@@ -181,7 +181,7 @@ async def new_async_iterator():
181181
yield chunk
182182
except Exception as exc:
183183
_capture_exception(exc)
184-
chat_span.set_status(SPANSTATUS.ERROR)
184+
chat_span.set_status(SPANSTATUS.INTERNAL_ERROR)
185185
raise
186186
finally:
187187
# Accumulate all chunks and set final response data on spans
@@ -244,7 +244,7 @@ def new_generate_content(self, *args, **kwargs):
244244
response = f(self, *args, **kwargs)
245245
except Exception as exc:
246246
_capture_exception(exc)
247-
chat_span.set_status(SPANSTATUS.ERROR)
247+
chat_span.set_status(SPANSTATUS.INTERNAL_ERROR)
248248
raise
249249

250250
set_span_data_for_response(chat_span, integration, response)
@@ -290,7 +290,7 @@ async def new_async_generate_content(self, *args, **kwargs):
290290
response = await f(self, *args, **kwargs)
291291
except Exception as exc:
292292
_capture_exception(exc)
293-
chat_span.set_status(SPANSTATUS.ERROR)
293+
chat_span.set_status(SPANSTATUS.INTERNAL_ERROR)
294294
raise
295295

296296
set_span_data_for_response(chat_span, integration, response)

sentry_sdk/integrations/openai_agents/spans/execute_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def update_execute_tool_span(span, agent, tool, result):
4242
if isinstance(result, str) and result.startswith(
4343
"An error occurred while running the tool"
4444
):
45-
span.set_status(SPANSTATUS.ERROR)
45+
span.set_status(SPANSTATUS.INTERNAL_ERROR)
4646

4747
if should_send_default_pii():
4848
span.set_data(SPANDATA.GEN_AI_TOOL_OUTPUT, result)

sentry_sdk/integrations/openai_agents/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,4 @@ def _create_mcp_execute_tool_spans(span, result):
196196
SPANDATA.GEN_AI_TOOL_OUTPUT, output.output
197197
)
198198
if output.error:
199-
execute_tool_span.set_status(SPANSTATUS.ERROR)
199+
execute_tool_span.set_status(SPANSTATUS.INTERNAL_ERROR)

sentry_sdk/tracing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,7 @@ def __enter__(self):
408408
def __exit__(self, ty, value, tb):
409409
# type: (Optional[Any], Optional[Any], Optional[Any]) -> None
410410
if value is not None and should_be_treated_as_error(ty, value):
411-
if self.status != SPANSTATUS.ERROR:
412-
self.set_status(SPANSTATUS.INTERNAL_ERROR)
411+
self.set_status(SPANSTATUS.INTERNAL_ERROR)
413412

414413
with capture_internal_exceptions():
415414
scope, old_span = self._context_manager_state

sentry_sdk/tracing_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -933,14 +933,14 @@ def get_current_span(scope=None):
933933
def set_span_errored(span=None):
934934
# type: (Optional[Span]) -> None
935935
"""
936-
Set the status of the current or given span to ERROR.
937-
Also sets the status of the transaction (root span) to ERROR.
936+
Set the status of the current or given span to INTERNAL_ERROR.
937+
Also sets the status of the transaction (root span) to INTERNAL_ERROR.
938938
"""
939939
span = span or get_current_span()
940940
if span is not None:
941-
span.set_status(SPANSTATUS.ERROR)
941+
span.set_status(SPANSTATUS.INTERNAL_ERROR)
942942
if span.containing_transaction is not None:
943-
span.containing_transaction.set_status(SPANSTATUS.ERROR)
943+
span.containing_transaction.set_status(SPANSTATUS.INTERNAL_ERROR)
944944

945945

946946
def _generate_sample_rand(

tests/integrations/anthropic/test_anthropic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ def test_exception_message_create(sentry_init, capture_events):
701701

702702
(event, transaction) = events
703703
assert event["level"] == "error"
704-
assert transaction["contexts"]["trace"]["status"] == "error"
704+
assert transaction["contexts"]["trace"]["status"] == "internal_error"
705705

706706

707707
def test_span_status_error(sentry_init, capture_events):
@@ -722,8 +722,8 @@ def test_span_status_error(sentry_init, capture_events):
722722

723723
(error, transaction) = events
724724
assert error["level"] == "error"
725-
assert transaction["spans"][0]["tags"]["status"] == "error"
726-
assert transaction["contexts"]["trace"]["status"] == "error"
725+
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
726+
assert transaction["contexts"]["trace"]["status"] == "internal_error"
727727

728728

729729
@pytest.mark.asyncio
@@ -745,8 +745,8 @@ async def test_span_status_error_async(sentry_init, capture_events):
745745

746746
(error, transaction) = events
747747
assert error["level"] == "error"
748-
assert transaction["spans"][0]["tags"]["status"] == "error"
749-
assert transaction["contexts"]["trace"]["status"] == "error"
748+
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
749+
assert transaction["contexts"]["trace"]["status"] == "internal_error"
750750

751751

752752
@pytest.mark.asyncio
@@ -767,7 +767,7 @@ async def test_exception_message_create_async(sentry_init, capture_events):
767767

768768
(event, transaction) = events
769769
assert event["level"] == "error"
770-
assert transaction["contexts"]["trace"]["status"] == "error"
770+
assert transaction["contexts"]["trace"]["status"] == "internal_error"
771771

772772

773773
def test_span_origin(sentry_init, capture_events):

tests/integrations/cohere/test_cohere.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ def test_span_status_error(sentry_init, capture_events):
181181

182182
(error, transaction) = events
183183
assert error["level"] == "error"
184-
assert transaction["spans"][0]["tags"]["status"] == "error"
185-
assert transaction["contexts"]["trace"]["status"] == "error"
184+
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
185+
assert transaction["contexts"]["trace"]["status"] == "internal_error"
186186

187187

188188
@pytest.mark.parametrize(

tests/integrations/huggingface_hub/test_huggingface_hub.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ def test_chat_completion_api_error(
792792
assert span["op"] == "gen_ai.chat"
793793
assert span["description"] == "chat test-model"
794794
assert span["origin"] == "auto.ai.huggingface_hub"
795-
assert span.get("tags", {}).get("status") == "error"
795+
assert span.get("tags", {}).get("status") == "internal_error"
796796

797797
assert (
798798
error["contexts"]["trace"]["trace_id"]
@@ -835,9 +835,9 @@ def test_span_status_error(sentry_init, capture_events, mock_hf_api_with_errors)
835835
assert sp["op"] == "http.client"
836836

837837
assert span is not None
838-
assert span["tags"]["status"] == "error"
838+
assert span["tags"]["status"] == "internal_error"
839839

840-
assert transaction["contexts"]["trace"]["status"] == "error"
840+
assert transaction["contexts"]["trace"]["status"] == "internal_error"
841841

842842

843843
@pytest.mark.httpx_mock(assert_all_requests_were_expected=False)

0 commit comments

Comments
 (0)