feat(metrics): implement Prometheus metrics collection & /metrics endpoint#342
Merged
OthmanImam merged 1 commit intoJun 23, 2026
Conversation
…ndpoint - Add MetricsModule with global HTTP interceptor for request tracking - Expose /metrics endpoint (GET, public, Prometheus text format) - Define 20+ custom metrics: HTTP, auth, DB, job queue, business - Add auth-specific counters: attempts, success, failures - Wire MetricsModule into AppModule - Add Grafana dashboard template (docs/dashboards/stellaiverse-backend.json) - Add metrics documentation (docs/METRICS.md) - 10 unit/integration tests for interceptor and controller Closes StellAIverse#311
8 tasks
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 full Prometheus metrics integration for the StellAIverse backend, satisfying all acceptance criteria from issue #311.
Implementation Details
MetricsModule (
src/metrics/)MetricsController— exposesGET /metrics(public, no auth required) returning Prometheus text formatMetricsInterceptor— global NestJS interceptor that automatically tracks every HTTP request (latency, total count, in-progress, errors)MetricsModule— registers the controller and wires the interceptor asAPP_INTERCEPTORinAppModuleCustom Metrics (
src/config/metrics.ts)20+ custom metrics implemented with the
stellaiverse_prefix:http_request_duration_seconds(histogram),http_requests_total(counter),http_requests_in_progress(gauge),http_errors_total(counter)auth_attempts_total,auth_success_total,auth_failures_total,user_signups_total,active_usersdatabase_query_duration_seconds(histogram),active_connections(gauge)job_duration_seconds,job_success_total,job_failure_total,queue_lengtherrors_totalNode.js default metrics (CPU, memory, event loop, GC, file descriptors, etc.) are also collected via
collectDefaultMetrics.Grafana Dashboard
Pre-built dashboard template at
docs/dashboards/stellaiverse-backend.json— importable directly into Grafana. Panels cover HTTP traffic, latency percentiles (p50/p95), error rate, auth rate, DB query latency, Node.js heap, and event loop lag.Documentation
docs/METRICS.md— complete reference for all metrics, adding new metrics, Prometheus scrape config, and Grafana import instructions.Validation Results
Build: ✅
npm run build— webpack compiled successfullyNew tests (10 passing):
src/metrics/metrics.interceptor.spec.ts— 4 tests (success path, error path, default 500, no-request passthrough)src/metrics/metrics.controller.spec.ts— 6 tests (endpoint format, default metrics, HTTP metrics, auth metrics, DB metrics, schema prefix validation)Pre-existing failures (unrelated, confirmed on main before this branch):
10 test suites fail with
Cannot find module 'src/...'— a module path resolution issue in Jest config that predates this PR.Closes
Closes #311