oci: don't override build-provided OpenTelemetry env vars - #6958
Merged
Conversation
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
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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=nonehad no effect since BuildKit re-addedOTEL_TRACES_EXPORTER=otlpafterwards. 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.: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-providedOTEL_TRACES_EXPORTER=noneis preserved (and BuildKit's=otlpis 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 (abuildkitd.tomloption), I'm happy to add that as well or instead — just let me know.