Skip to content
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
4 changes: 1 addition & 3 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,20 +864,18 @@ class SPANSTATUS:
CANCELLED = "cancelled"
DATA_LOSS = "data_loss"
DEADLINE_EXCEEDED = "deadline_exceeded"
ERROR = "error" # OTel status code: https://opentelemetry.io/docs/concepts/signals/traces/#span-status
FAILED_PRECONDITION = "failed_precondition"
INTERNAL_ERROR = "internal_error"
INVALID_ARGUMENT = "invalid_argument"
NOT_FOUND = "not_found"
OK = "ok" # HTTP 200 and OTel status code: https://opentelemetry.io/docs/concepts/signals/traces/#span-status
OK = "ok"
OUT_OF_RANGE = "out_of_range"
PERMISSION_DENIED = "permission_denied"
RESOURCE_EXHAUSTED = "resource_exhausted"
UNAUTHENTICATED = "unauthenticated"
UNAVAILABLE = "unavailable"
UNIMPLEMENTED = "unimplemented"
UNKNOWN_ERROR = "unknown_error"
UNSET = "unset" # OTel status code: https://opentelemetry.io/docs/concepts/signals/traces/#span-status


class OP:
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def _sentry_patched_create_sync(*args, **kwargs):
return _execute_sync(f, *args, **kwargs)
finally:
span = sentry_sdk.get_current_span()
if span is not None and span.status == SPANSTATUS.ERROR:
if span is not None and span.status == SPANSTATUS.INTERNAL_ERROR:
with capture_internal_exceptions():
span.__exit__(None, None, None)

Expand Down Expand Up @@ -420,7 +420,7 @@ async def _sentry_patched_create_async(*args, **kwargs):
return await _execute_async(f, *args, **kwargs)
finally:
span = sentry_sdk.get_current_span()
if span is not None and span.status == SPANSTATUS.ERROR:
if span is not None and span.status == SPANSTATUS.INTERNAL_ERROR:
with capture_internal_exceptions():
span.__exit__(None, None, None)

Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/integrations/google_genai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def new_iterator():
yield chunk
except Exception as exc:
_capture_exception(exc)
chat_span.set_status(SPANSTATUS.ERROR)
chat_span.set_status(SPANSTATUS.INTERNAL_ERROR)
raise
finally:
# Accumulate all chunks and set final response data on spans
Expand Down Expand Up @@ -181,7 +181,7 @@ async def new_async_iterator():
yield chunk
except Exception as exc:
_capture_exception(exc)
chat_span.set_status(SPANSTATUS.ERROR)
chat_span.set_status(SPANSTATUS.INTERNAL_ERROR)
raise
finally:
# Accumulate all chunks and set final response data on spans
Expand Down Expand Up @@ -244,7 +244,7 @@ def new_generate_content(self, *args, **kwargs):
response = f(self, *args, **kwargs)
except Exception as exc:
_capture_exception(exc)
chat_span.set_status(SPANSTATUS.ERROR)
chat_span.set_status(SPANSTATUS.INTERNAL_ERROR)
raise

set_span_data_for_response(chat_span, integration, response)
Expand Down Expand Up @@ -290,7 +290,7 @@ async def new_async_generate_content(self, *args, **kwargs):
response = await f(self, *args, **kwargs)
except Exception as exc:
_capture_exception(exc)
chat_span.set_status(SPANSTATUS.ERROR)
chat_span.set_status(SPANSTATUS.INTERNAL_ERROR)
raise

set_span_data_for_response(chat_span, integration, response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def update_execute_tool_span(span, agent, tool, result):
if isinstance(result, str) and result.startswith(
"An error occurred while running the tool"
):
span.set_status(SPANSTATUS.ERROR)
span.set_status(SPANSTATUS.INTERNAL_ERROR)

if should_send_default_pii():
span.set_data(SPANDATA.GEN_AI_TOOL_OUTPUT, result)
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/openai_agents/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,4 @@ def _create_mcp_execute_tool_spans(span, result):
SPANDATA.GEN_AI_TOOL_OUTPUT, output.output
)
if output.error:
execute_tool_span.set_status(SPANSTATUS.ERROR)
execute_tool_span.set_status(SPANSTATUS.INTERNAL_ERROR)
3 changes: 1 addition & 2 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,7 @@ def __enter__(self):
def __exit__(self, ty, value, tb):
# type: (Optional[Any], Optional[Any], Optional[Any]) -> None
if value is not None and should_be_treated_as_error(ty, value):
if self.status != SPANSTATUS.ERROR:
self.set_status(SPANSTATUS.INTERNAL_ERROR)
self.set_status(SPANSTATUS.INTERNAL_ERROR)

with capture_internal_exceptions():
scope, old_span = self._context_manager_state
Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,14 +933,14 @@ def get_current_span(scope=None):
def set_span_errored(span=None):
# type: (Optional[Span]) -> None
"""
Set the status of the current or given span to ERROR.
Also sets the status of the transaction (root span) to ERROR.
Set the status of the current or given span to INTERNAL_ERROR.
Also sets the status of the transaction (root span) to INTERNAL_ERROR.
"""
span = span or get_current_span()
if span is not None:
span.set_status(SPANSTATUS.ERROR)
span.set_status(SPANSTATUS.INTERNAL_ERROR)
if span.containing_transaction is not None:
span.containing_transaction.set_status(SPANSTATUS.ERROR)
span.containing_transaction.set_status(SPANSTATUS.INTERNAL_ERROR)


def _generate_sample_rand(
Expand Down
12 changes: 6 additions & 6 deletions tests/integrations/anthropic/test_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ def test_exception_message_create(sentry_init, capture_events):

(event, transaction) = events
assert event["level"] == "error"
assert transaction["contexts"]["trace"]["status"] == "error"
assert transaction["contexts"]["trace"]["status"] == "internal_error"


def test_span_status_error(sentry_init, capture_events):
Expand All @@ -722,8 +722,8 @@ def test_span_status_error(sentry_init, capture_events):

(error, transaction) = events
assert error["level"] == "error"
assert transaction["spans"][0]["tags"]["status"] == "error"
assert transaction["contexts"]["trace"]["status"] == "error"
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
assert transaction["contexts"]["trace"]["status"] == "internal_error"


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

(error, transaction) = events
assert error["level"] == "error"
assert transaction["spans"][0]["tags"]["status"] == "error"
assert transaction["contexts"]["trace"]["status"] == "error"
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
assert transaction["contexts"]["trace"]["status"] == "internal_error"


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

(event, transaction) = events
assert event["level"] == "error"
assert transaction["contexts"]["trace"]["status"] == "error"
assert transaction["contexts"]["trace"]["status"] == "internal_error"


def test_span_origin(sentry_init, capture_events):
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/cohere/test_cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ def test_span_status_error(sentry_init, capture_events):

(error, transaction) = events
assert error["level"] == "error"
assert transaction["spans"][0]["tags"]["status"] == "error"
assert transaction["contexts"]["trace"]["status"] == "error"
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
assert transaction["contexts"]["trace"]["status"] == "internal_error"


@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/huggingface_hub/test_huggingface_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ def test_chat_completion_api_error(
assert span["op"] == "gen_ai.chat"
assert span["description"] == "chat test-model"
assert span["origin"] == "auto.ai.huggingface_hub"
assert span.get("tags", {}).get("status") == "error"
assert span.get("tags", {}).get("status") == "internal_error"

assert (
error["contexts"]["trace"]["trace_id"]
Expand Down Expand Up @@ -835,9 +835,9 @@ def test_span_status_error(sentry_init, capture_events, mock_hf_api_with_errors)
assert sp["op"] == "http.client"

assert span is not None
assert span["tags"]["status"] == "error"
assert span["tags"]["status"] == "internal_error"

assert transaction["contexts"]["trace"]["status"] == "error"
assert transaction["contexts"]["trace"]["status"] == "internal_error"


@pytest.mark.httpx_mock(assert_all_requests_were_expected=False)
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/langchain/test_langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ def test_span_status_error(sentry_init, capture_events):

(error, transaction) = events
assert error["level"] == "error"
assert transaction["spans"][0]["tags"]["status"] == "error"
assert transaction["contexts"]["trace"]["status"] == "error"
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
assert transaction["contexts"]["trace"]["status"] == "internal_error"


def test_span_origin(sentry_init, capture_events):
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/openai/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ def test_span_status_error(sentry_init, capture_events):

(error, transaction) = events
assert error["level"] == "error"
assert transaction["spans"][0]["tags"]["status"] == "error"
assert transaction["contexts"]["trace"]["status"] == "error"
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
assert transaction["contexts"]["trace"]["status"] == "internal_error"


@pytest.mark.asyncio
Expand Down
10 changes: 5 additions & 5 deletions tests/integrations/openai_agents/test_openai_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,8 @@ async def test_span_status_error(sentry_init, capture_events, test_agent):

(error, transaction) = events
assert error["level"] == "error"
assert transaction["spans"][0]["tags"]["status"] == "error"
assert transaction["contexts"]["trace"]["status"] == "error"
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
assert transaction["contexts"]["trace"]["status"] == "internal_error"


@pytest.mark.asyncio
Expand Down Expand Up @@ -827,7 +827,7 @@ async def test_mcp_tool_execution_spans(sentry_init, capture_events, test_agent)
)

# Verify no error status since error was None
assert mcp_tool_span.get("tags", {}).get("status") != "error"
assert mcp_tool_span.get("tags", {}).get("status") != "internal_error"


@pytest.mark.asyncio
Expand Down Expand Up @@ -927,7 +927,7 @@ async def test_mcp_tool_execution_with_error(sentry_init, capture_events, test_a
assert mcp_tool_span["data"]["gen_ai.tool.output"] is None

# Verify error status was set
assert mcp_tool_span["tags"]["status"] == "error"
assert mcp_tool_span["tags"]["status"] == "internal_error"


@pytest.mark.asyncio
Expand Down Expand Up @@ -1218,4 +1218,4 @@ def failing_tool(message: str) -> str:

# Verify error status was set (this is the key test for our patch)
# The span should be marked as error because the tool execution failed
assert execute_tool_span["tags"]["status"] == "error"
assert execute_tool_span["tags"]["status"] == "internal_error"