Send Heroku logs to S3 with a log drain
Heroku's Logplex keeps only the most recent lines, and heroku logs shows only those. A drain sends every line to Send2Bucket as it is written, and Send2Bucket delivers the lines to a bucket or table you own, for as long as you keep them.
We sent application/logplex-1 requests shaped like Logplex's, with the key as the Basic auth password, to a local Send2Bucket node writing to S3-compatible storage, and ran the check request and the DuckDB queries (DuckDB 2.0) on the objects it wrote. The heroku drains:add step follows Heroku's log drain docs and was not run against Heroku.
How it works
Heroku Logplex ──logplex syslog over HTTPS──▶ /v1/events/heroku ──▶ your stream's destination
- Each syslog message becomes one record with
signallog, parsed intotimestamp,app_name,proc_id,messageand the other syslog fields. Delivery format lists them. app_nameisappfor your processes andherokufor the platform's own lines, such as the router's.- A
200means the records are stored durably and will be delivered at least once. See Delivery semantics.
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.
2. Add the drain
A Heroku drain is a URL, so the key goes in it as the Basic auth password, and the stream in the stream query parameter:
heroku drains:add 'https://x:<key>@api.send2bucket.com/v1/events/heroku?stream=<stream_id>' -a <app>
The x username is ignored. Logplex retries a request that gets anything but a 2xx, and drops lines when a drain falls behind. These steps cover Cedar apps; telemetry drains on Fir apps send OpenTelemetry, which goes to the OTLP endpoints instead.
3. Check the endpoint
Before Heroku sends anything, check the key and stream with one Logplex-framed message. It stores one record, and the answer is a 200 with an empty body:
msg='<190>1 2026-11-25T10:00:00+00:00 host app web.1 - hello from curl'
curl -i "https://x:$S2B_API_KEY@api.send2bucket.com/v1/events/heroku?stream=<stream_id>" \
-H "Content-Type: application/logplex-1" \
--data-binary "${#msg} $msg"
Logplex frames each message with its length in bytes, which ${#msg} gives for ASCII text. 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';
Lines per dyno, your processes only:
SELECT data->>'$.proc_id' AS dyno, count(*) AS lines
FROM drains
WHERE data->>'$.app_name' = 'app'
GROUP BY ALL
ORDER BY lines DESC;
The router writes one key=value line per request. Router errors by code, such as H12 for a request that took over 30 seconds:
SELECT regexp_extract(data->>'$.message', 'code=(H[0-9]+)', 1) AS code, count(*) AS errors
FROM drains
WHERE data->>'$.proc_id' = 'router' AND data->>'$.message' LIKE 'at=error%'
GROUP BY ALL
ORDER BY errors DESC;
The slowest requests, by the router's service time:
SELECT data->>'$.timestamp' AS at,
regexp_extract(data->>'$.message', 'path="([^"]*)"', 1) AS path,
regexp_extract(data->>'$.message', 'status=([0-9]+)', 1) AS status,
TRY_CAST(regexp_extract(data->>'$.message', 'service=([0-9]+)ms', 1) AS INTEGER) AS service_ms
FROM drains
WHERE data->>'$.proc_id' = 'router'
ORDER BY service_ms DESC NULLS LAST
LIMIT 20;
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, so a line costs its parsed JSON, not its syslog text. See Plans and billing.
- Retries: Logplex's retries are not deduplicated. See Retries.
- Keys in URLs: the key in the drain URL can end up wherever the URL is shown or logged. Use a key for one stream, and rotate it if the URL leaks. See Drain keys and streams.
- Other platforms: Fly.io ships logs with its log shipper. Log drains covers Vercel, Supabase, Netlify, Cloudflare, Fastly and others.