# Fail a deploy when errors spike

After a release goes out, someone usually watches the error chart for a few minutes and decides whether it looks worse. Tailcove can do that for you on every deploy. You record the deploy from CI, and about 15 minutes later its [deploy check](https://tailcove.dev/docs/deploy-checks) says **healthy** or **regressed**. With `tailcove deploy --wait`, a regressed check fails the job, so the bad release shows up as a red pipeline instead of a quiet Slack thread.

## 1. Make a token for CI

CI can't sign in through a browser, so it uses an API token. In Tailcove, open **Settings → API tokens**, pick the **For CI** preset (it ticks `sources:read`, `deploys:read`, `deploys:write` and `sourcemaps:write`) and create the token. It's shown once.

In GitHub, add it to the repository under **Settings → Secrets and variables → Actions** as `TAILCOVE_API_TOKEN`.

Then find the source's id, which stays the same if someone renames the source:

```bash
tailcove sources
```

If you haven't installed the [CLI](https://tailcove.dev/docs/cli) on your laptop yet, the id is also in the address of the source's page, like `src_01jbx5q8k7m3n2p4r6s8t0v1w3`.

## 2. Check the deploy after it ships

Add a job that runs once the deploy job has finished. It installs the `tailcove` binary from the agent's latest release, records the deploy and waits for the check:

```yaml
  verify:
    needs: deploy
    runs-on: ubuntu-latest
    timeout-minutes: 25
    env:
      TAILCOVE_API_TOKEN: ${{ secrets.TAILCOVE_API_TOKEN }}
    steps:
      - name: Install tailcove
        run: |
          curl -fsSL https://github.com/tailcove/agent/releases/latest/download/tailcove_linux_amd64.tar.gz | tar -xz tailcove
          sudo install -m 0755 tailcove /usr/local/bin/tailcove

      - name: Record the deploy and wait for its check
        run: tailcove deploy --source src_01jbx5q8k7m3n2p4r6s8t0v1w3 --env production --wait
```

`tailcove deploy` takes the commit from `GITHUB_SHA` and uses its short form as the version, so there's nothing to pass. Give it `--version "$GITHUB_REF_NAME"` if you'd rather see your tag on the dashboard.

Keep this as its own job, after the deploy. The check waits about 16 minutes for errors to show up, and the release is already live by then: failing this job doesn't undo anything, it tells you. If your deploy can be rolled back by a script, add a step after the check that runs only when it failed:

```yaml
      - name: Roll back
        if: failure()
        run: ./scripts/rollback.sh
```

## 3. What the check looks at

Fifteen minutes after the deploy, Tailcove compares those 15 minutes with the hour before it, for the one source. The deploy **regressed** when any of these happened:

- Errors a minute went above 1.5 times the rate before, and at least 1 more a minute, with 5 errors or more after the deploy.
- An error [pattern](https://tailcove.dev/docs/patterns) shows up with 3 or more lines that the source hadn't logged once in the 7 days before.
- A new [issue](https://tailcove.dev/docs/issues) was first seen after the deploy.

A worked example: 24 errors in the hour before is 0.4 a minute, so the limit is 1.4 a minute. 32 errors in the 15 minutes after is 2.1 a minute, past it.

A source that sent nothing in the 15 minutes after, or nothing in the week before, gets **no data**: it can't compare, so it doesn't guess. `--wait` exits `0` for healthy, no data and a skipped check, and `1` for regressed or when it runs out of time (`--timeout`, 20 minutes by default).

## 4. Where the answer shows up

Each deploy gets a report page. Click the badge next to it on the dashboard's **Changes and incidents** card, on the source's **Overview**, or on a log line's **Release** row. The report lists errors a minute before and after, each new error pattern with its first line and a link to its logs, and each new issue.

A regression is also sent to the source's default alert channels, the ones under **Notify by default** on its **Alerts** tab, so Slack hears about it even when nobody is watching the pipeline. To get a short note for healthy deploys too, pick **Tell us about every check** under **Deploy checks** on the source's **Settings** tab.

When the source has a GitHub repository set on its **Issues** tab and the deploy names its full 40-character commit, the result is also a commit status called **Tailcove deploy check** on that commit, with a link back to the report. A repository connected through the Tailcove GitHub App needs the app to have the **Commit statuses** permission for this; the report page tells you when GitHub refused it.

## FAQ

**Does this slow down my deploy?**

No. The deploy job finishes as before. Only the `verify` job waits, and nothing else depends on it unless you add `needs: verify` somewhere.

**My service is quiet. Will one stray error fail the pipeline?**

No. The error rate rule needs at least 5 errors after the deploy and at least 1 more a minute than before. A new error pattern needs 3 lines.

**Can I use it without GitHub Actions?**

Yes. `tailcove deploy --wait` reads the commit from GitLab CI, Bitbucket Pipelines, CircleCI and Vercel variables too, or from `git rev-parse HEAD`. Without the CLI, `POST /api/v1/sources/{id}/deploys` records the deploy and `GET` on the deploy returns its `check` (see the [deploys API](https://tailcove.dev/docs/api/deploys)).

**Can I turn it off for one source?**

Yes. Pick **Off** under **Deploy checks** on the source's **Settings** tab. Deploys are still drawn on the charts; `--wait` then returns `0` straight away.
