|
@@ -1,13 +1,12 @@
|
|
|
from __future__ import annotations
|
|
|
|
|
|
-from contextlib import contextmanager
|
|
|
from datetime import timedelta
|
|
|
-from typing import Any, Callable, Dict, Generator, Optional, Sequence, Tuple
|
|
|
+from typing import Any, Callable, Dict, Optional, Sequence, Tuple
|
|
|
from urllib.parse import quote as urlquote
|
|
|
|
|
|
import sentry_sdk
|
|
|
from django.utils import timezone
|
|
|
-from rest_framework.exceptions import APIException, ParseError, ValidationError
|
|
|
+from rest_framework.exceptions import ParseError, ValidationError
|
|
|
from rest_framework.request import Request
|
|
|
from sentry_relay.consts import SPAN_STATUS_CODE_TO_NAME
|
|
|
|
|
@@ -19,13 +18,14 @@ from sentry.api.bases.organization import OrganizationEndpoint
|
|
|
from sentry.api.helpers.mobile import get_readable_device_name
|
|
|
from sentry.api.helpers.teams import get_teams
|
|
|
from sentry.api.serializers.snuba import BaseSnubaSerializer, SnubaTSResultSerializer
|
|
|
-from sentry.discover.arithmetic import ArithmeticError, is_equation, strip_equation
|
|
|
-from sentry.exceptions import IncompatibleMetricsQuery, InvalidSearchQuery
|
|
|
+from sentry.api.utils import handle_query_errors
|
|
|
+from sentry.discover.arithmetic import is_equation, strip_equation
|
|
|
+from sentry.exceptions import InvalidSearchQuery
|
|
|
from sentry.models.group import Group
|
|
|
from sentry.models.organization import Organization
|
|
|
from sentry.models.project import Project
|
|
|
from sentry.models.team import Team
|
|
|
-from sentry.search.events.constants import DURATION_UNITS, SIZE_UNITS, TIMEOUT_ERROR_MESSAGE
|
|
|
+from sentry.search.events.constants import DURATION_UNITS, SIZE_UNITS
|
|
|
from sentry.search.events.fields import get_function_alias
|
|
|
from sentry.search.events.types import SnubaParams
|
|
|
from sentry.snuba import (
|
|
@@ -206,68 +206,6 @@ class OrganizationEventsEndpointBase(OrganizationEndpoint):
|
|
|
)
|
|
|
return results
|
|
|
|
|
|
- @contextmanager
|
|
|
- def handle_query_errors(self) -> Generator[None, None, None]:
|
|
|
- try:
|
|
|
- yield
|
|
|
- except discover.InvalidSearchQuery as error:
|
|
|
- message = str(error)
|
|
|
- # Special case the project message since it has so many variants so tagging is messy otherwise
|
|
|
- if message.endswith("do not exist or are not actively selected."):
|
|
|
- sentry_sdk.set_tag(
|
|
|
- "query.error_reason", "Project in query does not exist or not selected"
|
|
|
- )
|
|
|
- else:
|
|
|
- sentry_sdk.set_tag("query.error_reason", message)
|
|
|
- raise ParseError(detail=message)
|
|
|
- except ArithmeticError as error:
|
|
|
- message = str(error)
|
|
|
- sentry_sdk.set_tag("query.error_reason", message)
|
|
|
- raise ParseError(detail=message)
|
|
|
- except snuba.QueryOutsideRetentionError as error:
|
|
|
- sentry_sdk.set_tag("query.error_reason", "QueryOutsideRetentionError")
|
|
|
- raise ParseError(detail=str(error))
|
|
|
- except snuba.QueryIllegalTypeOfArgument:
|
|
|
- message = "Invalid query. Argument to function is wrong type."
|
|
|
- sentry_sdk.set_tag("query.error_reason", message)
|
|
|
- raise ParseError(detail=message)
|
|
|
- except IncompatibleMetricsQuery as error:
|
|
|
- message = str(error)
|
|
|
- sentry_sdk.set_tag("query.error_reason", f"Metric Error: {message}")
|
|
|
- raise ParseError(detail=message)
|
|
|
- except snuba.SnubaError as error:
|
|
|
- message = "Internal error. Please try again."
|
|
|
- if isinstance(
|
|
|
- error,
|
|
|
- (
|
|
|
- snuba.RateLimitExceeded,
|
|
|
- snuba.QueryMemoryLimitExceeded,
|
|
|
- snuba.QueryExecutionTimeMaximum,
|
|
|
- snuba.QueryTooManySimultaneous,
|
|
|
- ),
|
|
|
- ):
|
|
|
- sentry_sdk.set_tag("query.error_reason", "Timeout")
|
|
|
- raise ParseError(detail=TIMEOUT_ERROR_MESSAGE)
|
|
|
- elif isinstance(error, (snuba.UnqualifiedQueryError)):
|
|
|
- sentry_sdk.set_tag("query.error_reason", str(error))
|
|
|
- raise ParseError(detail=str(error))
|
|
|
- elif isinstance(
|
|
|
- error,
|
|
|
- (
|
|
|
- snuba.DatasetSelectionError,
|
|
|
- snuba.QueryConnectionFailed,
|
|
|
- snuba.QueryExecutionError,
|
|
|
- snuba.QuerySizeExceeded,
|
|
|
- snuba.SchemaValidationError,
|
|
|
- snuba.QueryMissingColumn,
|
|
|
- ),
|
|
|
- ):
|
|
|
- sentry_sdk.capture_exception(error)
|
|
|
- message = "Internal error. Your query failed to run."
|
|
|
- else:
|
|
|
- sentry_sdk.capture_exception(error)
|
|
|
- raise APIException(detail=message)
|
|
|
-
|
|
|
|
|
|
class OrganizationEventsV2EndpointBase(OrganizationEventsEndpointBase):
|
|
|
owner = ApiOwner.PERFORMANCE
|
|
@@ -439,7 +377,7 @@ class OrganizationEventsV2EndpointBase(OrganizationEventsEndpointBase):
|
|
|
additional_query_column: Optional[str] = None,
|
|
|
dataset: Optional[Any] = None,
|
|
|
) -> Dict[str, Any]:
|
|
|
- with self.handle_query_errors():
|
|
|
+ with handle_query_errors():
|
|
|
with sentry_sdk.start_span(
|
|
|
op="discover.endpoint", description="base.stats_query_creation"
|
|
|
):
|