Repository navigation
feat(metrics): comprehensive Prometheus metrics interceptor for API latency and error tracking - #470
Merged
Cjay-Cyber-2 merged 1 commit intoOct 22, 2026
Conversation
…atency and error tracking - Record each HTTP request exactly once via the global MetricsInterceptor using rxjs finalize, so the duration histogram and status counter observe the final outcome (success or error) of every request. - Remove the redundant RequestMetricsMiddleware instrumentation path to prevent double counting of http_requests_total / http_request_duration_seconds. - Keep the /metrics scrape endpoint (Prometheus text format), route normalization, worker and stream metrics intact. Closes ASTROIDX556#421
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements comprehensive Prometheus metrics instrumentation for the Astroid API, closing the observability gap for API latency, error rates, and throughput.
What this PR does
MetricsInterceptor(src/common/interceptors/metrics.interceptor.ts) is the single authoritative instrumentation path for HTTP metrics:http_request_duration_secondshistogram (seconds) permethod/route/status_code.http_requests_totalcounter with low-cardinality labels (route paths are normalized, e.g./api/users/:id).activeRequests) and exposesgetActiveRequestCount()for load monitoring./metricsscrape endpoint to prevent self-instrumentation.finalizeso each request is recorded exactly once, on both success and error, using the final response status code./metricsendpoint (src/modules/metrics/metrics.controller.ts+metrics.service.ts) exposes the Prometheus text exposition format (text/plain; version=0.0.4) from theprom-clientregistry, with IP-restricted access (METRICS_ALLOWED_IPS) and exemption from throttle/audit/rate-limit policies.RequestMetricsMiddlewareinstrumentation path from the global wiring so the globalMetricsInterceptoris the single source of HTTP request metrics (prevents double counting of the counter/histogram).Acceptance criteria
MetricsInterceptorcreated insrc/common/interceptors/metrics.interceptor.ts./metricsendpoint returning Prometheus-formatted text metrics.Testing & validation
npm run test— full unit suite passes (181 test files / 1,893 tests).npm run typecheck— clean.npm run lint— clean.npm run start:devandcurl -H "Authorization: ..." http://localhost:<port>/metrics(scrape path is global-prefix excluded, i.e./metrics).Related issues
Closes #421
Closes #416