⚠️ This is a backend issue — work is done inside the backend/ folder
Description
backend/src/modules/observability/ contains metrics.service.ts, performance-monitoring.service.ts, http-metrics.interceptor.ts, and tracing.service.ts, but none of these are wired to an actual /metrics endpoint. The ObservabilityController exists but exposes no Prometheus-compatible scrape endpoint. Monitoring infrastructure cannot collect metrics without this.
Current State
metrics.service.ts — collects internal metrics but exposes no HTTP endpoint
http-metrics.interceptor.ts — records request durations but data goes nowhere
observability.controller.ts — exists but has no /metrics route
- No
prom-client or @willsoto/nestjs-prometheus integration
What Needs to Be Built
1. Install and Configure prom-client
npm install prom-client @willsoto/nestjs-prometheus
- Register
PrometheusModule in ObservabilityModule
- Expose
GET /metrics (Prometheus text format)
- Secure endpoint: only accessible from internal network or with
METRICS_TOKEN header
2. HTTP Request Metrics (via existing interceptor)
Update HttpMetricsInterceptor to record:
http_requests_total — counter by method, route, status code
http_request_duration_seconds — histogram by method and route
3. Custom Business Metrics
Add to MetricsService:
petchain_pets_total — gauge: total registered pets
petchain_medical_records_total — gauge: total medical records
petchain_blockchain_syncs_total — counter: successful/failed Stellar syncs
petchain_active_sessions_total — gauge: active user sessions
4. Apply Interceptor Globally
- Register
HttpMetricsInterceptor as a global interceptor in AppModule
5. Health Check Endpoint
- Return
{ status: 'ok', uptime, db: 'connected' | 'error', redis: 'connected' | 'error' }
- Use
@nestjs/terminus for DB and Redis health indicators
Acceptance Criteria
Files to Modify / Create
backend/src/modules/observability/observability.module.ts
backend/src/modules/observability/observability.controller.ts
backend/src/modules/observability/metrics.service.ts
backend/src/modules/observability/http-metrics.interceptor.ts
backend/src/app.module.ts (register interceptor globally)
Priority
Medium — required for production monitoring and alerting
Estimated Effort
2 days
backend/folderDescription
backend/src/modules/observability/containsmetrics.service.ts,performance-monitoring.service.ts,http-metrics.interceptor.ts, andtracing.service.ts, but none of these are wired to an actual/metricsendpoint. TheObservabilityControllerexists but exposes no Prometheus-compatible scrape endpoint. Monitoring infrastructure cannot collect metrics without this.Current State
metrics.service.ts— collects internal metrics but exposes no HTTP endpointhttp-metrics.interceptor.ts— records request durations but data goes nowhereobservability.controller.ts— exists but has no/metricsrouteprom-clientor@willsoto/nestjs-prometheusintegrationWhat Needs to Be Built
1. Install and Configure prom-client
PrometheusModuleinObservabilityModuleGET /metrics(Prometheus text format)METRICS_TOKENheader2. HTTP Request Metrics (via existing interceptor)
Update
HttpMetricsInterceptorto record:http_requests_total— counter by method, route, status codehttp_request_duration_seconds— histogram by method and route3. Custom Business Metrics
Add to
MetricsService:petchain_pets_total— gauge: total registered petspetchain_medical_records_total— gauge: total medical recordspetchain_blockchain_syncs_total— counter: successful/failed Stellar syncspetchain_active_sessions_total— gauge: active user sessions4. Apply Interceptor Globally
HttpMetricsInterceptoras a global interceptor inAppModule5. Health Check Endpoint
{ status: 'ok', uptime, db: 'connected' | 'error', redis: 'connected' | 'error' }@nestjs/terminusfor DB and Redis health indicatorsAcceptance Criteria
GET /metricsreturns valid Prometheus text formatGET /healthreturns DB and Redis statusHttpMetricsInterceptoris applied globallyFiles to Modify / Create
backend/src/modules/observability/observability.module.tsbackend/src/modules/observability/observability.controller.tsbackend/src/modules/observability/metrics.service.tsbackend/src/modules/observability/http-metrics.interceptor.tsbackend/src/app.module.ts(register interceptor globally)Priority
Medium — required for production monitoring and alerting
Estimated Effort
2 days