Skip to content
briefkastencloud

PostHog

Error tracking alerts, verified as Standard Webhooks.

Set it up

briefkasten source add posthog --project acme-shop
  1. In PostHog, open Error tracking → Configuration → Alerting, add a notification ("Issue created", "Issue reopened", "Issue resolved", …) and pick HTTP Webhook.
  2. Webhook URL: the source's hook URL. Method: POST. Signing secret: the secret source add printed (whsec_…), in the Standard Webhooks format.
  3. JSON Body:
{
  "event": "{event.event}",
  "issue": "{event.distinct_id}",
  "project": "{project.id}",
  "title": "{event.properties.name}",
  "status": "{event.properties.status}",
  "fingerprint": "{event.properties.fingerprint}"
}

Signature

PostHog signs in the Standard Webhooks format: webhook-signature: v1,<base64> is HMAC-SHA256 of <webhook-id>.<webhook-timestamp>.<body>, keyed with the base64-decoded secret. A webhook-timestamp more than five minutes from now is refused. PostHog's other format, X-Hub-Signature-256, signs no time and is not accepted.

Events

Every alert becomes one error event. Its body has action (the last part of PostHog's event: created, reopened, resolved, suppressed, spiking, …), project, issue, title, status, fingerprint, delivery (the webhook-id) and at. The target is <project id>.<issue id>. The samples below are the bodies PostHog posts.

$error_tracking_issue_createdA new error tracking issue was createdevent errortarget 12345.01936f3a-4b5c-7d8e-9f00-112233445566
{
  "event": "$error_tracking_issue_created",
  "issue": "01936f3a-4b5c-7d8e-9f00-112233445566",
  "project": 12345,
  "title": "TypeError: Cannot read properties of undefined (reading 'total')",
  "status": "active",
  "fingerprint": "c0ffee"
}
$error_tracking_issue_resolvedAn issue was resolvedevent errortarget 12345.01936f3a-4b5c-7d8e-9f00-112233445566
{
  "event": "$error_tracking_issue_resolved",
  "issue": "01936f3a-4b5c-7d8e-9f00-112233445566",
  "project": 12345,
  "title": "TypeError: Cannot read properties of undefined (reading 'total')",
  "status": "resolved",
  "fingerprint": "c0ffee"
}

Options

None.

In your app

import { posthog } from "@briefkasten/adapter-posthog";

const hooks = briefkasten({
  sources: { posthog: posthog({ secret: process.env.POSTHOG_WEBHOOK_SECRET }) },
});

hooks.on("posthog:error", async (event) => {
  console.log(event.body.action, event.body.title);
});