feat: add end-to-end observability (metrics, health, mobile RUM, dashboards, alerts)
- Backend: OTel metrics via OTLP -> Alloy -> Prometheus (OTEL_METRICS_EXPORTER=otlp) - New business metrics (src/metrics.js): searches, CIMA latency/errors, cache hits/misses, logins, rate-limits, pharmacy writes/links, push sent/failed, DB + Redis timings/errors, HTTP req count/duration, heartbeat - Backend health endpoints /healthz and /readyz - Mobile (Expo): Grafana Faro RUM via @grafana/faro-react-native - redis/postgres exporters in docker-compose + Prometheus scrape jobs - Grafana dashboards (backend, datastores, mobile RUM, overview) - Prometheus alert rules (farmafinder_*) -> existing Alertmanager (Telegram) - Design/spec saved to docs/superpowers/specs/
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { createClient } from 'redis';
|
||||
import * as appMetrics from './src/metrics.js';
|
||||
|
||||
// Create Redis client
|
||||
const redisClient = createClient({
|
||||
@@ -11,6 +12,7 @@ const redisClient = createClient({
|
||||
|
||||
// Error handler
|
||||
redisClient.on('error', (err) => {
|
||||
appMetrics.redisErrorsTotal.add(1);
|
||||
console.error('Redis Client Error:', err);
|
||||
});
|
||||
|
||||
@@ -19,6 +21,27 @@ redisClient.on('connect', () => {
|
||||
console.log('✅ Connected to Redis');
|
||||
});
|
||||
|
||||
// Instrument get/setEx with command duration (used by the CIMA cache path).
|
||||
const origGet = redisClient.get.bind(redisClient);
|
||||
redisClient.get = async (...args) => {
|
||||
const start = performance.now();
|
||||
try {
|
||||
return await origGet(...args);
|
||||
} finally {
|
||||
appMetrics.redisCmdDuration.record(performance.now() - start);
|
||||
}
|
||||
};
|
||||
|
||||
const origSetEx = redisClient.setEx.bind(redisClient);
|
||||
redisClient.setEx = async (...args) => {
|
||||
const start = performance.now();
|
||||
try {
|
||||
return await origSetEx(...args);
|
||||
} finally {
|
||||
appMetrics.redisCmdDuration.record(performance.now() - start);
|
||||
}
|
||||
};
|
||||
|
||||
// Connect to Redis
|
||||
await redisClient.connect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user