Set up observability for Klaviyo integrations with metrics, traces, and alerts.
Use when implementing monitoring for Klaviyo API operations, setting up dashboards,
or configuring alerting for Klaviyo integration health.
Trigger with phrases like "klaviyo monitoring", "klaviyo metrics",
"klaviyo observability", "monitor klaviyo", "klaviyo alerts", "klaviyo tracing".
jeremylongshore1,965 星標2026年3月22日
職業
分類
實驗室工具
技能內容
Overview
Comprehensive observability for Klaviyo integrations: Prometheus metrics for API call tracking, OpenTelemetry tracing, structured logging, and alerting rules tuned to Klaviyo's rate limits and error patterns.
Prerequisites
Prometheus or compatible metrics backend
OpenTelemetry SDK installed (optional)
Grafana or similar dashboarding tool (optional)
klaviyo-api SDK installed
Key Metrics to Track
Metric
Type
Why It Matters
klaviyo_api_requests_total
Counter
Track total API volume by endpoint
klaviyo_api_duration_seconds
Histogram
Detect latency degradation
klaviyo_api_errors_total
Counter
4xx/5xx error rates
相關技能
klaviyo_rate_limit_remaining
Gauge
Predict when you'll hit 429s
klaviyo_profiles_synced_total
Counter
Profile sync throughput
klaviyo_events_tracked_total
Counter
Event tracking volume
klaviyo_webhook_received_total
Counter
Inbound webhook volume
Instructions
Step 1: Instrumented API Wrapper
// src/klaviyo/instrumented-client.ts
import { Counter, Histogram, Gauge, Registry } from 'prom-client';
const registry = new Registry();
const apiRequests = new Counter({
name: 'klaviyo_api_requests_total',
help: 'Total Klaviyo API requests',
labelNames: ['method', 'endpoint', 'status'],
registers: [registry],
});
const apiDuration = new Histogram({
name: 'klaviyo_api_duration_seconds',
help: 'Klaviyo API request duration in seconds',
labelNames: ['method', 'endpoint'],
buckets: [0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
registers: [registry],
});
const apiErrors = new Counter({
name: 'klaviyo_api_errors_total',
help: 'Klaviyo API errors by status code',
labelNames: ['endpoint', 'status_code', 'error_code'],
registers: [registry],
});
const rateLimitRemaining = new Gauge({
name: 'klaviyo_rate_limit_remaining',
help: 'Remaining requests in current rate limit window',
registers: [registry],
});
export async function instrumentedCall<T>(
endpoint: string,
method: string,
operation: () => Promise<T>
): Promise<T> {
const timer = apiDuration.startTimer({ method, endpoint });
try {
const result = await operation();
apiRequests.inc({ method, endpoint, status: 'success' });
// Extract rate limit headers if available
const headers = (result as any)?.headers;
if (headers?.['ratelimit-remaining']) {
rateLimitRemaining.set(parseInt(headers['ratelimit-remaining']));
}
return result;
} catch (error: any) {
const statusCode = error.status || 'unknown';
const errorCode = error.body?.errors?.[0]?.code || 'unknown';
apiRequests.inc({ method, endpoint, status: 'error' });
apiErrors.inc({ endpoint, status_code: statusCode, error_code: errorCode });
throw error;
} finally {
timer();
}
}
export { registry };