Your trace starts in the application, but the customer started waiting earlier: the moment the request reached your reverse proxy. When a 502 or an 800 ms stall happens inside NGINX, no span shows it. Wiring up NGINX OpenTelemetry tracing with the ngx_otel_module module closes that gap, and the proxy becomes the first link of the trace. This article starts from the operational decisions you have to make, not from a directive catalogue.
The facts come from the module’s official page on nginx.org and from the nginx/nginx-otel repository, both read on 14 November 2026. I did not run NGINX for this article: the configurations follow the documentation, and anything I did not verify is flagged as such.
If span vocabulary is still fuzzy, read the anatomy of an OpenTelemetry span first. Here we deal with a single span: the one NGINX opens for each request.
NGINX OpenTelemetry: what the module does, and what it does not
The documentation describes the module as OpenTelemetry distributed tracing support. It handles W3C context propagation and exports over OTLP/gRPC. Note the exact scope: it produces traces. The page mentions neither OpenTelemetry metrics nor logs, and I infer nothing about them.
On licensing, the repository is Apache 2.0. On distribution, two prebuilt packages exist: nginx-module-otel, available since NGINX 1.25.3, and nginx-plus-module-otel, available since 1.23.4 with the commercial subscription. The repository also states that packages assume the officially distributed NGINX binaries, so a community build is not guaranteed to be compatible.
First decision: package or build
If you install NGINX from the nginx.org repositories, take the package and skip a build chain. If you maintain your own binary, mind the repository’s strong constraint: the module only works with the same NGINX source version it was compiled against.
The README procedure, for Ubuntu and Debian, boils down to four ideas. Install the dependencies (including libc-ares-dev and libre2-dev for gRPC). Run auto/configure --with-compat in the NGINX sources. Create a build folder in nginx-otel, run cmake with -DNGX_OTEL_NGINX_BUILD_DIR pointing to NGINX’s objs folder, then make. The output is ngx_otel_module.so. The README gives no steps for other systems, and I will not invent any.
SRE consequence: every NGINX upgrade means rebuilding the module. Put that step in your pipeline, or a security patch turns into a startup incident.
Second decision: who creates the trace?
The otel_trace_context directive answers that question. It takes four values, and the default is ignore: with no setting, NGINX leaves the traceparent and tracestate headers alone.
-
extract: NGINX takes the context from the incoming request. Thetrace_idand the parent span are inherited. -
inject: NGINX adds a new context to the request and overwrites any existing headers. -
propagate: it updates the existing context, which combines extract and inject. -
ignore: no processing at all.
The right choice depends on where the proxy sits. An edge NGINX facing the Internet is often the first link, so inject makes sense: nothing upstream deserves your trust. An internal NGINX behind a gateway or another instrumented service should continue the existing trace instead: propagate. That rule of thumb is mine, not the documentation’s, so test it with your clients.
To see why a trace identifier beats a home-grown one, read correlation ID or trace ID.
Third decision: how many requests to trace?
By default, otel_trace is off. You enable it in http, server or location, and the directive accepts a variable. That is your sampling lever. The documentation shows two patterns:
- A ratio sample with
split_clients "$otel_trace_id": 10% of requests go toon, the rest tooff. - A sample inherited from the parent, with
otel_trace $otel_parent_sampledpaired withotel_trace_context propagate: NGINX records a span only when the parent is sampled.
The first suits a proxy at the head of the chain. The second stops an internal proxy from tracing requests the rest of the chain dropped. If you want to decide afterwards, looking at the complete trace, that is not NGINX’s job: see the Collector’s tail sampling rules.
The README claims a performance impact of roughly 10 to 15%, against up to 50% for other implementations. That is the project’s claim and I have not measured it. Run your own load test before production.
Step by step: a minimal configuration
- Install the
nginx-module-otelpackage or build the module, then load it withload_module modules/ngx_otel_module.so;at the very top ofnginx.conf. - Declare the export in the
httpcontext withotel_exporter. Theendpointis an OTLP/gRPC address, for examplelocalhost:4317. TLS (thehttps://scheme,trusted_certificate) and theheaderdirective exist since module version 0.1.2. - Name the service with
otel_service_name. Otherwise the default isunknown_service:nginx, which you do not want to see across ten environments. - Enable tracing and pick the context in the relevant
location.
load_module modules/ngx_otel_module.so;
events {}
http {
otel_exporter {
endpoint localhost:4317;
interval 5s;
batch_size 512;
}
otel_service_name edge-nginx;
log_format traced '$remote_addr "$request" $status trace=$otel_trace_id span=$otel_span_id';
server {
listen 127.0.0.1:8080;
access_log /var/log/nginx/traced.log traced;
location / {
otel_trace on;
otel_trace_context inject;
otel_span_attr deploy.zone "eu-west";
proxy_pass http://backend;
}
}
}
Three lines deserve a word. interval sets the maximum time between two exports (5 seconds by default), and batch_size the maximum number of spans per batch per worker (512 by default). The log_format writes the trace identifier to the access log: your fallback when the trace backend is down. Finally otel_span_attr adds a custom attribute, here an example value.
One caveat: the documentation says batch_count (4 by default) caps the pending batches per worker, and spans beyond that limit are dropped. A slow Collector therefore loses spans without failing requests.
How to check that it works
Before any traffic, test the syntax with nginx -t, then reload. On the receiving side, a Collector with an OTLP gRPC receiver and the debug exporter prints every span that arrives. This file follows the Collector documentation, but I did not run it:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
exporters:
debug:
verbosity: detailed
service:
pipelines:
traces:
receivers: [otlp]
exporters: [debug]
Then send a request with curl http://127.0.0.1:8080/. Three checks: the Collector prints a span named after the location (the default name, which otel_span_name can change); http.method and http.status_code appear among the automatically added attributes; and the trace_id in the access log matches the Collector’s. If one is missing, look at the endpoint first, then at the firewall between NGINX and the Collector.
For the next leg, the route from a Collector to the backend, see the Collector contrib components.
Best practices
- Start with a single
locationand a 10% sample, then widen. - Set
otel_service_nameand a resource attribute specific to each environment (otel_resource_attr, since version 0.1.2). - Keep the trace identifier in the access log: it ties an NGINX log line to its trace.
- Rebuild the module at every NGINX upgrade if you do not use the package.
- Watch for dropped spans: HTTP status codes will not show them.
Frequently asked questions
Does ngx_otel_module also export metrics and logs?
The documentation presents distributed tracing support, with W3C propagation and OTLP/gRPC export. It does not describe any metrics or logs export. For those, look for another route and check it in its own documentation.
Can I send traces straight to a backend?
The module speaks OTLP over gRPC. If your backend accepts that protocol, nothing forbids it, with TLS and an authentication header through otel_exporter. An intermediate Collector stays more flexible for filtering and enrichment. For Dynatrace, consult docs.dynatrace.com and keep SaaS and Managed apart: I do not detail any feature here.
What is the difference between inject and propagate?
inject overwrites existing context headers and creates a new context. propagate updates the incoming one, so the client’s trace continues through the proxy.
Conclusion
With ngx_otel_module, NGINX stops being a blind spot: it opens the first span, forwards the W3C context and exports over OTLP. Everything rests on three decisions: package or build, inject or propagate, and a sampling rule. Sources: module documentation and nginx-otel repository.
span.observer is an independent community blog, not affiliated with Dynatrace LLC, F5 or NGINX. Brands mentioned belong to their owners. Tools change quickly: check commands and options against the official documentation.
Originally published on span.observer. French version: https://span.observer/fr/nginx-opentelemetry-ngx-otel-module/.


Top comments (0)