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
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 has the shape.
- Items are stored under a signal: logs as
log, transactions and spans asspan, trace metrics asmetric, and every other item, errors included, asevent. - A
200means the items are stored durably and will be delivered at least once. Replies follow Sentry's, so SDKs back off when the quota is reached.
1. Create a stream and a key
Create an ingestion stream in the dashboard, 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
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:
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:
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 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:
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 lists the other errors.
4. Query the data
DuckDB reads the objects in place:
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:
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:
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:
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:
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.
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
dataas stored is the number billed, which includes its envelope and item headers. - Retries: see Retries. To drop repeats, key on the envelope's
event_idin your query.