# DSN and the region model

## Format

```
https://<publicKey>@<region>.<ingestHost>/<projectId>
```

Example: `https://a1b2c3d4@us.ingest.example.com/clx0project0id`

| Part | Rules |
| --- | --- |
| scheme | `https` (`http` is tolerated for local development only) |
| `publicKey` | `[A-Za-z0-9_-]+`, unique to one project key |
| password half | **must be empty** — a DSN carrying a secret is rejected as malformed |
| `region` | first hostname label; `[a-z][a-z0-9-]{0,15}` |
| `ingestHost` | everything after the region label, port included |
| path | exactly one segment, the project id |
| query / fragment | must be absent |

Bucker's SDKs, the `bucker` CLI and `create-bucker` all check a DSN against these same
rules before using it.

## The Sentry-SDK form: the project's number

Every Sentry SDK refuses a DSN whose project segment is not an integer. The JavaScript SDKs
disable themselves without saying so outside debug mode (`Invalid Sentry Dsn: Invalid
projectId`), and sentry-python raises at `init` (`invalid literal for int()`). A Bucker
project id is not an integer, so the DSN above cannot be given to an unmodified Sentry SDK.

Each project therefore also has a number, and every key reports a second, equivalent DSN
with it, `sentryDsn`:

```
https://<publicKey>@<region>.<ingestHost>/<projectNumber>
```

Use `sentryDsn` in `Sentry.init({ dsn })`. Every DSN-authenticated route (the envelope,
OTLP, check-ins, feedback and the rest) accepts either form in its `<projectId>` path segment.
The number only identifies the project. It never authenticates: the public key must still
belong to the project the path names, so a key addressed at another project's number is
refused with a `403`, exactly as with another project's id. Bucker's own SDKs accept both
forms.

## The public key is not a credential for anything but ingest

The public key appears in client bundles by design. It authenticates **ingest
only** — it cannot read an issue, list a project, or call the control plane. There is
no secret half to protect, which is why listing keys back to project members is safe
and why the onboarding endpoint can return the DSN.

Legacy Sentry DSNs carried a secret in the password slot. Bucker DSNs never do, and
Bucker rejects a DSN that carries one.

## Why the region prefix exists on day one

The first hostname label is the data region. When another region opens, it gets a new
hostname with the same identifier scheme, so your existing DSN and every config file that
quotes it stay valid.

The DSN shown for a key (in the dashboard and in the keys API) is built fresh on every
read, so it always names the current ingest host and region; copy it from there rather
than assembling one by hand.

Today only one region runs: `us`. `eu` is a recognised label but is **not active**. Bucker's
SDKs and the CLI accept any well-formed region label, so they need no update when another
region opens.

## Ingest endpoint

```
POST https://<region>.<ingestHost>/api/<projectId>/envelope/
Content-Type: application/x-sentry-envelope   (or any type: the route reads the body raw)
```

The bare form without the trailing slash is registered too, so `curl` and hand-rolled
clients do not hit a surprise 404.

Authentication is the public key, sent either as the `sentry_key` query parameter or
inside the envelope header's `dsn` field. The browser SDK avoids a preflight on every
event, and that takes two things together. First, auth goes in the query string, because
an `X-Sentry-Auth` header is not CORS-safelisted. Second, the SDK sends
`Content-Type: text/plain;charset=UTF-8`, which the ingest route accepts because it
ignores the type. Query-string auth with `application/x-sentry-envelope` is still
preflighted. A `sendBeacon` built that way is credentialed, so it cannot pass the ingest
route's `*`/no-credentials preflight and is silently dropped. If you send envelopes from
a browser with your own code, use `text/plain;charset=UTF-8` and query-string auth, as the
Bucker browser SDK does.

A `200` carries `{ "id": "<eventId>" }` and an `X-Bucker-Ingest-Disposition` header.
**It means the envelope was accepted and queued**, not that an issue exists yet —
that happens a moment later, when Bucker processes the queued envelope.

## An organization is served by one region

An organization lives in one region, and a request for it that reaches another region is
refused with **409** and `error.details.redirectTo`, the API URL of the organization's
region. The check applies everywhere an organization is reached, not only the compliance
routes:

- REST routes naming `:orgSlug`, and every authenticated route (a `:projectId` in the URL,
  an organization-bound credential);
- ingest, OTLP, the platform log drains and the replay recorder config;
- Explore;
- MCP tools;
- background processing of your data, which runs only in your organization's region.

Details a client can rely on:

- `GET /orgs/:orgSlug/compliance/residency` is exempt. It reports `servedByThisRegion: false`, which
  is the answer that explains the refusals everywhere else.
- On an authenticated route, a signed-in caller who is **not a member** of the org gets a **404**
  and never the 409: whether someone else's organization lives in `eu` is not theirs to learn, and
  404 is what the other region would answer here. On a public or optional-auth route (status
  pages, SSO entry points) everyone gets the 409, as an anonymous caller does.
- `redirectServing: false` in the 409 means the named region is not operating. `eu` is listed and
  **not active**: it has no DNS name and no data stores, so there is nowhere to redirect to yet.
- Ingest takes the project from the **key** in the DSN, never from the envelope body.
- An organization's region is cached for up to 30 seconds. A region move is the only thing that
  changes it, and for up to 30 seconds after one, requests may still be served from the old
  region.
- No token changes. A token issued before a region check applies verifies exactly as it did; the
  audience stays `bucker-mcp`.

`residency_get` (MCP, `project:read`) tells an agent which region serves the org, which provider
and region hold each store (a `?` is "not yet confirmed", never a guess), and any region move in
flight; `include: [manifest]` adds the published trust manifest from `https://www.bucker.io/trust.json`.

## Size limits

| Limit | Value | What happens above it |
| --- | --- | --- |
| Largest accepted envelope | 20 MiB (`20971520` bytes) | Rejected, and counted as a `too_large` outcome in the project's drops panel |
