
# What the gateway records

Check what the gateway records and how long it keeps it, then change that with a few settings.

```bash
curl -sS "$TOKEDEX_URL/observability/v1/status" \
  -H "Authorization: Bearer $TOKEDEX_ADMIN_KEY"
```

```json
{
  "object": "observability_status",
  "apiVersion": "v1",
  "state": "ok",
  "enabled": true,
  "captureText": true,
  "traces": 4,
  "spans": 5,
  "oldestStartedAt": "2026-11-20T01:23:06.891Z",
  "newestStartedAt": "2026-11-20T01:28:45.067Z",
  "storageBytes": 102400,
  "retention": { "maxAgeSeconds": 2592000, "maxBytes": 536870912, "maxTraces": null, "lastPrunedAt": "2026-11-20T01:30:30.967Z" },
  "ingest": { "queueDepth": 0, "queueCapacity": 4096, "droppedEvents": 0, "degraded": false, "lastErrorAt": null }
}
```

You need: an admin key with the `admin`, `operator` or `viewer` preset in `TOKEDEX_ADMIN_KEY`, and `export TOKEDEX_URL='http://127.0.0.1:4000'`. Changing a setting below needs access to the gateway's environment.

## Data recorded for each request

| Data | Recorded |
| --- | --- |
| Model, provider, key, workspace, timings, token counts, cost, error codes, tool names, tags and session | Always, unless recording is off |
| Prompt, response, tool-argument, tool-result and provider error-message text | Only when the gateway allows text capture and the request asks for it |

Recording is on by default, and each record is a trace in [**Observability**](/gateway/requests-and-sessions). Spend is recorded separately, so budgets and the [spend report](/gateway/spend-and-usage) stay complete whatever you set here.

## Turn text capture on

Set `TOKEDEX_OBSERVABILITY_TEXT_CAPTURE=true` in the gateway's environment and restart it. Then the text of each request that sends this header is captured:

```text
x-tokedex-trace-text: true
```

Capture applies to later requests. A trace without text reads **Text not captured**.

Turn capture on only while you debug, and have only the client you are debugging send the header: captured text can be read by every organisation Owner and Admin, and by admin keys with the `admin` or `operator` preset, goes to your [export destinations](/gateway/export-traces#prompt-and-response-text) and stays in your backups. Callers set the header as [Errors, limits and request IDs](/gateway/errors-and-limits#make-a-request-easy-to-find) shows.

## Trace retention

| Variable | Keeps | Default |
| --- | --- | --- |
| `TOKEDEX_OBSERVABILITY_MAX_AGE_SECONDS` | Traces up to this age | `2592000` (30 days) |
| `TOKEDEX_OBSERVABILITY_MAX_BYTES` | The trace store up to this size | `536870912` (512 MiB) |
| `TOKEDEX_OBSERVABILITY_MAX_TRACES` | Up to this many traces | No limit |

Set the age to the longest you need to look back on requests, within what your privacy policy allows, and keep a size limit so traces cannot fill the disk or database that also holds spend. The gateway deletes the oldest traces at a limit, and lowering a limit deletes the traces beyond it, so export what you need first. Traces are kept in `~/.tokedex/observability.sqlite`, or `TOKEDEX_OBSERVABILITY_STORE_PATH`; with a shared Postgres database, in the database. With several replicas and no shared database, each replica records only the requests it served.

On Kubernetes, set variables under `extraEnv` in the Helm chart's values; for a local gateway started with `npm start`, in the `.env` file in the repository root. Restart the gateway after a change.

## Turn recording off or on

Prefer keeping recording on with text capture off: the metadata alone finds a failed request, and a request that must leave no record can send `x-tokedex-trace: false`. Set `TOKEDEX_OBSERVABILITY` to `0`, `false`, `no` or `off` and restart: nothing is recorded or [exported](/gateway/export-traces) from then on. `1`, `true`, `yes` or `on` turns it back on. Any other value turns recording off, with a warning at startup.

While it is off, an organisation Owner or Admin can also choose **Enable observability** on **Observability**, or send `PUT /control/observability` with `{"enabled": true}`, then restart. A set `TOKEDEX_OBSERVABILITY` wins.

## Keep content private

- **Leave a request out.** A request that sends `x-tokedex-trace: false` is not recorded or exported at all, metadata included. It takes effect once a request has authenticated; a request refused before that is recorded as the gateway's setting says. No header turns recording on when the gateway has it off.
- **Restrict who reads traces.** Tool names, tags and key names can identify a workflow without any text. Organisation Owners, Admins and Viewers read every trace.
- **Restrict who reads logs.** Logs are separate from traces. A failed request's log line keeps up to 2 KiB of the provider's error body, which can repeat prompt text whatever you set here.
- **Plan for the store.** Include it in your [backups](/gateway/backup-restore) and privacy reviews.

The gateway masks the key that authenticated the request in the traces it records and exports. Keep other credentials out of captured text. If an earlier trace contains a key, revoke it and follow your retention policy for the trace and any copies at export destinations.

## Check that recording works

A request succeeds whether or not its trace is stored, so check the status above, and have your monitoring alert when it is not `ok`. Its `state` is:

- `ok`: the gateway is recording.
- `degraded`: the gateway is dropping trace events, so some traces are incomplete.
- `disabled`: recording is off. With `configEnabled: true`, the store is not running: restart the gateway, then check its startup log, store path or database, permissions and disk space.

Two endpoints that need no key report the gateway itself:

```bash
curl -sS "$TOKEDEX_URL/readyz"
```

```json
{"ok":true,"release":{"environment":"local"},"service":"tokedex"}
```

`/healthz` says the process is running. `/readyz` also tests Postgres and Redis, when used, within one second; when one fails, it answers `503` with its name in `unavailable`. A gateway that cannot write spend refuses keys under a budget, so watch your database and disk.

## Audit log

The **Audit log** records who changed the gateway's configuration and access, such as keys, provider credentials, models, prices and workspaces, and each attempt to authenticate to manage it. It records no model requests. Organisation Owners, Admins and Viewers see it in the sidebar.

The audit log keeps 30 days of changes. With a shared Postgres database, set `TOKEDEX_CONTROL_JOURNAL_MAX_AGE_SECONDS` to change the age limit and `TOKEDEX_CONTROL_JOURNAL_MAX_EVENTS` to cap the number of events. The gateway checks both limits at startup and every minute, even when nobody makes changes. An age limit under a minute shortens the sweep interval to that limit, down to one second. Include the audit log in your backups and export anything you need before lowering a limit. Without Postgres, the audit log also stops at 256 MiB.

Next: [Find and inspect a request](/gateway/requests-and-sessions), [Export traces with OpenTelemetry](/gateway/export-traces) or [Backup and restore](/gateway/backup-restore).
