# Send application events and OpenTelemetry to Cloudflare R2

Send JSON events over HTTP or export telemetry over OTLP to Send2Bucket. It writes gzip NDJSON objects to your Cloudflare R2 bucket through the S3 API, partitioned by date and hour. You’ll need an R2 bucket and an API token.

## Logpush or Send2Bucket?

Search for "send logs to R2" and you find [Cloudflare Logpush](https://developers.cloudflare.com/logs/logpush/). Logpush exports logs that Cloudflare produces about your traffic, such as HTTP requests, firewall events and Workers trace events, and [R2 is one of its destinations](https://developers.cloudflare.com/logs/logpush/logpush-job/enable-destinations/r2/). It does not accept records from your own code.

| You want in R2 | Use |
|---|---|
| Cloudflare's request, firewall or Workers trace logs | Logpush |
| Your application's events, such as `order.paid` or `signup`, as JSON | Send2Bucket `POST /v1/events` |
| Logs, traces and metrics from OpenTelemetry SDKs or a Collector | Send2Bucket's OTLP endpoint |

Both can write to the same bucket under different prefixes.

## How it works

```text
curl, SDK or Collector ──HTTPS──▶ api.send2bucket.com ──S3 API──▶ <account_id>.r2.cloudflarestorage.com/<bucket>/<prefix>/s2b/…
```

- A `204` for JSON, or a `200` or gRPC `OK` for OTLP, means the batch is stored durably and will be delivered at least once. See [Delivery semantics](../delivery-semantics.md).
- Send2Bucket writes an object when a delivery batch reaches 16 MiB, or after 10 seconds on Free and 60 seconds on the other plans, whichever comes first.
- Objects sit under `date=YYYY-MM-DD/hour=HH/` folders, so a query for one day reads only that day's objects. [Delivery format](../delivery-format.md) has the full layout.

## 1. Create the bucket and an API token

Create the bucket in the Cloudflare dashboard, or with Wrangler as [Create buckets](https://developers.cloudflare.com/r2/buckets/create-buckets/) shows:

```bash
wrangler r2 bucket create <bucket>
```

Then create an API token, following [R2 authentication](https://developers.cloudflare.com/r2/api/tokens/):

1. On the **R2 object storage** page, open **Overview** and select **Manage** next to **API Tokens**.
2. Select **Create Account API token**. An account token keeps working if the person who made it leaves the account.
3. Under **Permissions**, choose **Object Read & Write** and scope the token to the bucket.
4. Create the token and copy the **Access Key ID** and **Secret Access Key**. Cloudflare shows the secret only once.

Your account ID is in the dashboard too. The S3 endpoint is `https://<account_id>.r2.cloudflarestorage.com`; a bucket created in a jurisdiction uses that jurisdiction's endpoint, such as `https://<account_id>.eu.r2.cloudflarestorage.com`.

## 2. Add R2 as a destination

Create an ingestion stream in the [dashboard](pathname:///app/) and add an [S3-compatible destination](../destinations/s3-compatible.md):

| Field | Value for R2 |
|---|---|
| `bucket` | `<bucket>` |
| `endpoint` | `https://<account_id>.r2.cloudflarestorage.com` |
| `region` | `auto`. [R2's S3 API](https://developers.cloudflare.com/r2/api/s3/api/) also treats an empty value and `us-east-1` as `auto`. |
| `prefix` | `raw`, or any folder name |
| `addressing` | `path`, the default. R2 accepts both styles; Cloudflare's [presigned URL examples](https://developers.cloudflare.com/r2/api/s3/presigned-urls/) show each. |
| `access_key_id`, `secret_access_key` | The token's Access Key ID and Secret Access Key |

Select Verify. Send2Bucket writes a test object under `raw/s2b/_verify/` and reads it back, and the destination becomes `active`. Copy the stream's API key when the dashboard shows it:

```bash
export S2B_API_KEY=s2b_ingest_...
```

## 3. Send JSON events

`POST /v1/events` takes one JSON object or an array of objects. Each object is stored unchanged as one line:

```bash
curl -sS -w '%{http_code}\n' https://api.send2bucket.com/v1/events \
  -H "Authorization: Bearer $S2B_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '[{"event":"order.paid","order_id":"ord_20931","cents":4200},
       {"event":"signup","user_id":"usr_0042","plan":"free"}]'
```

```text
204
```

A `204` with an empty body means stored. The whole request is accepted or rejected; one invalid item rejects all of it. A request can be up to 8 MiB decompressed. The [API reference](../api-reference.md#post-events) lists every error code.

## 4. Send OpenTelemetry

OpenTelemetry SDKs read the standard exporter variables, so a service that already exports OTLP needs no code change:

```bash
export OTEL_SERVICE_NAME=checkout
export OTEL_EXPORTER_OTLP_ENDPOINT=https://api.send2bucket.com
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer%20$S2B_API_KEY"
```

The SDK appends `/v1/traces`, `/v1/logs` and `/v1/metrics`. `http/protobuf` and `http/json` both work. gRPC works too, at the endpoint in the [API reference](../api-reference.md#otlp-grpc).

If services already export to a Collector, add an `otlphttp` exporter and list it in each pipeline:

```yaml
receivers:
  otlp:
    protocols:
      grpc:
      http:

exporters:
  otlphttp/s2b:
    endpoint: https://api.send2bucket.com
    headers:
      authorization: Bearer ${env:S2B_API_KEY}
    compression: gzip

service:
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [otlphttp/s2b]
    logs:
      receivers: [otlp]
      exporters: [otlphttp/s2b]
    metrics:
      receivers: [otlp]
      exporters: [otlphttp/s2b]
```

Collector 0.165.0 logs a warning that the `otlphttp` name is deprecated in favour of `otlp_http`; both work there. [OpenTelemetry to Amazon S3](./opentelemetry-to-s3.md) covers the same setup in more detail, and its queries run unchanged on R2 once the DuckDB secret below is in place.

## 5. Check the objects arrived

Cloudflare documents the [AWS CLI with R2](https://developers.cloudflare.com/r2/examples/aws/aws-cli/): run `aws configure` with the token's keys and region `auto`, then pass the R2 endpoint on each command. Use a token with **Object Read** to list, not the one Send2Bucket writes with:

```bash
aws s3 ls s3://<bucket>/raw/s2b/ --recursive --endpoint-url https://<account_id>.r2.cloudflarestorage.com | tail -3
```

```text
2026-11-23 00:38:12        276 raw/s2b/stream=<stream_id>/date=2026-11-23/hour=00/dlv_00361pmf1hu4r6dbj9j71npsqc4h0.ndjson.gz
2026-11-23 00:38:27        935 raw/s2b/stream=<stream_id>/date=2026-11-23/hour=00/dlv_00361pmfu5f3ea8tfudlpeub1mghe.ndjson.gz
2026-11-23 00:38:51        601 raw/s2b/stream=<stream_id>/date=2026-11-23/hour=00/dlv_00361pmhbu9uvan78vnlp74qs926s.ndjson.gz
```

For rclone, Cloudflare's [rclone example](https://developers.cloudflare.com/r2/examples/rclone/) has the remote configuration; with a bucket-scoped token, add `no_check_bucket = true` as it says. If nothing arrives, open the stream in the dashboard: it shows the destination's status and last error. A token that R2 refuses turns the destination `blocked`; batches are kept, and delivery resumes after you verify again ([Delivery semantics](../delivery-semantics.md)).

## 6. Query the objects

[DuckDB](../querying/duckdb.md#s3-compatible-storage) reads R2 with an S3 secret that carries the endpoint. Use a read-only token here as well:

```sql
INSTALL httpfs; LOAD httpfs;
CREATE SECRET s2b_bucket (
  TYPE s3, KEY_ID '<access_key_id>', SECRET '<secret_access_key>',
  REGION 'auto', ENDPOINT '<account_id>.r2.cloudflarestorage.com');

CREATE VIEW records AS
SELECT * FROM read_json(
  's3://<bucket>/raw/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'});

CREATE MACRO service(resource) AS (
  SELECT a->>'$.value.stringValue'
  FROM unnest(json_extract(resource, '$.attributes[*]')) AS t(a)
  WHERE a->>'$.key' = 'service.name');
```

Events by name today, with revenue from `cents`:

```sql
SELECT data->>'$.event' AS event, count(*) AS events,
       sum((data->>'$.cents')::BIGINT) / 100 AS revenue
FROM records
WHERE signal = 'event' AND date = current_date
GROUP BY ALL
ORDER BY events DESC;
```

OpenTelemetry records per service and signal:

```sql
SELECT service(resource) AS service, signal, count(*) AS records
FROM records
WHERE signal IN ('log', 'span', 'metric') AND date = current_date
GROUP BY ALL
ORDER BY service, signal;
```

Everything one trace recorded, spans and logs together:

```sql
SELECT signal,
       make_timestamp_ns(coalesce(data->>'$.startTimeUnixNano', data->>'$.timeUnixNano')::BIGINT) AS ts,
       coalesce(data->>'$.name', data->>'$.body.stringValue') AS what,
       data->>'$.severityText' AS severity
FROM records
WHERE data->>'$.traceId' = '<trace_id>'
ORDER BY ts;
```

```text
┌─────────┬───────────────────────────────┬────────────────┬──────────┐
│ signal  │              ts               │      what      │ severity │
├─────────┼───────────────────────────────┼────────────────┼──────────┤
│ span    │ 2026-11-23 00:38:23.743983134 │ POST /orders   │ NULL     │
│ log     │ 2026-11-23 00:38:23.744024064 │ order received │ INFO     │
│ span    │ 2026-11-23 00:38:23.74442215  │ charge card    │ NULL     │
│ log     │ 2026-11-23 00:38:23.794593024 │ card declined  │ ERROR    │
└─────────┴───────────────────────────────┴────────────────┴──────────┘
```

These guides also show the R2 settings for their engine: [ClickHouse](../querying/clickhouse.md), [Apache Spark](../querying/spark.md), [StarRocks](../querying/starrocks.md), [Dremio](../querying/dremio.md), [Databricks](../querying/databricks.md) and [Python](../querying/python.md). Each record's envelope is described in [Delivery format](../delivery-format.md).

## Limits and costs

- **Send2Bucket.** A request can be up to 8 MiB decompressed. Send2Bucket bills the stored JSON of each record it accepts; see [Plans and billing](../plans-and-billing.md). It does not deduplicate retried requests ([Retries](../api-reference.md#retries)).
- **R2 operations.** Each object is one `PutObject`, a Class A operation; verification and retries add `HeadObject`, a Class B operation. A busy stream on a 60-second timer writes about 1,440 objects a day, roughly 45,000 a month.
- **R2 price.** From [R2 pricing](https://developers.cloudflare.com/r2/pricing/) for Standard storage: $0.015 per GB-month, $4.50 per million Class A and $0.36 per million Class B operations, with 10 GB-month, 1 million Class A and 10 million Class B free each month. Data read through the S3 API has no egress charge, so an engine outside Cloudflare pays R2 only for the requests.
- **R2 limits.** [R2 limits](https://developers.cloudflare.com/r2/platform/limits/) allow 5 GiB per single upload and 1,024-byte keys; Send2Bucket's objects are at most 16 MiB before compression, with keys well under that.
- **Retention.** Send2Bucket never deletes objects. Add an [object lifecycle rule](https://developers.cloudflare.com/r2/buckets/object-lifecycles/) on `raw/s2b/` to delete them, or move them to Infrequent Access, after a number of days. Infrequent Access bills at least 30 days per object.

## Other ways to get data into R2

- [Cloudflare Pipelines](../compare/send2bucket-vs-cloudflare-pipelines.md): much cheaper per GB when the data can stay in R2, and adds SQL transforms, but has no OTLP endpoint.
- [Cloudflare Logpush](https://developers.cloudflare.com/logs/logpush/): for Cloudflare's own logs, as above.
- Write your own producer with an S3 SDK and the R2 endpoint: you handle batching, retries and object naming.
