# Request traces: why did this request fail?
Source: https://sovaria.in/docs/request-traces

Every request carries a trace id from the SDK through the gateway, each Sovaria product and SQL. When one is refused or fails, Sovaria records which check said no and why, and explains it.

A request passes several checks before it reaches your data: sign-in, the caller's access to the project, their team role, rate limits, app attestation, plan limits, access policies, and in the database, row-level security and privileges. When one of them says no — or a service fails — **Request traces** (in the console sidebar under **More**, or pinned to it) shows which one, the reason, and what to do.

(Diagram: One trace id, end to end)

## The trace id

The SDKs send a W3C `traceparent` with every call (all retries of one call share it) and put the trace id on errors; every response also carries it as `X-Request-ID`. Your own trace id is kept only when it is well formed: an `X-Request-ID` of 16–64 hex characters (a UUID is accepted without its dashes) or a valid W3C `traceparent` (32-hex trace id); anything else gets a fresh id.

JavaScript:
```ts
try {
  await sov.data.sql('insert into orders (total) values ($1)', [42])
} catch (e) {
  if (e instanceof SovariaError) {
    console.log(e.traceId)            // 4bf92f3577b34da6a3ce929d0e0e4736
    const why = await sov.api.traces.get({ traceId: e.traceId! })   // project team only
    why.explanation  // { verdict: 'denied', by: 'Guard policy', reason: "Guard denied INSERT on 'orders' …", hint: '…' }
  }
}
```

Python:
```python
try:
    await client.sql_query("insert into orders (total) values (42)")
except SovariaError as e:
    print(e.trace_id)
```

CLI:
```bash
sov logs why 4bf92f3577b34da6a3ce929d0e0e4736
sov logs refused --kind denied
```

## What it can tell you

| Refused by | Means | What to do |
|---|---|---|
| Sign-in | No token, or an expired, revoked or wrong-project token or key. | Sign in again; check the project URL and key. |
| Team role | Your organization role lacks the permission. | An owner grants it in Organization › Roles. |
| Rate limit / plan quota | Too many requests, or the plan's quota is used up. | Wait for Retry-After; see Plan & usage. |
| App attestation | Attestation is enforced and the app sent no valid token. | Integrate App Check / App Attest, or use a debug token. |
| Guard policy | An access policy refused the action. | Simulate the user, table and action under Policies. |
| Row-level security | A row policy rejected the row. | Check the policy's USING / WITH CHECK, and who owns the row. |
| Database privileges | The app role has no privilege on that object. | Grant it in a migration or set the table's access preset. |
| Team-only API | App users and the anon key can't do this. | Call it from your server or a function with the service key. |

- Refusals (401, 403, 409, 422, 429) and failures (5xx) are recorded; successful requests are not stored.
- Only refusals of signed-in callers of your project are stored for it — anonymous noise never lands in your traces.
- Only your project team can read its traces (not app users or the anon key), and another project's trace id answers like one that doesn't exist.
- Messages are stored as the caller saw them, with tokens and secrets scrubbed; request and response bodies are never stored.

## How long traces are kept

|  | Free | Pro | Ultra | Team | Enterprise |
|---|---|---|---|---|---|
| Request trace history (why a request failed) | 1 day | 7 days | 14 days | 30 days | 30 days |
