---
name: klaviyo-observability
description: '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".'
allowed-tools: Read, Write, Edit
version: 1.7.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - klaviyo
  - email-marketing
  - cdp
compatibility: Designed for Claude Code
title: klaviyo-observability
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/klaviyo-observability
last_updated: 2026-10-07T06:06:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/alerting.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-observability/references/alerting.md), [references/instrumentation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-observability/references/instrumentation.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/klaviyo-observability`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/klaviyo-observability`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/klaviyo-observability) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/klaviyo-observability`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/klaviyo-observability --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/klaviyo-observability --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# 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-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

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.

1. **Instrumented API wrapper** — write `src/klaviyo/instrumented-client.ts` with the
   Prometheus counters, histogram, and gauge, exposed through a single
   `instrumentedCall()` helper.
2. **Route every call** through `instrumentedCall(endpoint, method, () => ...)` in
   the service layer so profile/event/webhook traffic is all counted.
3. **OpenTelemetry tracing** (optional) — add `tracedKlaviyoCall()` to emit spans
   with Klaviyo operation + error attributes.
4. **Structured logging** — add a `pino` logger with an email-redacting serializer.
5. **Alert rules** — drop `prometheus/klaviyo-alerts.yml` in place for error-rate,
   429, latency, down, and low-headroom alerts.
6. **Metrics endpoint** — expose `GET /metrics` from the shared registry.

The wrapper is the load-bearing piece — the skeleton is:

```typescript
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](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-observability/references/instrumentation.md).
Alert rules and Grafana panels are in [references/alerting.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-observability/references/alerting.md).

## Output

Applying this skill produces:

- `src/klaviyo/instrumented-client.ts` — Prometheus registry + `instrumentedCall()` wrapper
- `src/klaviyo/tracing.ts` — OpenTelemetry `tracedKlaviyoCall()` (optional)
- `src/klaviyo/logger.ts` — `pino` logger with PII-redacting serializers
- `prometheus/klaviyo-alerts.yml` — five alert rules (error rate, 429s, latency, down, low headroom)
- `GET /metrics` route 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](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-observability/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
`klaviyo_api_requests_total` and records latency:

```typescript
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:

```yaml
- 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](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-observability/references/instrumentation.md)
and [references/alerting.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-observability/references/alerting.md).

## Resources

- [references/instrumentation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-observability/references/instrumentation.md) — full metrics, tracing, logging, and metrics-endpoint source
- [references/alerting.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-observability/references/alerting.md) — Prometheus alert rules and Grafana dashboard panels
- [Prometheus Best Practices](https://prometheus.io/docs/practices/naming/)
- [OpenTelemetry Node.js](https://opentelemetry.io/docs/languages/js/)
- [pino Logger](https://github.com/pinojs/pino)

## Next Steps

For incident response, see the `klaviyo-incident-runbook` skill, which pairs these
metrics and alerts with triage and escalation procedures.
