# Send Sentry SDK errors, traces and logs to your own storage

Sentry SDKs send what they capture to the host in their DSN, as envelopes. A DSN that names Send2Bucket makes any SDK send there instead, with no other code change. Each envelope item, such as an error event, a transaction, a span or a log, becomes one line in your stream's destination. Sentry's product is not involved: you get the raw items, without issue grouping, symbolication or alerts. Use it to keep error and performance data at storage prices, for as long as you keep it.

## How it works

```text
Sentry SDK ──envelope──▶ /v1/events/sentry/<stream_id>/api/<project>/envelope/ ─▶ your stream's destination
```

- Each item becomes one line holding the envelope header, the item header and the payload: JSON as JSON, anything else, such as an attachment, as base64. A log, span or metric container becomes one line per entry. [Delivery format](../delivery-format.md#sentry) has the shape.
- Items are stored under a signal: logs as `log`, transactions and spans as `span`, trace metrics as `metric`, and every other item, errors included, as `event`.
- A `200` means the items are stored durably and will be delivered at least once. Replies follow Sentry's, so SDKs back off when the [quota](../api-reference.md#sentry-replies) is reached.

## 1. Create a stream and a key

Create an ingestion stream in the [dashboard](pathname:///app/), add a destination, and copy the stream's API key and ID. The key is the DSN's public key, and a DSN ships inside browser and mobile apps, so use a key that writes only to this stream.

## 2. Set the DSN

```text
https://<key>@api.send2bucket.com/v1/events/sentry/1
```

The final `1` stands for the project ID every DSN ends with; Send2Bucket ignores it. A key for several streams names the stream before it: `https://<key>@api.send2bucket.com/v1/events/sentry/<stream_id>/1`.

Set it wherever the SDK takes its DSN, such as the `SENTRY_DSN` environment variable or `init`. In Python:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@api.send2bucket.com/v1/events/sentry/1",
    traces_sample_rate=1.0,
    enable_logs=True,
    _experiments={"transport_compression_algo": "gzip"},
)
```

With the `brotli` package installed, sentry-python compresses with Brotli, which Send2Bucket does not accept; the `_experiments` line keeps it on gzip. In JavaScript:

```js
Sentry.init({
  dsn: 'https://<key>@api.send2bucket.com/v1/events/sentry/1',
  tracesSampleRate: 1.0,
  enableLogs: true,
});
```

Browser SDKs need nothing more: replies allow any origin. Sample rates work as usual, since sampling happens in the SDK.

Sentry's OTLP endpoints under the DSN, `…/v1/events/sentry/<stream_id>/api/1/integration/otlp/v1/traces` and `…/logs`, are served too: they store OpenTelemetry records as the [OTLP endpoints](../api-reference.md#otlp-http) do, with the key from the `X-Sentry-Auth` header Sentry's setup gives.

## 3. Check the endpoint

Send one event in an envelope. The answer is a `200` with the event's ID:

```bash
curl -i https://api.send2bucket.com/v1/events/sentry/api/1/envelope/ \
  -H "X-Sentry-Auth: Sentry sentry_version=7, sentry_key=$S2B_API_KEY" \
  --data-binary $'{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"}\n{"type":"event"}\n{"message":"hello from curl","level":"info"}\n'
```

A `401` means the key is wrong or revoked; the reason is also in the `X-Sentry-Error` header. The [API reference](../api-reference.md#sentry) lists the other errors.

## 4. Query the data

[DuckDB](../querying/duckdb.md) reads the objects in place:

```sql
INSTALL httpfs; LOAD httpfs;
CREATE SECRET s2b (TYPE s3, PROVIDER credential_chain, REGION '<region>');

CREATE VIEW sentry AS
SELECT * FROM read_json(
  's3://<bucket>/<prefix>/s2b/stream=*/date=*/hour=*/*.ndjson.gz',
  format = 'newline_delimited',
  hive_partitioning = true,
  columns = {v: 'INTEGER', delivery_batch_id: 'VARCHAR', batch_id: 'VARCHAR',
             received_at: 'TIMESTAMPTZ', signal: 'VARCHAR', data: 'JSON'})
WHERE stream = '<stream_id>';
```

What the SDKs send, by item type:

```sql
SELECT data->>'$.type' AS item, signal, count(*) AS lines
FROM sentry
GROUP BY ALL
ORDER BY lines DESC;
```

Errors by exception. The last exception in `values` is the one thrown:

```sql
SELECT data->>'$.payload.platform' AS platform,
       data->>'$.payload.exception.values[#-1].type' AS type,
       data->>'$.payload.exception.values[#-1].value' AS message,
       count(*) AS events
FROM sentry
WHERE data->>'$.type' = 'event'
GROUP BY ALL
ORDER BY events DESC;
```

The slowest transactions and spans. SDKs send timestamps as Unix seconds or as RFC 3339 text, so the macro reads both:

```sql
CREATE MACRO seconds(t) AS coalesce(TRY_CAST(t AS DOUBLE), epoch(TRY_CAST(t AS TIMESTAMPTZ)));

SELECT data->>'$.type' AS item,
       coalesce(data->>'$.payload.transaction', data->>'$.payload.name') AS name,
       round((seconds(coalesce(data->>'$.payload.timestamp', data->>'$.payload.end_timestamp'))
            - seconds(data->>'$.payload.start_timestamp')) * 1000, 3) AS ms
FROM sentry
WHERE signal = 'span'
ORDER BY ms DESC
LIMIT 10;
```

The latest logs:

```sql
SELECT to_timestamp(seconds(data->>'$.payload.timestamp')) AS ts,
       data->>'$.payload.level' AS level,
       data->>'$.payload.body' AS body
FROM sentry
WHERE signal = 'log'
ORDER BY ts DESC
LIMIT 20;
```

In an Iceberg or DuckLake table, the same line is in the `payload` column; see [Table columns](../delivery-format.md#table-columns).

## Notes

- **What is not done**: stack traces stay as the SDK sent them, so minified JavaScript and native frames are not symbolicated. There are no issues, releases or alerts.
- **Everything is stored**: sessions, client reports, check-ins, profiles, replays and attachments are lines too, binary ones as base64. Filter on `data.type`.
- **Size**: an envelope can be up to 8 MiB decompressed, attachments included; a larger one gets a `413`.
- **Compression**: gzip works; Brotli gets a `415`.
- **Billing**: each record's `data` as stored is the number billed, which includes its envelope and item headers.
- **Retries**: see [Retries](../api-reference.md#retries). To drop repeats, key on the envelope's `event_id` in your query.
