The ngx_otel_module module provides OpenTelemetry distributed tracing support. The module supports W3C context propagation and OTLP/gRPC export protocol.
The source code of the module is available here. Download and install instructions are available here.
The module is also available in a prebuilt nginx-module-otel package since 1.25.3 and in nginx-plus-module-otel package as part of our commercial subscription since 1.23.4.
load_module modules/ngx_otel_module.so;
events {
}
http {
otel_exporter {
endpoint localhost:4317;
}
server {
listen 127.0.0.1:8080;
location / {
otel_trace on;
otel_trace_context inject;
proxy_pass http://backend;
}
}
}
| Syntax: | otel_exporter { ... } |
|---|---|
| Default: | — |
| Context: | http |
Specifies OTel data export parameters:
endpoint [(http|https)://]host:port;
trusted_certificate path;header name value;interval time;5 seconds. batch_size number;512. batch_count number;4. Example:
otel_exporter {
endpoint https://otel-example.nginx.com:4317;
header X-API-Token "my-token-value";
}
| Syntax: | otel_service_name name; |
|---|---|
| Default: | otel_service_name unknown_service:nginx; |
| Context: | http |
Sets the “service.name” attribute of the OTel resource.
| Syntax: | otel_resource_attr name value; |
|---|---|
| Default: | — |
| Context: | http |
This directive appeared in version 0.1.2.
Sets a custom OTel resource attribute.
| Syntax: | otel_trace on |
off |
$variable; |
|---|---|
| Default: | otel_trace off; |
| Context: | http, server, location |
Enables or disables OpenTelemetry tracing. The directive can also be enabled by specifying a variable:
split_clients "$otel_trace_id" $ratio_sampler {
10% on;
* off;
}
server {
location / {
otel_trace $ratio_sampler;
otel_trace_context inject;
proxy_pass http://backend;
}
}
| Syntax: | otel_trace_context extract |
inject |
propagate |
ignore; |
|---|---|
| Default: | otel_trace_context ignore; |
| Context: | http, server, location |
Specifies how to propagate traceparent/tracestate headers:
extractinjectpropagateignore| Syntax: | otel_span_name name; |
|---|---|
| Default: | — |
| Context: | http, server, location |
Defines the name of the OTel span. By default, it is a name of the location for a request. The name can contain variables.
| Syntax: | otel_span_attr name value; |
|---|---|
| Default: | — |
| Context: | http, server, location |
Adds a custom OTel span attribute. The value can contain variables.
The following span attributes are added automatically:
http.method http.target http.route http.scheme http.flavor http.user_agent http.request_content_length http.response_content_length http.status_code net.host.name net.host.port net.sock.peer.addr net.sock.peer.port $otel_trace_id56552bc4daa3bf39c08362527e1dd6c4 $otel_span_id4c0b8531ec38ca59 $otel_parent_iddc94d281b0f884ea $otel_parent_sampledsampled” flag of the parent span, can be “1” or “0”
© 2002-2021 Igor Sysoev
© 2011-2025 Nginx, Inc.
Licensed under the BSD License.
https://nginx.org/en/docs/ngx_otel_module.html