Skip to content

Commit

Permalink
feat: monitoring for endpoint errors (#24617)
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhpillai authored Aug 28, 2024
1 parent 7a0bd63 commit 520bd99
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 11 additions & 2 deletions posthog/api/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class Feature(StrEnum):
labelnames=["endpoint", "method"],
)

API_REQUESTS_ERROR_COUNTER = Counter(
"api_requests_error",
"Number of errored API requests",
labelnames=["endpoint", "method"],
)


def monitor(*, feature: Feature | None, endpoint: str, method: str) -> Callable:
"""
Expand All @@ -30,8 +36,11 @@ def wrapper(*args, **kwargs):

if feature:
set_tag("feature", feature.value)

return func(*args, **kwargs)
try:
return func(*args, **kwargs)
except Exception:
API_REQUESTS_ERROR_COUNTER.labels(endpoint=endpoint, method=method).inc()
raise

return wrapper

Expand Down
6 changes: 4 additions & 2 deletions posthog/clickhouse/client/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
QUERY_ERROR_COUNTER = Counter(
"clickhouse_query_failure",
"Query execution failure signal is dispatched when a query fails.",
labelnames=["exception_type"],
labelnames=["exception_type", "query_type"],
)

QUERY_EXECUTION_TIME_GAUGE = Gauge(
Expand Down Expand Up @@ -146,7 +146,9 @@ def sync_execute(
)
except Exception as e:
err = wrap_query_error(e)
QUERY_ERROR_COUNTER.labels(exception_type=type(err).__name__).inc()
exception_type = type(err).__name__
set_tag("clickhouse_exception_type", exception_type)
QUERY_ERROR_COUNTER.labels(exception_type=exception_type, query_type=query_type).inc()

raise err from e
finally:
Expand Down

0 comments on commit 520bd99

Please sign in to comment.