Skip to content

[nginx] configure with environment variables ?Β #515

@sinux-l5d

Description

@sinux-l5d

Describe your environment
nginx 1.27.1

Steps to reproduce
Dockerfile:

FROM nginx:1.27.1-alpine

RUN apk update \
  && apk add --no-cache tzdata \
  && apk add --no-cache libprotobuf \
  && wget https://github.com/open-telemetry/opentelemetry-cpp-contrib/releases/download/nginx%2Fv0.1.1/otel_ngx_module-alpine-3.20-1.27.1.so -O /usr/lib/nginx/modules/otel_ngx_module.so \
  && chmod +x /usr/lib/nginx/modules/otel_ngx_module.so

nginx.conf:

load_module /etc/nginx/modules/otel_ngx_module.so;

env OTEL_COLLECTOR_SERVICE;
env OTEL_SERVICE_NAME;
env OTEL_EXPORTER_OTLP_ENDPOINT;
env OTEL_RESOURCE_ATTRIBUTES_POD_NAME;
env OTEL_RESOURCE_ATTRIBUTES_POD_UID;
env OTEL_RESOURCE_ATTRIBUTES_NODE_NAME;
env OTEL_PROPAGATOR;
env OTEL_TRACES_SAMPLER;
env OTEL_TRACES_SAMPLER_ARG;
env OTEL_RESOURCE_ATTRIBUTES;

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    server {
        listen 8080;
        server_name _;

        location /ping {
            return 200 "pong!";
        }
    }

    include /etc/nginx/conf.d/*.conf;
}

What is the expected behavior?

If I understand correctly, webserver autoinstrumentation is far behind (nginx 1.23). So I'm building my container with the Dockerfile above to use the nginx "manual" instrumentation.

However, I'm using kubernetes and I'd like to use env vars injection, say with instrumentation.opentelemetry.io/inject-sdk annotation. As described here, it sounds possible to use env vars. But the nginx.conf configuration above doesn't send the traces to my otel collector.

What is the actual behavior?

With the described configuration, the nginx cpp module doesn't seem to pick the env var and does not send variables

Additional context

I'm testing with :

curl localhost:8080/ping

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions