Skip to content

oci: don't override build-provided OpenTelemetry env vars - #6958

Merged
tonistiigi merged 1 commit into
moby:masterfrom
Kunalbehbud:fix/otel-env-override
Jul 17, 2026
Merged

oci: don't override build-provided OpenTelemetry env vars#6958
tonistiigi merged 1 commit into
moby:masterfrom
Kunalbehbud:fix/otel-env-override

Conversation

@Kunalbehbud

Copy link
Copy Markdown
Contributor

Fixes #4972

Problem

When a tracing socket is configured, BuildKit injects the OpenTelemetry trace-exporter variables (OTEL_TRACES_EXPORTER=otlp, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_PROTOCOL) into every build environment. It did this unconditionally, appending its own values after any the build already provided. Because a later duplicate wins, there was no way to opt out or override them — as the issue reporter found, --opt env.OTEL_TRACES_EXPORTER=none had no effect since BuildKit re-added OTEL_TRACES_EXPORTER=otlp afterwards. This breaks builds that run OpenTelemetry-instrumented tooling of their own.

Change

In GenerateSpec, only inject the trace-exporter variables the build has not already set. A build can now disable or override tracing per build, e.g.:

--opt env.OTEL_TRACES_EXPORTER=none

Behavior is unchanged when the build sets none of these variables (all three are still injected as before).

Tests

Added offline unit tests for the new helper (executor/oci/spec_test.go): all vars injected when none are set, a user-provided OTEL_TRACES_EXPORTER=none is preserved (and BuildKit's =otlp is not added), and no user-provided tracing var is overridden.

Note

This makes the existing per-build env.* mechanism work as expected, which I think is the least surprising fix. If you'd instead prefer a daemon-level opt-out (a buildkitd.toml option), I'm happy to add that as well or instead — just let me know.

BuildKit injects OTEL_TRACES_EXPORTER (and the OTLP endpoint/protocol)
into the build environment whenever a tracing socket is configured, and
it did so unconditionally -- appending its values after any the build
already set. That made it impossible to opt out or override them; for
example `--opt env.OTEL_TRACES_EXPORTER=none` had no effect because
BuildKit re-added OTEL_TRACES_EXPORTER=otlp afterwards.

Only inject the trace-exporter variables the build has not already set,
so a build can override them or opt out of tracing.

Fixes moby#4972

Signed-off-by: Kunalbehbud <b.kunal2002@gmail.com>
@tonistiigi
tonistiigi merged commit 540ab6a into moby:master Jul 17, 2026
193 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to disable OpenTelemetry

2 participants