Skip to content
Latchkey

How to Run an OpenTelemetry Collector in CI

A Collector as a service container gives pipeline steps a local OTLP endpoint that batches and forwards telemetry.

Declare the Collector under services: so it starts before your steps, and mount a config that receives OTLP on 4317 and exports to your backend. Steps then send to localhost:4317.

Steps

  • Add the Collector image under services: with port 4317 mapped.
  • Provide a config that receives OTLP and exports to your backend.
  • Point step exporters at localhost:4317.

Service container

.github/workflows/ci.yml
jobs:
  build:
    runs-on: ubuntu-latest
    services:
      otelcol:
        image: otel/opentelemetry-collector-contrib:latest
        ports: ['4317:4317']
    steps:
      - uses: actions/checkout@v4
      - run: OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 ./run-tests.sh

Collector config

otel-collector.yaml
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
processors:
  batch: {}
exporters:
  otlphttp:
    endpoint: ${env:BACKEND_OTLP_URL}
service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlphttp]

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →