Skip to main content

Send Supabase log drains to S3 with OpenTelemetry

Supabase keeps project logs for a retention period set by its plan. A log drain sends them as they are written, and Send2Bucket delivers them to a bucket or table you own, for as long as you keep them.

note

We sent a gzip OTLP protobuf logs request, as Supabase's OTLP destination sends, and the OTLP JSON check request below to a local Send2Bucket node writing to S3-compatible storage, and ran the DuckDB queries (DuckDB 2.0) on the objects it wrote. The dashboard steps follow Supabase's log drain docs and were not run against Supabase.

How it works​

Supabase ──OTLP/HTTP protobuf──▶ /v1/logs ──▶ your stream's destination
  • Each log record becomes one line with signal log, as an OpenTelemetry record with its resource and scope.
  • A 200 means the records are stored durably and will be delivered at least once. See Delivery semantics.
  • Log drains need a Supabase Pro, Team or Enterprise plan.

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. A key for one stream needs no stream ID in the drain. A stream for Supabase alone keeps the queries below to its records.

2. Add the drain​

Supabase's log drains send OpenTelemetry logs over HTTP as protobuf, which the OTLP/HTTP endpoint takes as it is.

  1. In your Supabase project's settings, open Log Drains and add an OpenTelemetry (OTLP) destination.

  2. Endpoint: https://api.send2bucket.com/v1/logs, the full URL. Protocol: http/protobuf, the only one Supabase offers.

  3. Headers:

    Authorization: Bearer <key>
    S2b-Stream: <stream_id>

    Leave out S2b-Stream if the key writes to one stream.

  4. Turn on gzip: compression does not change what Send2Bucket bills, and gzip makes the requests smaller.

3. Check the endpoint​

Before Supabase sends anything, check the key and stream with one log record in the OTLP JSON encoding. It stores one record, and the answer is a 200 with {}:

curl -i https://api.send2bucket.com/v1/logs \
-H "Authorization: Bearer $S2B_API_KEY" \
-H "S2b-Stream: <stream_id>" \
-H "Content-Type: application/json" \
--data-binary '{"resourceLogs":[{"scopeLogs":[{"logRecords":[{"severityText":"INFO","body":{"stringValue":"hello from curl"}}]}]}]}'

A 401 means the key is wrong or revoked; a 403 or 400 names the stream problem; a 409 means the stream has no destination. The API reference lists every error.

4. Query the logs​

DuckDB reads the objects in place. This view keeps the drained logs:

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

CREATE VIEW drains 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',
resource: 'JSON', scope: 'JSON', data: 'JSON'})
WHERE signal = 'log';

The latest records. body is the message as an OTLP value, such as {"stringValue":"…"}, and attributes a list of {key, value}:

SELECT received_at, data->>'$.severityText' AS severity, data->'$.body' AS body
FROM drains
ORDER BY received_at DESC
LIMIT 20;

Records per severity each hour:

SELECT date_trunc('hour', received_at) AS hour, data->>'$.severityText' AS severity, count(*) AS records
FROM drains
GROUP BY ALL
ORDER BY hour DESC, records DESC;

Supabase does not document which attributes it sets on each record, so list the keys it sends before writing queries that depend on them:

SELECT a->>'$.key' AS attribute, count(*) AS records
FROM drains, unnest(json_extract(data, '$.attributes[*]')) AS t(a)
GROUP BY ALL
ORDER BY records DESC;

In an Iceberg or DuckLake table, the same line is in the payload column with signal_type log; see Table columns.

Notes​

  • Billing: each record's JSON as stored is the number billed, whatever the compression or encoding. See Plans and billing.
  • Retries: see Retries.
  • Other platforms: Log drains covers Vercel, Heroku, Netlify, Cloudflare, Fastly and others.