All checks were successful
Deploy / deploy (push) Successful in 1m44s
- Add phaseflow_build_info metric with version and commit labels - Inject GIT_COMMIT env var at build time via next.config.ts - Add logging to all Garmin fetch functions (HRV, body battery, intensity) - Log API response status codes, actual data values, and errors This enables verifying which build is deployed and diagnosing silent failures where Garmin API returns errors but sync reports success. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
// ABOUTME: Prometheus metrics collection module for production monitoring.
|
|
// ABOUTME: Exposes counters, gauges, and histograms for Garmin sync, email, and decision engine.
|
|
|
|
import * as promClient from "prom-client";
|
|
|
|
// Create a new registry for our application metrics
|
|
export const metricsRegistry = new promClient.Registry();
|
|
|
|
// Collect default Node.js metrics (heap, event loop, etc.)
|
|
promClient.collectDefaultMetrics({ register: metricsRegistry });
|
|
|
|
// Custom metric: Garmin sync operations counter
|
|
export const garminSyncTotal = new promClient.Counter({
|
|
name: "phaseflow_garmin_sync_total",
|
|
help: "Total number of Garmin sync operations",
|
|
labelNames: ["status"] as const,
|
|
registers: [metricsRegistry],
|
|
});
|
|
|
|
// Custom metric: Garmin sync duration histogram
|
|
export const garminSyncDuration = new promClient.Histogram({
|
|
name: "phaseflow_garmin_sync_duration_seconds",
|
|
help: "Duration of Garmin sync operations in seconds",
|
|
buckets: [0.1, 0.5, 1, 2, 5, 10],
|
|
registers: [metricsRegistry],
|
|
});
|
|
|
|
// Custom metric: Email sent counter
|
|
export const emailSentTotal = new promClient.Counter({
|
|
name: "phaseflow_email_sent_total",
|
|
help: "Total number of emails sent",
|
|
labelNames: ["type"] as const,
|
|
registers: [metricsRegistry],
|
|
});
|
|
|
|
// Custom metric: Decision engine calls counter
|
|
export const decisionEngineCallsTotal = new promClient.Counter({
|
|
name: "phaseflow_decision_engine_calls_total",
|
|
help: "Total number of decision engine calls",
|
|
labelNames: ["decision"] as const,
|
|
registers: [metricsRegistry],
|
|
});
|
|
|
|
// Custom metric: Active users gauge
|
|
export const activeUsersGauge = new promClient.Gauge({
|
|
name: "phaseflow_active_users",
|
|
help: "Number of users with activity in the last 24 hours",
|
|
registers: [metricsRegistry],
|
|
});
|
|
|
|
// Build info metric: exposes version and git commit for deployment verification
|
|
const buildInfo = new promClient.Gauge({
|
|
name: "phaseflow_build_info",
|
|
help: "Build information with version and git commit",
|
|
labelNames: ["version", "commit"] as const,
|
|
registers: [metricsRegistry],
|
|
});
|
|
|
|
// Set build info at module load (value is always 1, labels contain the info)
|
|
buildInfo
|
|
.labels({
|
|
version: process.env.npm_package_version || "unknown",
|
|
commit: process.env.GIT_COMMIT || "unknown",
|
|
})
|
|
.set(1);
|