OpenTelemetry Collector Persistent Queue Setup

Set up an OpenTelemetry Collector persistent queue with file_storage and sending_queue, mount durable disk, run a kill test, and see where spans still get lost.

Ephraim Duncan

To set up an OpenTelemetry Collector persistent queue, add the file_storage extension, point an exporter's sending_queue.storage at it, and put the storage directory on a disk that outlives the Collector process. Batches waiting to be exported then survive a restart instead of vanishing with memory.

That is the whole mechanism. The rest of this guide is the YAML, the Docker and Kubernetes mounts, a kill test you can run in five minutes, and an honest list of where spans still get lost. Persistence helps with restarts and backend outages. It is not a delivery guarantee, and treating it like one is how teams end up surprised.

What a persistent queue protects (and what it doesn't)

A persistent queue protects data that has been accepted by your exporter but not yet delivered to the backend, across a Collector crash or restart. By default the exporter's sending queue lives in memory, so a restart empties it. The Collector docs describe persistent storage as a write-ahead log that guards against data loss when the instance itself crashes or restarts.

What it does not protect: data that never reached the queue, data dropped because the queue was full, and data lost on a disk that dies with the node. We cover those cases below.

If you run AI apps or agents, this matters more than usual. A single agent run can emit dozens of spans, and the failed run you most want to inspect is often the one that coincided with a deploy or a backend blip.

Configure file_storage and sending_queue.storage

You need two pieces: a file_storage extension instance, and a storage reference on the exporter's sending_queue. The exporterhelper README lists the persistent queue as a sending_queue setting that points at a storage extension ID.

extensions:
  file_storage/queue:
    directory: /var/lib/otelcol/queue
    create_directory: true
    fsync: true
    compaction:
      on_start: true
      on_rebound: true
      directory: /var/lib/otelcol/compaction

receivers:
  otlp:
    protocols:
      http:

exporters:
  otlp:
    endpoint: otel-backend:4317
    sending_queue:
      enabled: true
      storage: file_storage/queue

service:
  extensions: [file_storage/queue]
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [otlp]

Three details trip people up. First, the extension must be listed under service.extensions, or the Collector will not load it. Second, the value of storage is the extension's full ID, including the /queue suffix. Third, the directory must be writable by the Collector's user; create_directory: true will make it if missing, but not fix permissions.

The file_storage extension stores data with bbolt, and names each file after the component using it.

Put the queue on a durable mount (Docker volume, Kubernetes PVC)

The queue directory only helps if it survives the container. A path inside the container's writable layer disappears when the container is recreated, which defeats the point.

In Docker, mount a named volume at the queue path:

services:
  otelcol:
    image: otel/opentelemetry-collector-contrib:latest
    volumes:
      - otelcol-queue:/var/lib/otelcol
      - ./config.yaml:/etc/otelcol-contrib/config.yaml
volumes:
  otelcol-queue:

In Kubernetes, use a StatefulSet with a volumeClaimTemplate so each replica keeps its own persistent volume across pod restarts:

volumeClaimTemplates:
  - metadata:
      name: queue
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: 10Gi

Mount it at /var/lib/otelcol in the container spec. Prefer a StatefulSet over a Deployment here. Deployment replicas sharing one claim, or getting a fresh emptyDir on reschedule, are the two most common ways teams think they have persistence and don't. Also confirm the container's user can write to the volume; a fsGroup in the pod security context usually solves that.

Verify a restart locally with synthetic spans

Prove it before you trust it. The test: make the backend unreachable so spans pile up in the queue, kill the Collector, restart it, bring the backend back, and count what arrives.

  1. Point the exporter at an endpoint that is down (a closed port works). Keep the persistent config and the volume from above.

  2. Start the Collector and send a known number of spans, for example 200, using telemetrygen or any OTLP client:

telemetrygen traces --otlp-insecure --otlp-endpoint localhost:4318 --otlp-http --traces 200
  1. Confirm the queue file exists and has grown in your queue directory.

  2. Kill the Collector hard: docker kill otelcol (or kubectl delete pod --grace-period=0 --force). A hard kill is the realistic case.

  3. Start a backend that accepts OTLP, restart the Collector, and watch the received span count.

If the count lands at 200, the queue persisted. Now run the same test with storage removed from sending_queue. The count drops to zero. That before/after is your proof, and it takes minutes.

If you want to see the replayed spans as traces rather than counters, point the exporter at telemetry.dev, which accepts standard OTLP/HTTP from any OpenTelemetry Collector, and check that the synthetic run shows up once the Collector comes back.

Tune and size it: fsync, compaction, queue size and disk space

Four knobs matter.

fsync: Setting fsync: true syncs each database write to disk, which is the safer option after a hard kill or power loss, at a performance cost. If you can tolerate losing the last few writes, leave it off and measure throughput first.

Compaction: bbolt files do not shrink on their own after the queue drains. Configuring compaction helps reclaim space, and you should ensure the compaction directory has sufficient free space to operate.

Queue size: sending_queue.queue_size caps how many batches wait. Set it from your outage tolerance. If a backend can be down for 30 minutes and you export N batches per minute, you want roughly 30 times N, plus headroom.

Disk space: size the volume for the full queue plus compaction scratch space. A queue that fills the disk fails worse than a queue that fills its limit. Alert on volume usage, not just queue depth.

Persistence is not a delivery guarantee: remaining loss cases

A persistent queue narrows the loss window. It does not close it. The Collector resiliency docs list the circumstances where data loss can still occur, and recommend message queues for the highest level of resilience between tiers.

Cases that persistence does not cover:

  • Spans in flight between the receiver and the queue when the process dies.

  • Spans dropped because the queue hit queue_size. Persistent queues still have a cap.

  • Retries that exhaust. Retry-on-failure has its own limits, so data can be dropped after the retry window ends.

  • A lost volume. If the node or disk is gone, so is the queue.

  • Spans lost upstream, in your app's SDK buffer, before they ever reach the Collector.

  • Sampling or processors that drop spans before the exporter.

So say it plainly in your runbook: persistence survives restarts, it does not guarantee delivery. If you need stronger guarantees across tiers, put a message queue between them. For tracing a drop to its cause, see OpenTelemetry Collector Dropped Spans: Find the Drop.

Troubleshooting: full queues, one storage per exporter, and permissions

Most persistent queue problems are one of three things.

Queue full. If the backend stays down longer than your queue can absorb, new batches are refused. Raise queue_size only if the disk can hold it, and fix the backend. Our walkthrough OpenTelemetry Collector Sending Queue Full: What to Check covers the diagnosis step by step.

One storage per exporter. Do not share a single file_storage instance across several exporters. The extension names its file from the component's type and name, and each queue should have its own storage. Declare file_storage/traces and file_storage/metrics, and reference each from the matching exporter.

Permissions. A Collector that cannot write to the directory fails at startup or silently loses persistence. Check the directory owner against the container user, and check that the volume is actually mounted where the config says. A wrong mount path is the classic cause of a queue that works in testing and is empty after a restart.

When something looks off, inspect the queue file size on disk. If it never grows during a backend outage, the exporter is not using your storage.

Run the kill test, then trace the replayed spans

Wire sending_queue.storage to file_storage, mount the directory on a volume that outlives the pod, and prove it with a hard kill and 200 synthetic spans before you rely on it. Then be honest in your runbook: you bought restart survival, not guaranteed delivery. If you are sending AI app and agent telemetry, point your Collector's OTLP/HTTP exporter at telemetry.dev, start on the free plan, and confirm the spans from your restart test show up as traces.

Share this article

Related posts