Skip to content
All flows

OpenTelemetry Collector to S3

Writes logs, metrics, and traces to S3 as gzipped OTLP JSON, one prefix per signal, with disk-backed queues.

Everything the collector receives goes to one S3 bucket, with an awss3 exporter and prefix per signal (logs/, metrics/, traces/), so one signal's backlog does not hold up the others and a lifecycle rule or reader can target one signal.

Keys follow logs/year=YYYY/month=MM/day=DD/hour=HH/minute=mm/logs_<random number>.json.gz in UTC, likewise for metrics and traces. Each exporter queues batches on disk and retries every S3 error forever (max_elapsed_time: 0), so queued batches survive restarts and S3 outages delay data instead of dropping it, until the queue fills (1,000 batches by default) and new data for its signal is dropped.

Run it as a gateway and point SDKs and agents at port 4317 (gRPC) or 4318 (HTTP).

Set S3_REGION and S3_BUCKET to the bucket's region and name. The config holds no credentials. The AWS SDK's default chain checks, in order, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, a web identity token (like the one EKS IAM roles for service accounts mount), shared credentials and config files, an ECS task role, and an EC2 instance role.

For an S3-compatible store, set S3_ENDPOINT to its URL and S3_FORCE_PATH_STYLE to true. Without path style, the SDK sends requests for a hostname endpoint to <bucket>.<endpoint host>, which fails unless the store and its DNS are set up for virtual-hosted style. On AWS, leave both unset and ignore the harmless Configuration references unset environment variable startup warning.

Let the collector's IAM identity write objects to the bucket
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::<bucket>/*"
    }
  ]
}
How the data moves
receiverprocessorexporterextension
logs
otlpmemory_limiterbatchawss3/logs
metrics
otlpmemory_limiterbatchawss3/metrics
traces
otlpmemory_limiterbatchawss3/traces
Collector config (YAML)Show
config.yaml
# Ship OTel data to S3
# Writes logs, metrics, and traces to one S3 bucket as gzipped OTLP JSON,
# one prefix per signal, partitioned by minute in UTC. Each exporter keeps
# its queue on disk, so queued data survives a restart and waits out an S3 outage.
# otelcol-contrib v0.159.0.

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317 # the default binds to localhost
      http:
        endpoint: 0.0.0.0:4318

processors:
  memory_limiter:
    check_interval: 1s
    limit_mib: 512
    spike_limit_mib: 128
  batch:
    send_batch_size: 8192
    timeout: 60s # each flush is one S3 object, so a long timeout means fewer, larger objects

exporters:
  awss3/logs:
    marshaler: otlp_json # the default, written out; otlp_proto writes .binpb.gz objects instead
    s3uploader:
      region: ${env:S3_REGION}
      s3_bucket: ${env:S3_BUCKET}
      s3_prefix: logs # one prefix per signal
      s3_partition_timezone: UTC # the default is the collector's local time zone
      compression: gzip # keys end in .json.gz
      endpoint: ${env:S3_ENDPOINT} # leave unset for AWS; set for an S3-compatible store
      s3_force_path_style: ${env:S3_FORCE_PATH_STYLE} # true for stores that want the bucket in the path
    timeout: 30s # the default is 5s
    retry_on_failure:
      enabled: true
      max_elapsed_time: 0 # keep retrying; the disk queue holds the backlog
    sending_queue:
      enabled: true # off by default on this exporter
      storage: file_storage
  awss3/metrics:
    marshaler: otlp_json
    s3uploader:
      region: ${env:S3_REGION}
      s3_bucket: ${env:S3_BUCKET}
      s3_prefix: metrics
      s3_partition_timezone: UTC
      compression: gzip
      endpoint: ${env:S3_ENDPOINT}
      s3_force_path_style: ${env:S3_FORCE_PATH_STYLE}
    timeout: 30s
    retry_on_failure:
      enabled: true
      max_elapsed_time: 0
    sending_queue:
      enabled: true
      storage: file_storage
  awss3/traces:
    marshaler: otlp_json
    s3uploader:
      region: ${env:S3_REGION}
      s3_bucket: ${env:S3_BUCKET}
      s3_prefix: traces
      s3_partition_timezone: UTC
      compression: gzip
      endpoint: ${env:S3_ENDPOINT}
      s3_force_path_style: ${env:S3_FORCE_PATH_STYLE}
    timeout: 30s
    retry_on_failure:
      enabled: true
      max_elapsed_time: 0
    sending_queue:
      enabled: true
      storage: file_storage

extensions:
  health_check:
    endpoint: 0.0.0.0:13133
  file_storage:
    directory: /var/lib/otelcol/file_storage
    create_directory: true # the default expects the directory to exist

service:
  extensions: [health_check, file_storage]
  pipelines:
    logs:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [awss3/logs]
    metrics:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [awss3/metrics]
    traces:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [awss3/traces]

Use this flow

Open the config in Telflo and it becomes a working pipeline on the canvas: adapt what's specific to you, test it against recorded traffic, and push it to your fleet. Free account, no card.

Components

What's in it, and why

otlp

Binds to 0.0.0.0 so other hosts can reach it.

memory_limiter

Checks memory every second and refuses data once usage passes 384 MiB (512 MiB limit minus 128 MiB spike allowance), so senders back off and retry before the collector runs out of memory. Scale both with the host.

batch

Flushes at 8,192 items or after 60 seconds, and each flush becomes one S3 object, about 1,440 per signal per day for a gateway that gets data every minute. A shorter timeout means more objects and PUT requests.

awss3/logs

Writes logs under `logs/`.

awss3/metrics

Writes metrics under `metrics/`.

awss3/traces

Writes spans under `traces/`.

health_check

Answers liveness checks on port 13133 from the container runtime or load balancer.

file_storage

Holds the exporter queues in `/var/lib/otelcol/file_storage`, created if missing. Keep it on a persistent volume so they survive restarts.

Notes

Gotchas

  • 1

    Key partitions use upload time, not record time, so data queued through an outage lands under the minute it was written.

  • 2

    The batch processor holds up to 60 seconds of data in memory before the disk queue, so a crash or kill -9 loses it.

  • 3

    A bucket policy that denies writes keeps batches retrying while the queue fills. Watch otelcol_exporter_queue_size, otelcol_exporter_enqueue_failed_log_records and its metric and span twins, and the log for Exporting failed.

  • 4

    A timed-out upload that still landed is retried under a new random key, so readers should tolerate occasional duplicates.

  • 5

    Objects hold gzip bytes and carry Content-Encoding: gzip. Decompress a download with gunzip before reading it.

  • 6

    S3 keeps objects until deleted. A lifecycle rule can expire them by age.

  • 7

    Replay is a separate collector with the awss3 receiver in time-range mode (starttime, endtime) on one signal's prefix. Like any reader that builds keys from a time range, it needs s3_partition_timezone: UTC to match the exporters, which override their local-time default. Set marshaler: otlp_proto on all three exporters to write .binpb.gz instead of .json.gz. The receiver reads both.

Sources and references (24)Show

Everything consulted while researching and fact-checking this flow, including the README of every component it uses.

Test it before your fleet runs it

Free account, no card. Open this flow in the editor, adapt it, and see what it does to real data before anything ships.