# Ship Fly.io logs to your own storage with the Fly log shipper

Fly.io has no drain URL to set. It publishes the logs of every app in an organization to a NATS stream, and the [Fly log shipper](https://github.com/superfly/fly-log-shipper), a Fly app that runs [Vector](https://vector.dev), reads that stream and forwards it to one or more sinks. Its HTTP sink posts JSON to any URL, which Send2Bucket's generic JSON drain, `POST /v1/events/json`, takes as it is. Each Fly log line then lands in your stream's destination as one record, for as long as you keep it.

## How it works

```text
Fly apps ──▶ NATS logs.<app>.<region>.<instance> ──▶ log shipper (Vector) ──HTTP sink──▶ /v1/events/json ──▶ your stream's destination
```

- The shipper parses each NATS message into the JSON record Fly published and sends that record unchanged. A record looks like this:

  ```json
  {"event":{"provider":"app"},"fly":{"app":{"instance":"148e272bd65289","name":"web"},"region":"ams"},"host":"a1b2","log":{"level":"info"},"message":"GET /healthz 200 1ms","timestamp":"2026-11-23T10:15:02.123456789Z"}
  ```

- Each record becomes one line with `signal` `log` and the record, as sent, in `data`. See [Delivery format](../delivery-format.md#log-drains).
- A `200` means the records are stored durably and will be delivered at least once. See [Delivery semantics](../delivery-semantics.md).
- Requests are not deduplicated: a batch Vector retries after a lost response is stored again.

## Pick a sink

| Sink | Set up with | Use it when |
|---|---|---|
| **Built-in HTTP sink** (recommended) | Two secrets, `HTTP_URL` and `HTTP_TOKEN` | Most organizations. Nothing to maintain beyond the shipper image. |
| **Custom HTTP sink** | Your own `vector.toml`, deployed with the shipper | You want gzip on the wire, smaller batches, or to drop lines before they are billed. |
| **Beside another sink** | The other sink's secrets as well | You keep Datadog, Better Stack or another vendor for search and alerts, and keep every line in your own bucket. |

The shipper's Datadog sink takes a Datadog site, not a URL, so it cannot reach Send2Bucket's [Datadog intake](./datadog.md); Loki, Axiom and the rest speak their vendor's API, which Send2Bucket does not accept. Its `aws_s3` sink writes NDJSON to a bucket directly, without Send2Bucket's streams, table destinations or delivery format. The shipper runs Vector 0.29.1, which has no OpenTelemetry sink, so send to the JSON drain rather than [`/v1/logs`](../api-reference.md#otlp-http).

## 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. A key for one stream needs no stream ID in the sink. One stream for Fly logs keeps them apart from your other records in your queries.

## 2. Create the shipper app

Create the app from the shipper image without deploying it, and give it a read-only token for your organization's log stream:

```bash
mkdir fly-log-shipper && cd fly-log-shipper
fly launch --no-deploy --image ghcr.io/superfly/fly-log-shipper:latest

ORG=<org_slug>
fly secrets set ORG=$ORG
fly secrets set ACCESS_TOKEN=$(fly tokens create readonly $ORG)
```

The shipper takes no inbound traffic. In the generated `fly.toml`, delete the `[http_service]` or `[[services]]` section, and add a check on Vector's health endpoint instead:

```toml
[checks]
  [checks.vector]
    port = 8686
    type = "http"
    method = "get"
    path = "/health"
    grace_period = "10s"
    interval = "30s"
    timeout = "5s"
```

By default the shipper reads every app in the organization. To read fewer, set `SUBJECT` under `[env]`, such as `"logs.web.>"` for one app or `"logs.*.ams.>"` for one region. If you run more than one shipper Machine, also set `QUEUE = "org-logs"`, so that each line goes to one Machine only.

## 3. Add the sink

### Built-in HTTP sink

Set the two secrets, then deploy:

```bash
fly secrets set HTTP_URL='https://api.send2bucket.com/v1/events/json?stream=<stream_id>' HTTP_TOKEN=<key>
fly deploy --no-public-ips
```

The shipper turns a sink on when the secrets it reads are set. These two turn on its `http` sink:

```toml
[sinks.http]
  type = "http"
  inputs = ["log_json"]
  uri = "${HTTP_URL}"
  encoding.codec = "json"
  auth.strategy = "bearer"
  auth.token = "${HTTP_TOKEN}"
```

- The key goes in `Authorization: Bearer`. The sink cannot set other headers, so the stream goes in the `stream` query parameter; leave it out if the key writes to one stream.
- Vector sends a batch every second, as a JSON array or NDJSON. The drain takes both. The body is not compressed.
- A batch holds up to about 10 MB of events, Vector's default, and a request above 8 MiB is rejected with a `413`, which Vector drops. This only happens above roughly 8 MB of logs a second; past that, use a custom sink with a smaller batch.

### Custom HTTP sink

Write your own `vector.toml`. It replaces the shipper's, so it keeps the shipper's NATS source and `log_json` transform, and adds a sink for Send2Bucket:

```toml
[api]
  enabled = true
  address = "[::]:8686"

[sources.nats]
  type = "nats"
  url = "nats://[${NETWORK-fdaa}::3]:4223"
  queue = "${QUEUE-}"
  subject = "${SUBJECT-logs.>}"
  auth.strategy = "user_password"
  auth.user_password.user = "${ORG-personal}"
  auth.user_password.password = "${ACCESS_TOKEN?}"
  connection_name = "Fly logs stream"

[transforms.log_json]
  type = "remap"
  inputs = ["nats"]
  source = '''
  . = parse_json!(.message)
  '''

[sinks.s2b]
  type = "http"
  inputs = ["log_json"]
  uri = "https://api.send2bucket.com/v1/events/json"
  encoding.codec = "json"
  framing.method = "newline_delimited"
  compression = "gzip"
  auth.strategy = "bearer"
  auth.token = "${S2B_API_KEY}"
  request.headers.S2b-Stream = "${S2B_STREAM}"
  batch.max_bytes = 4000000
```

Set the key and stream as secrets, and deploy with the file in place of the shipper's:

```bash
fly secrets set S2B_API_KEY=<key> S2B_STREAM=<stream_id>
fly deploy --no-public-ips --file-local="/etc/vector/vector.toml=./vector.toml"
```

- The body is NDJSON with `Content-Encoding: gzip`. Send2Bucket bills the decompressed size either way; gzip makes the requests smaller.
- `batch.max_bytes` keeps each request well under the 8 MiB limit.
- Leave out the `S2b-Stream` line, and the `S2B_STREAM` secret, if the key writes to one stream.
- Do not also set `HTTP_URL`, or the built-in sink sends every line a second time.

To drop lines before they are sent, and billed, add a `filter` transform and point the sink's `inputs` at it:

```toml
[transforms.s2b_filter]
  type = "filter"
  inputs = ["log_json"]
  condition = '.log.level != "debug"'
```

### Beside another sink

Each sink the shipper turns on reads every line. To keep another vendor and send everything to your bucket as well, set that vendor's secrets, such as `DATADOG_API_KEY`, next to `HTTP_URL` and `HTTP_TOKEN`, and deploy. The [shipper's README](https://github.com/superfly/fly-log-shipper) lists the secrets for each sink.

Vector retries a `429` or `5xx` without limit and waits for every sink, so one sink that stays down holds up the others.

## 4. Check the sink

Check the key and stream with one request. It stores one record, and the answer is a `200` with an empty body:

```bash
curl -i 'https://api.send2bucket.com/v1/events/json?stream=<stream_id>' \
  -H "Authorization: Bearer $S2B_API_KEY" \
  --data-binary '{"log":{"level":"info"},"message":"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. Vector drops a batch that gets any of these, without retrying, so lines are lost until the problem is fixed. The [API reference](../api-reference.md#log-drains) lists every error.

After the deploy, `fly logs` on the shipper app prints `Configured sinks:` followed by the sinks it turned on: `http` for the built-in sink. `fly checks list` shows the health check.

## 5. Query the logs

[DuckDB](../querying/duckdb.md) reads the objects in place. This view keeps the Fly logs; the `stream` column comes from the object path:

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

CREATE VIEW fly_logs 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 stream = '<stream_id>';
```

Lines and errors per app:

```sql
SELECT data->>'$.fly.app.name' AS app,
       count(*) AS lines,
       count(*) FILTER (WHERE data->>'$.log.level' = 'error') AS errors
FROM fly_logs
GROUP BY ALL
ORDER BY lines DESC;
```

The latest lines from one app, with the region and Machine that wrote them:

```sql
SELECT CAST(data->>'$.timestamp' AS TIMESTAMPTZ) AS logged_at,
       data->>'$.fly.region' AS region,
       data->>'$.fly.app.instance' AS machine,
       data->>'$.message' AS message
FROM fly_logs
WHERE data->>'$.fly.app.name' = '<app>'
ORDER BY logged_at DESC
LIMIT 50;
```

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

## Notes

- **Size**: a request can be up to 8 MiB decompressed; records have no size limit of their own.
- **Billing**: the decompressed request body is the number billed, so a `filter` transform in a custom sink is the way to pay for fewer lines.
- **Retries**: Vector retries a `429` or `5xx`, and Send2Bucket stores a retried batch again. Fly records carry no ID, so to drop repeats, group on `timestamp`, `fly.app.instance` and `message` in your query. See [Retries](../api-reference.md#retries).
- **Other platforms**: [Log drains](./log-drains.md) covers Vercel, Heroku, Supabase, Cloudflare and other platforms.
