Episode 02tracesmetrics

Docker already traces every build

BuildKit records a full OpenTelemetry trace of every image build. One builder exports every build's trace and metrics, using nothing but standard OTEL_* variables.

Ship telemetry toUse an OTLP endpoint you already have, from another vendor or your platform team. This one needs a one-time setup step: save your endpoint and the episodes fill it in.Set your endpointRun an OpenTelemetry Collector on your machine and watch telemetry arrive in its terminal. No account needed.More detailsShip straight to Bronto. You need an account and an API key with ingest permission.More details

Switch it on

Create a builder with OTel enabled, once. Every build then exports the full trace, span names matching your Dockerfile steps, plus BuildKit’s metrics.

docker buildx create --name otel-builder \
  --driver docker-container \
  --driver-opt env.OTEL_TRACES_EXPORTER=otlp \
  --driver-opt env.OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
  --driver-opt env.OTEL_EXPORTER_OTLP_ENDPOINT=https://ingestion.eu.bronto.io \
  --driver-opt env.OTEL_EXPORTER_OTLP_HEADERS=x-bronto-api-key=$BRONTO_API_KEY \
  --driver-opt env.OTEL_SERVICE_NAME=buildx

docker buildx use --default otel-builder
docker buildx build -t myapp .

This assumes a Collector listening on localhost:4318; the Local Collector setup shows how to start one. On Linux, use http://localhost:4318 and add --driver-opt network=host.

docker buildx create --name otel-builder \
  --driver docker-container \
  --driver-opt env.OTEL_TRACES_EXPORTER=otlp \
  --driver-opt env.OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
  --driver-opt env.OTEL_EXPORTER_OTLP_ENDPOINT=http://host.docker.internal:4318 \
  --driver-opt env.OTEL_EXPORTER_OTLP_HEADERS=x-otel-auth=none \
  --driver-opt env.OTEL_SERVICE_NAME=buildx

docker buildx use --default otel-builder
docker buildx build -t myapp .

This uses the endpoint and auth header you saved in the setup guide. BuildKit needs a headers line even without authentication; a dummy value works.

docker buildx create --name otel-builder \
  --driver docker-container \
  --driver-opt env.OTEL_TRACES_EXPORTER=otlp \
  --driver-opt env.OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
  --driver-opt env.OTEL_EXPORTER_OTLP_ENDPOINT=YOUR_OTLP_ENDPOINT \
  --driver-opt env.OTEL_EXPORTER_OTLP_HEADERS=YOUR_AUTH_HEADER=YOUR_AUTH_VALUE \
  --driver-opt env.OTEL_SERVICE_NAME=buildx

docker buildx use --default otel-builder
docker buildx build -t myapp .

use --default makes plain docker build go through this builder too.