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: 4 additions & 0 deletions src/sentry/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ def handle_query_errors() -> Iterator[None]:
except SnubaRPCError as error:
message = "Internal error. Please try again."
arg = error.args[0] if len(error.args) > 0 else None
if getattr(arg, "code", None) == 408:
sentry_sdk.set_tag("query.error_reason", "Timeout")
sentry_sdk.set_attribute("query.error_reason", "Timeout")
raise ParseError(detail=TIMEOUT_RPC_ERROR_MESSAGE)
if isinstance(arg, TimeoutError):
sentry_sdk.set_tag("query.error_reason", "Timeout")
sentry_sdk.set_attribute("query.error_reason", "Timeout")
Expand Down
28 changes: 26 additions & 2 deletions tests/sentry/api/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from django.db import OperationalError
from django.utils import timezone
from rest_framework.exceptions import APIException, Throttled, ValidationError
from rest_framework.exceptions import APIException, ParseError, Throttled, ValidationError
from sentry_sdk import Scope
from snuba_sdk.column import InvalidColumnError

Expand Down Expand Up @@ -39,7 +39,7 @@
SnubaError,
UnqualifiedQueryError,
)
from sentry.utils.snuba_rpc import SnubaRPCTooManySimultaneous, SnubaRPCUnavailable
from sentry.utils.snuba_rpc import SnubaRPCError, SnubaRPCTooManySimultaneous, SnubaRPCUnavailable


class GetDateRangeFromParamsTest(unittest.TestCase):
Expand Down Expand Up @@ -277,6 +277,30 @@ def test_handle_snuba_rpc_unavailable(
mock_warning.assert_called_once_with("snuba_rpc.unavailable")
mock_capture_exception.assert_not_called()

@patch("sentry.api.utils.sentry_sdk.capture_exception")
@patch("sentry.api.utils.sentry_sdk.set_attribute")
@patch("sentry.api.utils.sentry_sdk.set_tag")
def test_handle_snuba_rpc_query_timeout(
self,
mock_set_tag: MagicMock,
mock_set_attribute: MagicMock,
mock_capture_exception: MagicMock,
) -> None:
from sentry_protos.snuba.v1.error_pb2 import Error as ErrorProto

error_proto = ErrorProto(
code=408,
message="Query timed out, this violates the EAP SLO",
)
with pytest.raises(ParseError) as raised:
with handle_query_errors():
raise SnubaRPCError(error_proto)

assert raised.value.status_code == 400
mock_set_tag.assert_called_once_with("query.error_reason", "Timeout")
mock_set_attribute.assert_called_once_with("query.error_reason", "Timeout")
mock_capture_exception.assert_not_called()


class ClampDateRangeTest(unittest.TestCase):
def test_no_clamp_if_range_under_max(self) -> None:
Expand Down
Loading