# Delivery format

Amazon S3, Google Cloud Storage, Azure Blob Storage and S3-compatible destinations use the same object layout. Table destinations use the four columns listed below.

## Object keys

Each delivery batch is one gzip-compressed NDJSON object:

```text
<prefix>/s2b/stream=<stream_id>/date=YYYY-MM-DD/hour=HH/<delivery_batch_id>.ndjson.gz
```

- `<prefix>` is the prefix you configured for the destination.
- `<stream_id>` is the stream's UUID. Streams that share a destination write to their own `stream=` folders, and each object holds one stream's records.
- `date` and `hour` are the UTC hour in which Send2Bucket received the records.
- A delivery batch is written when it reaches 16 MiB of uncompressed data or when its oldest batch has waited the stream's flush interval, whichever comes first. The interval is 10 seconds on Free and 60 seconds on Trial, Pro and Team, unless the stream sets its own, from 10 to 60 seconds, on its dashboard page or with `flush_seconds` in the [Management API](./management-api.md). A quiet stream is still delivered on the timer.
- The key and the contents of an object never change between retries. A retry writes identical bytes under the same key, or confirms that the object already written belongs to the same delivery batch.

The `key=value` path segments work as Hive-style partitions in [DuckDB](./querying/duckdb.md), [Spark](./querying/spark.md), [Athena](./querying/athena.md) and other engines.

## The envelope

Each line is one record wrapped in an envelope:

```json
{"v":1,"delivery_batch_id":"dlv_01jd3kb7m4","stream_id":"4f1c2b9e-8d3a-4e7b-9c51-0a6f2d8e3b17","batch_id":"bat_01jd3k9qx2","received_at":"2026-11-19T03:04:05.123456Z","signal":"event","data":{"event":"order.paid","order_id":"ord_20931","cents":4200}}
```

| Field | Type | Meaning |
|---|---|---|
| `v` | number | Envelope version, currently `1`. |
| `delivery_batch_id` | string | The object or table commit this line belongs to (`dlv_…`). |
| `stream_id` | string | The stream that received the record. Streams can share a destination, so this tells their records apart. |
| `batch_id` | string | The batch that carried the record (`bat_…`): one per request, or one per stream in the [batch format](./api-reference.md#batch-format). |
| `received_at` | string | When Send2Bucket accepted the request, RFC 3339 in UTC with microseconds. |
| `signal` | string | `event`, `log`, `span`, `metric` or `series`, or `aggregate` for a row of [stream aggregation](./aggregation.md). |
| `resource` | object | OTLP only. The resource of the record. |
| `scope` | object | OTLP only. The instrumentation scope of the record. |
| `data` | object | The record. |

### JSON events

`data` is the object you sent, unchanged: same keys, same values, same nesting. A stream with a [transform](./transforms.md) delivers `data` as its program leaves it.

### Log drains

Records from a [log drain](./api-reference.md#log-drains) have `signal` `log` and no `resource` or `scope`. A record that arrives as a JSON object is kept as the platform sent it: same keys, same values, same nesting. That covers `/v1/events/json`, Vercel, Convex events and the Cloud Logging `LogEntry` of a Pub/Sub message. Supabase drains send OpenTelemetry, so their lines are [OpenTelemetry records](#opentelemetry-records).

#### Heroku

A Heroku syslog message becomes an object with these fields:

| Field | Type | Meaning |
|---|---|---|
| `priority` | number | Syslog priority: facility × 8 + severity. |
| `timestamp` | string or null | When the line was logged, RFC 3339, as Heroku sent it. |
| `hostname` | string or null | Heroku sends `host`. |
| `app_name` | string or null | `app` for your processes, `heroku` for the platform's own lines. |
| `proc_id` | string or null | The dyno or component, such as `web.1` or `router`. |
| `msg_id` | string or null | Usually null. |
| `message` | string | The log line without its trailing newline. Bytes that are not valid UTF-8 become U+FFFD. |

A syslog `-` (no value) becomes null.

```json
{"v":1,"delivery_batch_id":"dlv_01jd3kd7q2","stream_id":"4f1c2b9e-8d3a-4e7b-9c51-0a6f2d8e3b17","batch_id":"bat_01jd3kcw0m","received_at":"2026-11-19T03:04:09.200114Z","signal":"log","data":{"priority":40,"timestamp":"2026-11-19T03:04:08+00:00","hostname":"host","app_name":"app","proc_id":"web.1","msg_id":null,"message":"State changed from starting to up"}}
```

#### Amazon Data Firehose

A CloudWatch Logs record becomes one line per log event. `data` holds `owner`, `logGroup`, `logStream` and `subscriptionFilters` from the record, then the event's `id`, `timestamp` (Unix milliseconds) and `message`:

```json
{"v":1,"delivery_batch_id":"dlv_01jd3ke1v7","stream_id":"4f1c2b9e-8d3a-4e7b-9c51-0a6f2d8e3b17","batch_id":"bat_01jd3kdz4k","received_at":"2026-11-19T03:04:10.512007Z","signal":"log","data":{"owner":"111111111111","logGroup":"/aws/lambda/checkout","logStream":"2026/11/19/[$LATEST]5d1f","subscriptionFilters":["to-send2bucket"],"id":"38604851629213928163527192837","timestamp":1763521449000,"message":"START RequestId: 6f2d Version: $LATEST"}}
```

Any other record becomes one line per JSON object it holds. Text becomes one line per line, as `{"message":"<line>"}`, with bytes that are not valid UTF-8 replaced by U+FFFD.

#### Google Cloud Pub/Sub

`data` is the message data: for a Cloud Logging sink, the `LogEntry` as Google sent it. Data that is not a JSON object becomes `{"message":"<text>"}`. The message's attributes, ID and publish time are not kept.

### Datadog

Lines from [Datadog clients](./api-reference.md#datadog) have no `resource` or `scope`.

- **Logs** (`signal` `log`) are kept as the client sent them, such as the Agent's `message`, `status`, `timestamp`, `hostname`, `service`, `ddsource` and `ddtags`, or the browser SDK's log object.
- **Metric series** (`signal` `metric`) sent as JSON are kept as sent: API v1 series have `points` as `[timestamp, value]` pairs and a `type` name, API v2 series have `points` as `{"timestamp","value"}` objects and a numeric `type`. Protobuf series are written in the v2 JSON shape, with the protobuf's field names: `resources`, `metric`, `tags`, `points`, `type` (`0` unspecified, `1` count, `2` rate, `3` gauge), `unit`, `source_type_name`, `interval` and `metadata`.
- **Sketches** (`signal` `metric`), from distributions, have `metric`, `host`, `tags` and `dogsketches`: per interval, `ts`, `cnt`, `min`, `max`, `avg`, `sum`, and the DDSketch bin keys `k` and counts `n`. The payload's metadata, which holds the client's API key, is not kept.
- **Spans** (`signal` `span`) have the tracer's span fields: `service`, `name`, `resource`, `trace_id`, `span_id`, `parent_id` (unsigned 64-bit numbers), `start` and `duration` (nanoseconds), `error` (`0` or `1`), `meta` (strings), `metrics` (numbers), `type`, and `meta_struct` (base64), `span_links` and `span_events` when sent. Spans from the Agent or the `datadog` exporter also carry `chunk`, `tracer_payload` and `agent_payload`: the trace chunk's sampling `priority` and `origin`, the tracer's language, version, `env` and `hostname`, and the Agent's host and version.

The Agent's string-table spans are written in the same shape: string attributes go to `meta`, along with `env`, `version`, `component` and `span.kind`; numbers go to `metrics` and bytes to `meta_struct`.

```json
{"v":1,"delivery_batch_id":"dlv_01jd3kf3h1","stream_id":"4f1c2b9e-8d3a-4e7b-9c51-0a6f2d8e3b17","batch_id":"bat_01jd3kf1z8","received_at":"2026-11-19T03:04:11.008412Z","signal":"span","data":{"duration":12000000,"error":0,"meta":{"env":"prod","order.id":"o-7"},"metrics":{"_sampling_priority_v1":1.0},"name":"checkout","parent_id":0,"resource":"POST /cart","service":"shop","span_id":11,"start":1763521450000000000,"trace_id":1234567890123,"type":"web"}}
```

### Sentry

Each item of a [Sentry envelope](./api-reference.md#sentry) becomes one line with no `resource` or `scope`. `data` holds:

| Field | Meaning |
|---|---|
| `type` | The item type, such as `event`, `transaction`, `span`, `log`, `attachment`, `session` or `client_report`. |
| `envelope` | The envelope header, such as `event_id`, `sent_at`, `sdk` and `trace`, without its `dsn`. |
| `item` | The item header, such as `type`, `length`, `content_type` and `filename`. |
| `encoding` | `json` when the payload is a JSON object, else `base64`. |
| `payload` | The payload: the object as the SDK sent it, or its bytes in base64. |

`signal` is `log` for `log` and `otel_log` items, `span` for `transaction` and `span`, `metric` for `trace_metric`, `statsd` and `metric_buckets`, and `event` for the rest. A container item, whose `content_type` starts with `application/vnd.sentry.items.`, becomes one line per entry of its `items`, with that entry as `payload`.

```json
{"v":1,"delivery_batch_id":"dlv_01jd3kg8m4","stream_id":"4f1c2b9e-8d3a-4e7b-9c51-0a6f2d8e3b17","batch_id":"bat_01jd3kg6q0","received_at":"2026-11-19T03:04:12.300125Z","signal":"event","data":{"type":"event","envelope":{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"},"item":{"type":"event"},"encoding":"json","payload":{"message":"hello from curl","level":"info"}}}
```

### PostHog

Each event a [PostHog SDK](./api-reference.md#posthog) sends becomes one line with `signal` `event` and no `resource` or `scope`. `data` is the event as the SDK sent it, such as `event`, `distinct_id`, `properties`, `timestamp` and `uuid`, without the project token: `api_key`, `token`, `$token` and `properties.token` are removed. Session recordings are `$snapshot` events whose `properties.$snapshot_data` holds the recorded snapshots.

```json
{"v":1,"delivery_batch_id":"dlv_01jd3khb2q","stream_id":"4f1c2b9e-8d3a-4e7b-9c51-0a6f2d8e3b17","batch_id":"bat_01jd3kh9t6","received_at":"2026-11-19T03:04:13.104433Z","signal":"event","data":{"event":"order_paid","distinct_id":"user-42","properties":{"cents":4200,"$lib":"posthog-python"},"timestamp":"2026-11-19T03:04:12.981000+00:00","uuid":"0193a2f4-6c1e-7d2b-9f3a-5e8c1b7d4a20"}}
```

### OpenTelemetry records

Each log record, span or metric becomes one line. `data` is the [OTLP JSON mapping](https://opentelemetry.io/docs/specs/otlp/#json-protobuf-encoding) of the `LogRecord`, `Span` or `Metric`, and `resource` and `scope` are copied onto every line, so a line can be read on its own. In that mapping:

- 64-bit integers, such as `startTimeUnixNano`, are JSON strings, so no precision is lost.
- Trace and span IDs are lowercase hex strings.
- Field names are lowerCamelCase and enums are integers.

```json
{"v":1,"delivery_batch_id":"dlv_01jd3kc2r8","stream_id":"4f1c2b9e-8d3a-4e7b-9c51-0a6f2d8e3b17","batch_id":"bat_01jd3kbz51","received_at":"2026-11-19T03:04:07.481920Z","signal":"span","resource":{"attributes":[{"key":"service.name","value":{"stringValue":"checkout"}}]},"scope":{"name":"checkout.http","version":"1.4.0"},"data":{"traceId":"5b8efff798038103d269b633813fc60c","spanId":"eee19b7ec3c1b174","name":"POST /orders","kind":2,"startTimeUnixNano":"1763521447100000000","endTimeUnixNano":"1763521447181000000","attributes":[{"key":"http.response.status_code","value":{"intValue":"201"}}],"status":{}}}
```

Metrics keep their name, unit, type, temporality, monotonicity, exemplars and every data point, including histogram buckets, exponential histogram scales and summary quantiles.

### Prometheus series

Each time series in a [remote write](./api-reference.md#prometheus-remote-write) request becomes one line with `signal` `series` and no `resource` or `scope`. `data` holds:

| Field | Meaning |
|---|---|
| `labels` | Object of label name to value, `__name__` included. |
| `samples` | Array of `{"timestamp", "value"}`, plus `"startTimestamp"` when a 2.0 sender sets it. Timestamps are milliseconds since the epoch, as strings. |
| `exemplars` | Present when sent: `{"labels", "timestamp", "value"}`. |
| `histograms` | Present when sent: native histograms in the protobuf JSON mapping of `prometheus.Histogram` (1.0) or `io.prometheus.write.v2.Histogram` (2.0), every field included. |
| `metadata` | 2.0 only, present when sent: `{"type", "help", "unit"}`, each when set. `type` is `counter`, `gauge`, `histogram`, `gaugehistogram`, `summary`, `info` or `stateset`. |

Values are numbers, or `"NaN"`, `"Infinity"` and `"-Infinity"`. Prometheus staleness markers arrive as `"NaN"`.

```json
{"v":1,"delivery_batch_id":"dlv_01jd3kd9w1","stream_id":"4f1c2b9e-8d3a-4e7b-9c51-0a6f2d8e3b17","batch_id":"bat_01jd3kd8t0","received_at":"2026-11-19T03:04:09.201337Z","signal":"series","data":{"labels":{"__name__":"http_requests_total","code":"200","job":"checkout"},"samples":[{"timestamp":"1795057449000","value":1027.0}]}}
```

One row per sample in [DuckDB](./querying/duckdb.md):

```sql
SELECT data->>'$.labels.__name__' AS metric,
       data->>'$.labels.job' AS job,
       epoch_ms(CAST(s->>'timestamp' AS BIGINT)) AS at,
       CAST(s->>'value' AS DOUBLE) AS value
FROM read_json('s3://<bucket>/<prefix>/s2b/stream=*/date=*/hour=*/*.ndjson.gz',
               columns = {signal: 'VARCHAR', data: 'JSON'}),
     unnest(CAST(data->'$.samples' AS JSON[])) AS t(s)
WHERE signal = 'series';
```

### Aggregate rows

A stream with [aggregation rules](./aggregation.md) also gets one line per rule, window and group, with `signal` `aggregate`. `data` holds the rule's name, the `source_stream_id` whose records it counted, `window_start`, `window_end`, the `group` values and the outputs, such as `count`, `sum` and `quantiles`. `received_at` is when the window was closed, shortly after `window_end`. A rule with an output stream writes its lines under that stream instead.

## Reading objects

DuckDB reads the gzip files directly:

```sql
SELECT received_at, data->>'event' AS event, data->>'order_id' AS order_id
FROM read_json('s3://analytics-raw/raw/s2b/stream=*/date=*/hour=*/*.ndjson.gz',
               hive_partitioning = true)
WHERE signal = 'event' AND date = '2026-11-19';
```

See [Querying](./querying/index.md) for DuckDB, [Trino](./querying/trino.md), [BigQuery](./querying/bigquery.md), [PostgreSQL](./querying/postgres.md) and [MySQL](./querying/mysql.md).

## Table columns

DuckLake, Apache Iceberg, Amazon S3 Tables and Supabase Analytics Buckets get one row per record:

| Column | Type | Value |
|---|---|---|
| `signal_type` | `VARCHAR` | `event`, `log`, `span`, `metric`, `series` or `aggregate` |
| `delivery_batch_id` | `VARCHAR` | The delivery batch that committed the row |
| `stream_id` | `VARCHAR` | The stream that received the record; streams sharing the table differ here |
| `ingested_at` | `TIMESTAMPTZ` | When Send2Bucket accepted the record |
| `payload` | `VARCHAR` | The envelope above, as JSON text |

Query the payload with your engine's JSON functions:

```sql
SELECT ingested_at, json_extract_string(payload, '$.data.event') AS event
FROM events
WHERE signal_type = 'event';
```

Setup creates the table in the namespace you name, which must already exist. An existing table with these columns is reused. An existing table with other columns is left untouched, and setup fails with `incompatible table: …`.
