# Send Datadog Agent, tracer and Vector data to your own storage

Point your Datadog client at `https://api.send2bucket.com/v1/events/datadog` and configure a Send2Bucket API key. You can keep your existing instrumentation. Each log, metric series and span becomes a separate record in your bucket or table. To keep sending to Datadog as well, configure an additional endpoint where the client supports it.

## How it works

```text
Datadog Agent                ──logs, metrics, traces─┐
Tracers (Python, Go, Java)   ──traces────────────────┤
OTel Collector datadog       ──logs, metrics, traces─┼─▶ /v1/events/datadog ─▶ your stream's destination
Vector datadog sinks         ──logs, metrics─────────┤
Browser SDK proxy            ──logs──────────────────┘
```

- Logs are stored as sent, with `signal` `log`. Each metric series or sketch is a `metric` line, and each span a `span` line in the tracer's span shape. [Delivery format](../delivery-format.md#datadog) lists them.
- Replies follow Datadog's: `202` when stored, `403` for a missing or wrong key. A `2xx` means the data is stored durably and will be delivered at least once.
- Requests Send2Bucket does not store, such as host metadata, check runs, events, process data, APM stats, profiles and tracer telemetry, are answered with `202` and dropped, so clients do not retry them.

## 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. The key goes where the client takes its Datadog API key. A key for several streams also needs the stream ID: add it to the URL as a path segment, `…/v1/events/datadog/<stream_id>`.

## 2. Point the client

### Datadog Agent

Set the Agent's intake URLs in `datadog.yaml`. Logs with a path in `logs_dd_url` need Agent 7.70 or later.

```yaml
api_key: <key>
dd_url: https://api.send2bucket.com/v1/events/datadog
logs_enabled: true
logs_config:
  logs_dd_url: https://api.send2bucket.com/v1/events/datadog
apm_config:
  apm_dd_url: https://api.send2bucket.com/v1/events/datadog
```

The same settings as environment variables are `DD_API_KEY`, `DD_DD_URL`, `DD_LOGS_CONFIG_LOGS_DD_URL` and `DD_APM_DD_URL`.

- Metrics arrive as series API v2 and sketches. The Agent sends series v3 only to Datadog's own URLs unless `use_v3_api.series.enabled` is `true`; leave it unset, since Send2Bucket refuses v3 with a `400`.
- Traces arrive in the string-table format recent Agents send; the older format works too.
- Products that keep their own Datadog URLs, such as the process agent and remote configuration, still send to Datadog. Turn off the ones you do not use.

To keep sending metrics to Datadog and also store them, leave `dd_url` and add Send2Bucket as an additional endpoint:

```yaml
additional_endpoints:
  "https://api.send2bucket.com/v1/events/datadog":
    - <key>
```

### Tracers without an Agent

A tracer can send straight to Send2Bucket. Tracers drop the query string of their agent URL and send no API key, so the key is a path segment:

```bash
export DD_TRACE_AGENT_URL=https://api.send2bucket.com/v1/events/datadog/<key>/
```

- Keep the trailing slash: the Java tracer needs it. A key for several streams takes the stream next: `…/datadog/<key>/<stream_id>/`.
- Without an Agent nothing samples centrally: the tracer keeps every trace at its default rate. Set `DD_TRACE_SAMPLE_RATE` or sampling rules to keep fewer.

:::warning Rotate keys used in tracer URLs often
A key in the URL is exposed more than one in a header: it shows in the process environment, the tracer's debug logs and the access logs of any proxy on the way. Use a key that writes to this one stream only, and rotate it often, for example every 30 days and at once if it may have leaked: create a new key for the stream, update `DD_TRACE_AGENT_URL`, then revoke the old key. Where you can, send traces through an Agent, which sends the key in a header.
:::

The Node.js, Ruby and PHP tracers drop the path of their agent URL, so they cannot reach this endpoint; send their traces through an Agent configured as above. The .NET tracer was not tested.

### OpenTelemetry Collector

The `datadog` exporter takes an endpoint per signal. Logs need otelcol-contrib 0.165 or later; earlier versions post logs to the host root and get a `404`.

```yaml
exporters:
  datadog:
    api:
      key: ${env:S2B_API_KEY}
    logs:
      endpoint: https://api.send2bucket.com/v1/events/datadog
    metrics:
      endpoint: https://api.send2bucket.com/v1/events/datadog
    traces:
      endpoint: https://api.send2bucket.com/v1/events/datadog
    host_metadata:
      enabled: false
```

If you can change the pipeline, the Collector's `otlphttp` exporter to Send2Bucket's [OTLP endpoints](../api-reference.md#otlp-http) keeps the OpenTelemetry data model instead of Datadog's; see [OpenTelemetry to Amazon S3](./opentelemetry-to-s3.md).

### Vector

```toml
[sinks.datadog_logs]
type = "datadog_logs"
inputs = ["app_logs"]
endpoint = "https://api.send2bucket.com/v1/events/datadog"
default_api_key = "${S2B_API_KEY}"

[sinks.datadog_metrics]
type = "datadog_metrics"
inputs = ["app_metrics"]
endpoint = "https://api.send2bucket.com/v1/events/datadog"
default_api_key = "${S2B_API_KEY}"
series_api_version = "v2"
```

Vector versions with `series_api_version` default to series v3, which Send2Bucket refuses with a `400`; set `v2`. Older versions reject the option and send v1 series, which work without it.

### Browser SDK

The logs SDK's `proxy` option sends each request to one URL, with Datadog's path, key and encoding in a `ddforward` parameter. Send2Bucket stores the logs and drops RUM and session replay requests.

```js
datadogLogs.init({
  clientToken: '<key>',
  site: 'datadoghq.com',
  proxy: 'https://api.send2bucket.com/v1/events/datadog/browser',
});
```

The key is visible to anyone who loads the page. Use a key for one stream that holds only browser logs.

## 3. Check the endpoint

Check the key the way the clients do, then send one log. The first answers `{"valid":true}`; the second stores one record and answers `202` with `{}`:

```bash
curl https://api.send2bucket.com/v1/events/datadog/api/v1/validate \
  -H "DD-API-KEY: $S2B_API_KEY"

curl -i https://api.send2bucket.com/v1/events/datadog/api/v2/logs \
  -H "DD-API-KEY: $S2B_API_KEY" \
  -H "Content-Type: application/json" \
  --data '[{"message":"hello from curl","service":"check","status":"info"}]'
```

A `403` means the key is wrong or revoked. The [API reference](../api-reference.md#datadog) lists the other errors.

## 4. Query the data

[DuckDB](../querying/duckdb.md) reads the objects in place:

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

CREATE VIEW datadog 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', data: 'JSON'})
WHERE stream = '<stream_id>';
```

Logs by service and status:

```sql
SELECT data->>'$.service' AS service, data->>'$.status' AS status, count(*) AS logs
FROM datadog
WHERE signal = 'log'
GROUP BY ALL
ORDER BY logs DESC;
```

The points of one metric. Series API v2 points are `{"timestamp","value"}` objects and v1 points `[timestamp, value]` pairs; this reads both:

```sql
SELECT data->>'$.metric' AS metric,
       to_timestamp(CAST(coalesce(p->>'$.timestamp', p->>'$[0]') AS BIGINT)) AS ts,
       CAST(coalesce(p->>'$.value', p->>'$[1]') AS DOUBLE) AS value
FROM datadog, unnest(CAST(data->'$.points' AS JSON[])) AS t(p)
WHERE signal = 'metric' AND data->>'$.metric' = 'queue.depth'
ORDER BY ts DESC
LIMIT 10;
```

Distributions arrive as sketches, which carry their count, sum, minimum and maximum:

```sql
SELECT data->>'$.metric' AS metric,
       sum(CAST(s->>'$.cnt' AS BIGINT)) AS count,
       min(CAST(s->>'$.min' AS DOUBLE)) AS min,
       max(CAST(s->>'$.max' AS DOUBLE)) AS max,
       sum(CAST(s->>'$.sum' AS DOUBLE)) / sum(CAST(s->>'$.cnt' AS BIGINT)) AS avg
FROM datadog, unnest(CAST(data->'$.dogsketches' AS JSON[])) AS t(s)
WHERE signal = 'metric'
GROUP BY ALL
ORDER BY count DESC;
```

The slowest spans. Trace and span IDs are unsigned 64-bit numbers, so cast them to `UBIGINT`:

```sql
SELECT data->>'$.service' AS service,
       data->>'$.resource' AS resource,
       CAST(data->>'$.trace_id' AS UBIGINT) AS trace_id,
       CAST(data->>'$.duration' AS BIGINT) / 1e6 AS ms
FROM datadog
WHERE signal = 'span'
ORDER BY ms DESC
LIMIT 10;
```

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

## Not supported

| Client or request | What happens | Instead |
|---|---|---|
| Fluent Bit's `datadog` output | It takes a host, not a URL with a path. | Fluent Bit's `http` output to [`/v1/events/json`](./log-drains.md) |
| Node.js, Ruby and PHP tracers without an Agent | They drop the URL's path. | Send through an Agent. |
| Series API v3 (Vector's default, or the Agent's `use_v3_api.series.enabled: true`) | `400`, which the client logs and drops. | Series v2 |
| RUM, session replay, profiles, APM stats, host metadata, events, service checks | `202`, not stored. | |

## Notes

- **Billing**: each record's JSON as stored is the number billed. Clients compress with gzip, deflate or zstd; all three work, and none changes it.
- **Sampling**: what the Agent or tracer keeps is what is stored. Spans are not re-sampled.
- **Trace IDs**: 128-bit trace IDs keep their high half in `meta._dd.p.tid`, as Datadog's tracers send it.
- **Retries**: the Agent retries any status above `400` except `403` and `413`; a retried request is stored again. See [Retries](../api-reference.md#retries).
