Skip to content

Commit

Permalink
chore(replays): Capture rate-limit exceptions (#76611)
Browse files Browse the repository at this point in the history
Force the capture of rate limit exceptions and explicitly tag them with
replay metadata.

---------

Co-authored-by: Andrew Liu <159852527+aliu39@users.noreply.github.com>
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
  • Loading branch information
3 people committed Aug 27, 2024
1 parent c24c702 commit 38fd19a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/sentry/replays/usecases/query/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from datetime import datetime, timedelta
from typing import Any, Literal, cast

import sentry_sdk
from rest_framework.exceptions import ParseError
from snuba_sdk import (
And,
Expand All @@ -41,7 +42,7 @@
from sentry.replays.lib.new_query.errors import CouldNotParseValue, OperatorNotSupported
from sentry.replays.lib.new_query.fields import ColumnField, ExpressionField, FieldProtocol
from sentry.replays.usecases.query.fields import ComputedField, TagField
from sentry.utils.snuba import raw_snql_query
from sentry.utils.snuba import RateLimitExceeded, raw_snql_query

VIEWED_BY_ME_KEY_ALIASES = ["viewed_by_me", "seen_by_me"]
NULL_VIEWED_BY_ID_VALUE = 0 # default value in clickhouse
Expand Down Expand Up @@ -450,15 +451,22 @@ def _select_from_fields() -> list[Column | Function]:


def execute_query(query: Query, tenant_id: dict[str, int], referrer: str) -> Mapping[str, Any]:
return raw_snql_query(
Request(
dataset="replays",
app_id="replay-backend-web",
query=query,
tenant_ids=tenant_id,
),
referrer,
)
try:
return raw_snql_query(
Request(
dataset="replays",
app_id="replay-backend-web",
query=query,
tenant_ids=tenant_id,
),
referrer,
)
except RateLimitExceeded as exc:
sentry_sdk.set_tag("replay-rate-limit-exceeded", True)
sentry_sdk.set_tag("org_id", tenant_id.get("organization_id"))
sentry_sdk.set_extra("referrer", referrer)
sentry_sdk.capture_exception(exc)
raise


def handle_ordering(config: dict[str, Expression], sort: str) -> list[OrderBy]:
Expand Down

0 comments on commit 38fd19a

Please sign in to comment.