diff --git a/posthog/api/monitoring.py b/posthog/api/monitoring.py index be850f2c355e3..2f94e58c8a1cb 100644 --- a/posthog/api/monitoring.py +++ b/posthog/api/monitoring.py @@ -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: """ @@ -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 diff --git a/posthog/clickhouse/client/execute.py b/posthog/clickhouse/client/execute.py index d1423baa09a20..55b9862eb43a3 100644 --- a/posthog/clickhouse/client/execute.py +++ b/posthog/clickhouse/client/execute.py @@ -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( @@ -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: