klaviyo-observability
'Set up observability for Klaviyo integrations with metrics, traces,
Allowed Tools
Provided by Plugin
klaviyo-pack
Claude Code skill pack for Klaviyo (24 skills)
Installation
This skill is included in the klaviyo-pack plugin:
/plugin install klaviyo-pack@claude-code-plugins-plus
Click to copy
Instructions
Klaviyo Observability
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. The pattern centers on one instrumentation wrapper that every Klaviyo call routes through, so metrics, traces, and logs stay consistent across profiles, events, and webhooks.
Prerequisites
- Prometheus or compatible metrics backend
- OpenTelemetry SDK installed (optional)
- Grafana or similar dashboarding tool (optional)
klaviyo-apiSDK installed
Key Metrics to Track
| Metric | Type | Why It Matters |
|---|---|---|
klaviyoapirequests_total |
Counter | Track total API volume by endpoint |
klaviyoapiduration_seconds |
Histogram | Detect latency degradation |
klaviyoapierrors_total |
Counter | 4xx/5xx error rates |
klaviyoratelimit_remaining |
Gauge | Predict when you'll hit 429s |
klaviyoprofilessynced_total |
Counter | Profile sync throughput |
klaviyoeventstracked_total |
Counter | Event tracking volume |
klaviyowebhookreceived_total |
Counter | Inbound webhook volume |
Instructions
Read any existing Klaviyo client code first, then build the layers in order. Each
step writes one module; steps 5–6 wire the alerting and scrape endpoint.
- Instrumented API wrapper — write
src/klaviyo/instrumented-client.tswith the
Prometheus counters, histogram, and gauge, exposed through a single
instrumentedCall() helper.
- Route every call through
instrumentedCall(endpoint, method, () => ...)in
the service layer so profile/event/webhook traffic is all counted.
- OpenTelemetry tracing (optional) — add
tracedKlaviyoCall()to emit spans
with Klaviyo operation + error attributes.
- Structured logging — add a
pinologger with an email-redacting serializer. - Alert rules — drop
prometheus/klaviyo-alerts.ymlin place for error-rate,
429, latency, down, and low-headroom alerts.
- Metrics endpoint — expose
GET /metricsfrom the shared registry.
The wrapper is the load-bearing piece — the skeleton is:
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' });
return result;
} catch (error: any) {
apiErrors.inc({ endpoint, status_code: error.status || 'unknown', error_code: error.body?.errors?.[0]?.code || 'unknown' });
throw error;
} finally {
timer();
}
}
Full source for all six steps — counters, tracing, logging, and the metrics
endpoint — is in references/instrumentation.md.
Alert rules and Grafana panels are in references/alerting.md.
Output
Applying this skill produces:
src/klaviyo/instrumented-client.ts— Prometheus registry +instrumentedCall()wrappersrc/klaviyo/tracing.ts— OpenTelemetrytracedKlaviyoCall()(optional)src/klaviyo/logger.ts—pinologger with PII-redacting serializersprometheus/klaviyo-alerts.yml— five alert rules (error rate, 429s, latency, down, low headroom)GET /metricsroute exposing the registry in Prometheus text format
Once wired, curl localhost:PORT/metrics returns the klaviyo_* series, and the
Grafana panels in references/alerting.md render request
rate, error rate, P95 latency, and rate-limit headroom.
Error Handling
| Issue | Cause | Solution |
|---|---|---|
| Missing metrics | No instrumentation wrapper | Wrap all API calls with instrumentedCall() |
| High cardinality | Too many label values | Use endpoint groups, not full URLs |
| Alert storms | Thresholds too low | Tune alert rules to your traffic pattern |
| PII in logs | Email in log messages | Use serializer to redact emails |
Examples
Instrument a profile upsert — wrap the SDK call so it counts toward
klaviyoapirequests_total and records latency:
const profile = await instrumentedCall('profiles', 'POST', () =>
profilesApi.createOrUpdateProfile({
data: { type: 'profile', attributes: { email: user.email, firstName: user.name } },
})
);
Alert on rate-limit pressure — fire before you start getting 429s:
- alert: KlaviyoRateLimitLow
expr: klaviyo_rate_limit_remaining < 20
for: 30s
labels: { severity: warning }
annotations:
summary: "Klaviyo rate limit headroom below 20 requests"
More worked examples — event tracking, tracing, structured logging, and the full
alert group — are in references/instrumentation.md
Resources
- references/instrumentation.md — full metrics, tracing, logging, and metrics-endpoint source
- references/alerting.md — Prometheus alert rules and Grafana dashboard panels
- Prometheus Best Practices
- OpenTelemetry Node.js
- pino Logger
Next Steps
For incident response, see the klaviyo-incident-runbook skill, which pairs these
metrics and alerts with triage and escalation procedures.