Episode 04traces

OpenTofu can trace every apply

OpenTofu has emitted OpenTelemetry traces since 1.10, with the exporter switched off. A few environment variables turn on one span per resource instance.

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

OpenTofu ships tracing disabled and sends nothing until you name an exporter. Export these before you run anything; every tofu command then emits one trace, with a span per resource instance. Needs OpenTofu 1.10 or newer, where tracing arrived as an experimental feature.

export OTEL_TRACES_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://ingestion.eu.bronto.io/v1/traces
export OTEL_EXPORTER_OTLP_HEADERS="x-bronto-api-key=$BRONTO_API_KEY"
export OTEL_SERVICE_NAME=opentofu

tofu apply
export OTEL_TRACES_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:4318/v1/traces
export OTEL_SERVICE_NAME=opentofu

tofu apply

This assumes a Collector listening on localhost:4318; the Local Collector setup shows how to start one.

This uses the endpoint and auth header you saved in the setup guide.

export OTEL_TRACES_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=YOUR_OTLP_ENDPOINT/v1/traces
export OTEL_EXPORTER_OTLP_HEADERS="YOUR_AUTH_HEADER=YOUR_AUTH_VALUE"
export OTEL_SERVICE_NAME=opentofu

tofu apply