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:
@@ -6,3 +6,8 @@ EXPO_PUBLIC_API_URL=http://localhost:3001/api
|
||||
|
||||
# For production builds, update this to:
|
||||
# EXPO_PUBLIC_API_URL=https://api.yourdomain.com/api
|
||||
|
||||
# Grafana Alloy OTLP/HTTP endpoint for Faro RUM (must be reachable from the
|
||||
# device — use a LAN IP / public hostname, NOT localhost).
|
||||
# Open router :4318 → srv84-macos:4318, or proxy /faro via Nginx Proxy Manager.
|
||||
EXPO_PUBLIC_FARO_URL=http://grafana.hacecalor.net:4318
|
||||
|
||||
@@ -8,6 +8,10 @@ import { SafeAreaProvider } from 'react-native-safe-area-context';
|
||||
import { useAuthStore } from '../store/authStore';
|
||||
import { registerForPushNotifications, addNotificationListener, addNotificationResponseListener } from '../services/notifications';
|
||||
import { ThemeProvider, useThemeContext } from '../components/ThemeProvider';
|
||||
import { initFaro } from '../services/faro';
|
||||
|
||||
// Boot Faro RUM once, as early as possible.
|
||||
initFaro();
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"expo-constants": "~57.0.3",
|
||||
"expo-dev-client": "~57.0.5",
|
||||
"expo-device": "~7.0.2",
|
||||
"@grafana/faro-react-native": "^1.2.1",
|
||||
"expo-image-picker": "~57.0.2",
|
||||
"expo-linking": "~57.0.1",
|
||||
"expo-local-authentication": "~57.0.0",
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { initializeFaro } from '@grafana/faro-react-native';
|
||||
|
||||
let initialized = false;
|
||||
|
||||
/**
|
||||
* Initializes Grafana Faro RUM for the React Native app.
|
||||
*
|
||||
* Telemetry (crashes, JS errors, console, app-start, memory/ANR vitals,
|
||||
* session + screen tracking) is sent OTLP/HTTP to the Alloy collector.
|
||||
*
|
||||
* NOTE: `@grafana/faro-react-native` ships a native module, so it requires a
|
||||
* custom dev build / EAS build (not Expo Go). Initialization is wrapped in a
|
||||
* try/catch so a collector outage never crashes the app.
|
||||
*/
|
||||
export function initFaro(): void {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
|
||||
try {
|
||||
const url =
|
||||
process.env.EXPO_PUBLIC_FARO_URL || 'http://grafana.hacecalor.net:4318';
|
||||
|
||||
initializeFaro({
|
||||
app: {
|
||||
name: 'farmafinder-mobile',
|
||||
version: '1.0.0',
|
||||
environment: __DEV__ ? 'development' : 'production',
|
||||
},
|
||||
url,
|
||||
sessionTracking: { enabled: true },
|
||||
// Crash/JS error/console capture are on by default.
|
||||
});
|
||||
} catch (err) {
|
||||
console.warn('[faro] initialization failed:', err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user