Skip to content

fix(opentelemetry): export OTEL_* variables to NGINX workers - #1618

Open
vedantikapatil wants to merge 1 commit into
3scale:masterfrom
vedantikapatil:fix/1427-otel-env-vars
Open

vedantikapatil wants to merge 1 commit into
3scale:masterfrom
vedantikapatil:fix/1427-otel-env-vars

Conversation

@vedantikapatil

@vedantikapatil vedantikapatil commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Issue Link: #1427

NGINX replaces the environment of its worker processes, so only variables
declared with the env directive survive the fork. The OpenTelemetry module
resolves OTEL_RESOURCE_ATTRIBUTES and OTEL_EXPORTER_OTLP_HEADERS in the
worker (OtelNgxStart → Resource::Create / OtlpGrpcExporter), so both were
always read from an empty environment and silently ignored.

This declares every OTEL_* variable found in the environment when
OpenTelemetry is enabled. Only names are emitted, so the token in
OTEL_EXPORTER_OTLP_HEADERS is not written into the rendered nginx.conf.

OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_SERVICE_NAME were unaffected — those
are read at config-parse time in the master.

Verification steps

  • Checkout this branch
  • Build a new runtime image
make runtime-image IMAGE_NAME=apicast-test
  • Start the OpenTelemetry dev-environment, which this PR sets
    OTEL_RESOURCE_ATTRIBUTES=deployment.environment=dev-environment on
cd dev-environments/opentelemetry-instrumented-gateway
make gateway IMAGE_NAME=apicast-test
  • Send a request
curl --resolve get.example.com:8080:127.0.0.1 "http://get.example.com:8080/?user_key=123"
  • Open http://127.0.0.1:16686/search and inspect the trace. The process tags
    include deployment.environment=dev-environment. On master that tag is absent.

Unit coverage in spec/cli/nginx_conf_spec.lua (make busted).

Note

The issue also reports the parent TraceId being lost. That is
open-telemetry/opentelemetry-cpp-contrib#143 and needs a module bump, not a
config change — opentelemetry_propagate is already set. Consider keeping #1427
open for that half.

@vedantikapatil
vedantikapatil requested review from a team as code owners December 3, 2026 10:39
NGINX replaces the environment of its worker processes, so only variables
declared with the `env` directive survive the fork. The OpenTelemetry module
resolves some of its settings in the worker (`OtelNgxStart` -> `Resource::Create`
and the OTLP exporter), which meant OTEL_RESOURCE_ATTRIBUTES and
OTEL_EXPORTER_OTLP_HEADERS were always read from an empty environment and
silently ignored.

Declare every OTEL_* variable found in the environment with the `env` directive
when OpenTelemetry is enabled. Only the names are emitted, so credentials in
OTEL_EXPORTER_OTLP_HEADERS are not written to the rendered nginx.conf.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant