# Sentry

The back end's faults, and what the program reports itself, sent to
[Sentry](https://sentry.io) (or anything that takes its envelopes:
GlitchTip, a Sentry of your own), fed by
[`server on failure`](back-end.md#when-something-fails). An
[extension](../extensions/README.md): `extensions/sentry/`. Back to the
[map](README.md).

```mote
use "pkg:sentry/sentry.mote"

server fn checkout(cart: string): string requires signedIn
  if cart == "" sentryCapture("checkout with an empty cart", "warning", {cart})
  return "ok"
```

```sh
SENTRY_DSN=https://<key>@o0.ingest.sentry.io/<project> SENTRY_RELEASE=shop@1.4.0 bun dist/server/main.js
```

| Setting | |
|---|---|
| `SENTRY_DSN` | The project's DSN. Unset: nothing is sent. Its key only lets one post events: it is not a secret. |
| `SENTRY_ENVIRONMENT` | `production` unsaid. |
| `SENTRY_RELEASE` | The release (a version, a commit). |

- **Every fault is an event** of level `error`: its words, `transaction` the
  call, route, job or block, the stack by the program's own lines (the back
  end's [source maps](back-end.md#where-a-fault-was-written)) as frames, the
  signed-in person's id (nothing else of theirs), and the call's id, which
  the back end's log line has too.
- `sentryCapture(message, level, extra)`: a message of the program's own.
- An event is an envelope (`POST /api/<project>/envelope/`, three lines:
  its header, the item's, the event) with `X-Sentry-Auth`. Sending never
  fails and never waits more than five seconds: a refusal is a line of the
  log, and reporting cannot break what it reports on.

Not met Sentry: run against a stand-in (`tests/all.sh real_svc_more`). To
check: a project's DSN, a route that breaks, and the issue in Sentry with
its frames at the program's lines.
