Monitoring and Observability
1. Setting Up Application Monitoring
| Tool | Detail |
|---|---|
| Datadog APM | Auto-instrumentation |
| New Relic | Node agent |
| Grafana Cloud | Prom + Tempo + Loki |
2. Implementing Health Checks
app.get("/health/db", async (_, res) => {
try { await prisma.$queryRaw`SELECT 1`; res.json({ ok: true }); }
catch { res.status(503).json({ ok: false }); }
});
| Probe | Detail |
|---|---|
| Liveness | Process responsive |
| Readiness | DB reachable |
| Cadence | 5-30s in k8s |
3. Tracking Query Metrics
const prom = await prisma.$metrics.prometheus();
app.get("/metrics", (_, res) => res.type("text/plain").send(prom));
| Metric | Detail |
|---|---|
| prisma_client_queries_total | Counter |
| prisma_client_queries_duration_histogram_ms | Histogram |
| prisma_pool_connections_open | Gauge |
4. Using OpenTelemetry
import { PrismaInstrumentation } from "@prisma/instrumentation";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
registerInstrumentations({ instrumentations: [new PrismaInstrumentation()] });
| Aspect | Detail |
|---|---|
| Spans | One per query + engine work |
| Attributes | db.system, db.statement, model |
5. Implementing Alerting
| Signal | Alert |
|---|---|
| Error rate | > 1% sustained |
| p95 latency | > SLO threshold |
| Pool saturation | > 80% sustained |
| Migration failure | Page on-call |
6. Monitoring Database Performance
| Metric | Detail |
|---|---|
| CPU/IO | RDS Performance Insights / pganalyze |
| Slow queries | pg_stat_statements |
| Replication lag | Replica health |
7. Tracking Error Rates
| Tool | Detail |
|---|---|
| Sentry | Capture w/ stack + breadcrumbs |
| Bugsnag/Rollbar | Alternatives |
| Tagging | Add prisma.code tag |
8. Implementing Distributed Tracing
| Backend | Detail |
|---|---|
| Jaeger | OSS |
| Tempo | Grafana stack |
| Honeycomb | Wide-event SaaS |
9. Using Performance Dashboards
| Panel | Detail |
|---|---|
| QPS | Counter rate |
| Latency histogram | p50/p95/p99 |
| Pool gauges | open / idle / waiting |
| Error breakdown | By Prisma code |
10. Implementing Audit Trails
Combine extension-based audit logging (50.8) with append-only storage, signed events, and correlation IDs from OpenTelemetry to produce a complete, tamper-evident trail across services. Forward audit events to a separate sink (e.g., S3 with Object Lock or a dedicated audit DB) for compliance retention.
| Element | Detail |
|---|---|
| Who | Actor user ID / API key |
| What | Model + operation + diff |
| When | Server timestamp (UTC) |
| Where | Trace ID, request ID |
| Retention | Per compliance (e.g., 7 years) |