# How to run an OpenTelemetry collector for client telemetry

> Put a Collector between your services and the backend, with OTLP in, a memory limiter, batching, one exporter, and its own metrics to show that each span arrived.

Source: https://voxgig.com/howto/run-a-collector-for-client-telemetry

- Audience: platform-team
- Level: intermediate
- Verified: 2026-11-30
- Published: 2026-11-30

## Short answer

Run the OpenTelemetry Collector with an OTLP receiver, a pipeline that starts with memory_limiter and batches after it, and one otlp_http exporter to your backend. Point each service's OTLP exporter at the Collector instead of the vendor. The backend, redaction, and sampling then change in one config, and the Collector's own metrics show every span it accepted, sent, or still holds in its queue.

---
## You will need

Node 22.15 or later for the sample, a service instrumented with an OpenTelemetry SDK, and a
backend that accepts OTLP. Verified 2026-11-30 against Node 22.23.5 and the core distribution of
the Collector, `otelcol` 0.166.0, installed from the release tarball the
[Linux install page](https://opentelemetry.io/docs/collector/install/binary/linux/) names. The
service uses `@opentelemetry/sdk-trace` 3.1.1 and `@opentelemetry/exporter-trace-otlp-http`
0.301.2, whose `engines` field asks for Node 22.15.

## Approaches compared

| Approach | When it fits | What it costs you | When to pick something else |
| --- | --- | --- | --- |
| [A central Collector gateway](https://opentelemetry.io/docs/collector/deploy/gateway/) | Many services, one place for credentials, sampling, and redaction | One more service to scale, keep available and give enough memory | A handful of services that already share one host |
| [A Collector agent per host](https://opentelemetry.io/docs/collector/deploy/agent/) | You want host attributes and a local buffer next to each workload | A process on every host or pod, each with its own config to roll out | You run serverless functions with no host to put it on |
| [Direct OTLP export from the application](https://opentelemetry.io/docs/collector/deploy/other/no-collector/) | Development, tests, or one service with one backend | Each backend change, redaction rule or key rotation is a code change in every service | More than one service, or a backend you expect to change |
| [The Datadog Agent](https://docs.datadoghq.com/opentelemetry/setup/otlp_ingest_in_the_agent/) | Datadog is your backend and its Agent already runs on each host | Forwards to Datadog, needs an Agent on every sending host, and some Datadog products do not support upstream SDK data | You want to keep the choice of backend in your own config |

Direct export has the fewest parts, and the records below show it failing the export when
the backend refuses connections. A gateway keeps the backend out of every service, at the price of
one more thing that must stay up. An agent adds `host.name` and a buffer on each host, and
multiplies the configs you roll out. The Datadog Agent is that agent tier with Datadog as the
only destination, enabled with `otlp_config.receiver.protocols.http.endpoint` in `datadog.yaml`.

## Write the pipeline config

The pipeline order is the whole design. `memory_limiter` runs first, so it can refuse data before
anything else holds it. The [batch processor's README](https://github.com/open-telemetry/opentelemetry-collector/blob/v0.166.0/processor/batchprocessor/README.md)
asks for batching after the limiter and after any sampling, because batching should follow every
step that drops data.

```yaml title="collector.yaml"
receivers:
  otlp:
    protocols:
      http:
        endpoint: ${env:OTLP_HTTP_ENDPOINT:-127.0.0.1:4318}

processors:
  memory_limiter:
    check_interval: 1s
    limit_mib: 400
    spike_limit_mib: 80
  transform/redact:
    trace_statements:
      - delete_key(span.attributes, "http.request.header.authorization")
  batch:
    timeout: 200ms

exporters:
  otlp_http:
    endpoint: ${env:BACKEND_ENDPOINT:-http://127.0.0.1:4319}
    encoding: json
```

`limit_mib` is the hard limit and `limit_mib` minus `spike_limit_mib` the soft one, which the
[limiter's README](https://github.com/open-telemetry/opentelemetry-collector/blob/v0.166.0/processor/memorylimiterprocessor/README.md)
defines. Over the soft limit it refuses data. The same README also asks for `GOMEMLIMIT` at 80%
of the Collector's hard memory limit. The redaction uses the
[transform processor](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/v0.166.0/processor/transformprocessor/README.md)
and its `delete_key` function. `encoding: json` suits the stand-in backend here, and the
exporter's default is `proto`. The exporter is spelled `otlp_http` in this release.[^1]

The receiver's fallback address uses 4318, the default port for OTLP over HTTP.[^2] The rest of
the file exposes the Collector's own metrics on 127.0.0.1 with a `pull` reader, as the
[internal telemetry page](https://opentelemetry.io/docs/collector/internal-telemetry/) shows,
and lists the three processors in order.

## Check the order before you deploy

`otelcol validate` checks the config without starting the Collector. It does not check the order
of processors. `check-config.mjs` does, for every pipeline:

```bash
node check-config.mjs collector.yaml agent.yaml
```

```text output
collector.yaml traces: [memory_limiter, transform/redact, batch] ok
agent.yaml traces: [memory_limiter, resource_detection, batch] ok
```

It exits 1 when the limiter is missing, is not first, sets no limit or no `check_interval`, or
when `batch` is missing or runs before it. Run it in the same CI job that runs `otelcol validate`.

## Point the service at the Collector

The service changes one value: the URL its OTLP exporter sends to, which moves from the vendor's
intake to the Collector's receiver.

```ts title="app.mjs"
export async function sendOneSpan(tracesUrl, { timeoutMillis = 3000 } = {}) {
  const exporter = new OTLPTraceExporter({ url: tracesUrl, timeoutMillis })
```

`record.sh` downloads `otelcol` 0.166.0, checks its SHA-256 against the one published beside it,
and starts the Collector, a stand-in backend and the service on loopback ports. The service
records one client span that carries an `Authorization` value on purpose.

## Check it worked

Read what the backend received and what the Collector counted:

```bash
node show.mjs collector
```

```text output
collector: the service exports to the Collector, which exports to the backend
  app export: success
  backend received 1 span
    GET /v1/orders
      resource: service.name=checkout
      attributes: http.request.method=GET, url.full=https://api.example.com/v1/orders, http.response.status_code=200
  Collector metrics:
    otelcol_exporter_queue_capacity{exporter=otlp_http} 1000
    otelcol_exporter_queue_size{exporter=otlp_http} 0
    otelcol_exporter_sent_spans{exporter=otlp_http} 1
    otelcol_receiver_accepted_spans{receiver=otlp,transport=http} 1
    otelcol_receiver_refused_spans{receiver=otlp,transport=http} 0
  Collector log: no warnings
```

`otelcol_receiver_accepted_spans` and `otelcol_exporter_sent_spans` both read `1`, and the span
arrived without `http.request.header.authorization`. The direct-export record kept it. The tests
hold the records to these claims and the configs to the order rule:

```bash
node --test collector.test.mjs
```

```text output
1..10
# tests 10
# suites 0
# pass 10
# fail 0
# cancelled 0
# skipped 0
# todo 0
```

## Hold spans through a backend outage

With the backend down, the same span went to the Collector, and then straight to the closed port:

```bash
node show.mjs outage-collector outage-direct
```

```text output
outage-collector: the backend is down; the service exports to the Collector, which is then stopped
  app export: success
  Collector metrics before it stopped:
    otelcol_exporter_queue_capacity{exporter=otlp_http} 1000
    otelcol_exporter_queue_size{exporter=otlp_http} 1
    otelcol_receiver_accepted_spans{receiver=otlp,transport=http} 1
    otelcol_receiver_refused_spans{receiver=otlp,transport=http} 0
  Collector log:
    info: Exporting failed. Will retry the request after interval. error="failed to make an HTTP request: Post \"http://127.0.0.1:<backend>/v1/traces\": dial tcp 127.0.0.1:<backend>: connect: connection refused"
    error: Exporting failed. Dropping data. error="interrupted due to shutdown: failed to make an HTTP request: Post \"http://127.0.0.1:<backend>/v1/traces\": dial tcp 127.0.0.1:<backend>: connect: connection refused" dropped_items=1
outage-direct: the backend is down; the service exports straight to it
  app export: failed: Error: ECONNREFUSED
```

The Collector accepted the span and queued it for retry, while direct export failed. The
queue is in memory, so stopping the Collector dropped the span. A
[persistent queue](https://github.com/open-telemetry/opentelemetry-collector/blob/v0.166.0/exporter/exporterhelper/README.md#persistent-queue)
needs a storage extension, and this build lists only `health_check`, `pprof` and `zpages`, as
`node show.mjs validate` prints. The
[contrib distribution's manifest](https://github.com/open-telemetry/opentelemetry-collector-releases/blob/v0.166.0/distributions/otelcol-contrib/manifest.yaml)
lists `filestorage`.

The agent tier runs the same way: `agent.yaml` adds `resource_detection`, and the backend
received `host.name` and `os.type` on the span's resource, as `node show.mjs agent-gateway`
prints.

## When it goes wrong

The Collector runs out of memory during a backend outage. The pipeline has no `memory_limiter`,
and the Collector accepts that config:

```bash
node check-config.mjs no-limiter.yaml
```

```text output
no-limiter.yaml traces: [transform/redact, batch] FAIL, memory_limiter is missing
```

`records/validate.txt` holds `otelcol validate no-limiter.yaml: exit 0`, although that file
declares no limiter at all. The same record holds `exit 1` for a pipeline that names a processor
it never configures, so `validate` does refuse what it checks. Only the order check stands
between `no-limiter.yaml` and production.

Every export fails with a retryable status. The limiter is set below what the Collector holds at
rest, so it refuses everything:

```bash
node show.mjs limiter
```

```text output
limiter: memory_limiter with limit_mib 4 and spike_limit_mib 1, below what the Collector holds at rest
  one request with no retry: 503 {"code":14,"message":"data refused due to high memory usage"}
  app export: failed: OTLPExporterError: Export failed with retryable status
  backend received 0 spans
```

The receiver answered 503, which the
[OTLP specification](https://opentelemetry.io/docs/specs/otlp/#otlphttp-response) lists as
retryable. The SDK tried six times, and the counter `otelcol_receiver_refused_spans` reads `7`
with the probe. Size `limit_mib` from the memory the Collector is given, or use
`limit_percentage` in a container.

## When not to do this

Do not put a Collector in front of one service in development. Direct export has fewer parts,
and the failures it hides only matter once there is an outage to buffer through.

Do not count the in-memory queue as durability. It holds data through a backend outage and
loses it on a restart, as the record shows. If losing that window matters, run the contrib
distribution with a persistent queue, and size the disk for it.

Do not run a gateway without two replicas and a memory limit set from the container's limit. It
has become the one path every service's telemetry takes, so it needs the care any shared service
gets.

Skip your own Collector when Datadog is the backend you will keep and its Agent already runs on
every host. Its OTLP receiver covers the same ground with one less process, and the cost is that
the choice of backend moves out of your config.

## Related how-tos

- [Export outbound call spans from a serverless function](/howto/flush-spans-from-a-serverless-function)

- [Redact prompts and tool results in traces before export](/howto/redact-prompts-and-tool-results-in-traces)

- [Emit OpenTelemetry spans from a generated SDK](/howto/emit-opentelemetry-spans-from-a-generated-sdk)

- [Choose the layer that instruments outbound API calls](/howto/choose-a-layer-to-instrument-outbound-calls)

## Last verified

Verified 2026-11-30 against Node 22.23.5. Every output block is what the command preceding it
printed in the page's code directory, from records that `record.sh` wrote with `otelcol` 0.166.0
and the SDK packages in `versions`. The Datadog Agent was not run, and its row is read from its
OTLP ingestion documentation.

[^1]: The [README of the exporter](https://github.com/open-telemetry/opentelemetry-collector/blob/v0.166.0/exporter/otlphttpexporter/README.md)
calls it `otlp_http` and keeps `otlphttp` as a deprecated alias, which it says will be removed
in a future version without naming one. Started with the deprecated spelling, `otelcol` 0.166.0 runs and
logs `"otlphttp" alias is deprecated; use "otlp_http" instead`, a line `record.sh` keeps in
`records/alias.txt`.

[^2]: The [IANA port registry](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv)
lists 4317 as the OpenTelemetry Protocol, registered on 2020-12-09, and 4318 as unassigned. The
[OTLP specification](https://opentelemetry.io/docs/specs/otlp/#otlphttp-default-port) names 4318
as the default port for OTLP over HTTP all the same, one higher than the port OpenTelemetry
registered.