Guides / Monitoring

Monitor Webhook Delivery Failures in Real Time

4 min read·Monitoring

The Problem

When you send webhooks to your customers' endpoints and they fail (5xx, timeout, network error), you might not know for hours — until a customer emails support. Logging delivery failures to LogIt gives you real-time visibility.

Step 1: Log Delivery Failures

ts
// lib/webhook-dispatcher.ts
import { logit } from "@/lib/logit";

export async function dispatchWebhook(customerId: string, endpointUrl: string, eventType: string, payload: object) {
  let statusCode: number | null = null;

  try {
    const res = await fetch(endpointUrl, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(payload),
      signal: AbortSignal.timeout(10_000),
    });

    statusCode = res.status;
    if (!res.ok) throw new Error(`HTTP ${res.status}`);
  } catch (err) {
    const error = err instanceof Error ? err.message : String(err);

    await logit.now("webhook-failures", {
      event: "Webhook delivery failed",
      description: `${eventType} to ${new URL(endpointUrl).hostname}${error}`,
      icon: "📡",
      notify: false,
      tags: {
        customerId,
        eventType,
        statusCode: statusCode?.toString() ?? "timeout",
      },
      metadata: { customerId, endpointUrl, eventType, statusCode, error },
    });

    throw err;  // re-throw so your retry queue picks it up
  }
}

Step 2: Smart Action for Failure Spikes

FieldValue
NameWebhook failure spike
Channelwebhook-failures
Event nameWebhook delivery failed
Threshold10
Window15 minutes
Cooldown30 minutes
ActionPush notification

Step 3: Per-Customer Failure Tracking

Filter by customerId tag in the LogIt dashboard to see which customer's endpoint is failing — before they contact you.

Tips

  • Log statusCode in tags so you can filter by HTTP 500 vs. timeout vs. DNS failure.
  • Log successful deliveries to a webhooks channel (with notify: false) for a complete delivery timeline.
  • A per-customer Smart Action can detect when a specific customer's endpoint consistently fails.

Try LogIt free

7-day trial. No credit card required.

Start free