# Alert on error spikes

A good alert fires when something is actually wrong and stays quiet otherwise. This guide builds an alert for a spike of errors, tuned against your real baseline.

## 1. Find your baseline

Open the source's **Logs** tab and search for the lines you care about, over the last 24 hours:

```
level:error
```

Look at the volume chart. If you normally see a handful of errors per hour, a spike of 10 in five minutes is meaningful. If you see hundreds an hour, your threshold needs to be higher, or your query narrower:

```
level:error status>=500
```

![Searching level:error over the last 24 hours: a couple of errors an hour, and one burst of 26 two hours ago](https://tailcove.dev/images/guides/alert-on-error-spikes/baseline.mp4 "A day of a demo shop: two or three errors an hour is normal, so the burst near the right is what an alert should catch.")

## 2. Create the alert

Open the source's **Alerts** tab and create an alert:

| Field              | Example                   | Why                                             |
| ------------------ | ------------------------- | ----------------------------------------------- |
| Name               | High 5xx rate             | Shown in every notification                     |
| Query              | `level:error status>=500` | Same language as search                         |
| Threshold count    | 10                        | Above your normal baseline                      |
| Window (minutes)   | 5                         | How far back to count                           |
| Cooldown (minutes) | 30                        | Stops a flapping problem from paging repeatedly |

Alerts are checked every minute. When the count reaches the threshold the alert **triggers** and notifies once; when it drops back below, it **resolves** and notifies again.

![Creating the High 5xx rate alert: name, query, a 30-minute cooldown with the backtest, then Email as the channel](https://tailcove.dev/images/guides/alert-on-error-spikes/create-alert.mp4 "The backtest under When it fires replays the last 7 days with your numbers, so you can see how often it would have fired before you save.")

## 3. Choose channels

Pick at least one:

- **Slack** or **Discord**: paste an incoming webhook URL for the channel your on-call engineer watches.
- **Email**: one or more addresses.
- **Webhook**: your own endpoint, for automation.

## 4. Verify webhook signatures

Webhook requests carry an `X-Tailcove-Signature` header: an HMAC-SHA256 of the raw body with your team's webhook signing secret. Always verify it before acting:

```php
$signature = hash_hmac('sha256', $request->getContent(), $webhookSecret);

if (! hash_equals($signature, $request->header('X-Tailcove-Signature'))) {
    abort(401);
}
```

Compare with a constant-time function such as `hash_equals`, never `==`. The payload's `event` field is `alert.triggered` or `alert.resolved`.

## 5. Test it

Temporarily set the threshold to 1 and send a matching line:

```bash
curl -X POST https://ingest.tailcove.dev/api/v1/logs \
  -H "Authorization: Bearer YOUR_INGEST_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"message":"Test 500","level":"error","context":{"status":500}}'
```

Within about a minute the alert triggers and your channel receives a notification. Set the threshold back afterwards.

![The alert page after twelve 502s arrive: Firing, with the firing in History and the email it sent](https://tailcove.dev/images/guides/alert-on-error-spikes/fires.mp4 "Twelve 502s in a few minutes: the alert fires, and History shows the firing, how many lines matched and where the message went.")

## Tuning over time

Review your alerts once a month. One that fires often with no action needed should get a higher threshold or a narrower query; one that never fires may be watching the wrong thing.

## Next steps

- Cover the case where the app stops logging altogether: [monitor uptime and publish a status page](https://tailcove.dev/guides/uptime-monitoring-and-status-page).
- Catch a bad release before this alert has to: [fail a deploy when errors spike](https://tailcove.dev/guides/fail-deploys-when-errors-spike).
- Every field and payload in the [alerts reference](https://tailcove.dev/docs/alerts).
