OpenTelemetry
OpenTelemetry (OTel) is an observability framework for monitoring, tracing, troubleshooting, and optimizing applications. OTel enables the collection of telemetry data from a deployed application stack.
The nginx-plus-module-otel module is an NGINX-authored dynamic module that enables NGINX Plus to send telemetry data to an OTel collector. The module supports W3C trace context propagation, OpenTelemetry Protocol (OTLP)/gRPC trace exports, and offers several advantages over existing OTel modules including:
-
Enhanced performance: with the module enabled, request processing overhead is limited to 10-15%, compared to other OpenTelemetry implementations, which can introduce performance degradation of up to 50%.
-
Simplified provisioning through NGINX configuration file.
-
Dynamic, variable-based control of trace parameters with cookies, tokens, and variables. See Ratio-based Tracing example for details.
-
Dynamic control of sampling parameters via the NGINX Plus API and key-value storage.
The source code for the module is available in the official GitHub repository. The official documentation, including module reference and usage examples, is available on the nginx.org website.
The OpenTelemetry module supersedes the deprecated OpenTracing module which was available until NGINX Plus Release 34.
The installation process closely follows the NGINX Plus installation procedure. The module is available as the prebuilt nginx-plus-module-otel package for various Linux distributions and can be installed directly from the official NGINX Plus repository. Prior to installation, you need to add the NGINX Plus package repository for your distribution and update the repository metadata.
-
Check the Technical Specifications page to verify that the module is supported by your operating system.
Note: The OpenTelemetry module cannot be installed on Amazon Linux 2 LTS and SLES 15 SP5+. -
Make sure you have the latest version of NGINX Plus. In Terminal, run the command:
nginx -vExpected output of the command:
nginx version: nginx/1.27.4 (nginx-plus-r34) -
Ensure you have the nginx-repo.crt and nginx-repo.key files from MyF5 Customer Portal in the /etc/ssl/nginx/ directory. These files are required for accessing the NGINX Plus repository.
sudo cp <downloaded-file-name>.crt /etc/ssl/nginx/nginx-repo.crt && \ sudo cp <downloaded-file-name>.key /etc/ssl/nginx/nginx-repo.keyFor Alpine, the nginx-repo.crt to /etc/apk/cert.pem and nginx-repo.key files should be added to /etc/apk/cert.key. Ensure these files contain only the specific key and certificate as Alpine Linux does not support mixing client certificates for multiple repositories.
For FreeBSD, the path to these files should also be added to the
/usr/local/etc/pkg.conffile:PKG_ENV: { SSL_NO_VERIFY_PEER: "1", SSL_CLIENT_CERT_FILE: "/etc/ssl/nginx/nginx-repo.crt", SSL_CLIENT_KEY_FILE: "/etc/ssl/nginx/nginx-repo.key" } -
Ensure that all required dependencies for your operating system are installed.
For Amazon Linux 2023, AlmaLinux, CentOS, Oracle Linux, RHEL, and Rocky Linux:
sudo dnf update && \ sudo dnf install ca-certificatesFor Debian:
sudo apt update && \ sudo apt install apt-transport-https \ lsb-release \ ca-certificates \ wget \ gnupg2 \ debian-archive-keyringFor Ubuntu:
sudo apt update && \ sudo apt install apt-transport-https \ lsb-release \ ca-certificates \ wget \ gnupg2 \ ubuntu-keyringFor FreeBSD:
sudo pkg update && \ sudo pkg install ca_root_nss -
Ensure that the NGINX signing key has been added, if required by your operating system.
For Debian:
wget -qO - https://cs.nginx.com/static/keys/nginx_signing.key \ | gpg --dearmor \ | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/nullFor Ubuntu:
printf "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ https://pkgs.nginx.com/plus/ubuntu `lsb_release -cs` nginx-plus\n" \ | sudo tee /etc/apt/sources.list.d/nginx-plus.listFor Alpine:
sudo wget -O /etc/apk/keys/nginx_signing.rsa.pub https://cs.nginx.com/static/keys/nginx_signing.rsa.pub -
Ensure that your package management system is configured to pull packages from the NGINX Plus repository. See Installing NGINX Plus for details.
-
Update the repository information and install the
nginx-plus-module-otelpackage. In a terminal, run the appropriate command for your operating system.For CentOS, Oracle Linux, and RHEL:
sudo yum update && \ sudo yum install nginx-plus-module-otelFor Amazon Linux 2023, AlmaLinux, Rocky Linux:
sudo dnf update && \ sudo dnf install nginx-plus-module-otelFor Debian and Ubuntu:
sudo apt update && \ sudo apt install nginx-plus-module-otelFor Alpine:
sudo apk update && \ sudo apk add nginx-plus-module-otelFor FreeBSD:
sudo pkg update && \ sudo pkg install nginx-plus-module-otelThe resulting
ngx_otel_module.sodynamic module will be written to the following directory, depending on your operating system:
/usr/lib64/nginx/modules/for most Linux distributions/usr/lib/nginx/modulesfor Debian, Ubuntu, Alpine/usr/local/etc/nginx/modulesfor FreeBSD
-
Enable dynamic loading of the module.
-
In a text editor, open the NGINX Plus configuration file (
/etc/nginx/nginx.conffor Linux or/usr/local/etc/nginx/nginx.conffor FreeBSD). -
On the top-level (or “
main”) context, specify the path to the dynamic module with theload_moduledirective:
load_module modules/ngx_otel_module.so; http { #... }- Save the configuration file.
-
-
Test the NGINX Plus configuration. In a terminal, type-in the command:
nginx -tExpected output of the command:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf is successful -
Reload the NGINX Plus configuration to enable the module:
nginx -s reload
In a text editor, open the NGINX Plus configuration file:
/etc/nginx/nginx.conffor Linux/usr/local/etc/nginx/nginx.conffor FreeBSD
For a complete list of directives, embedded variables, default span attributes, refer to the ngx_otel_module official documentation.
List of directives:
https://nginx.org/en/docs/ngx_otel_module.html#directives
List of variables:
https://nginx.org/en/docs/ngx_otel_module.html#variables
Default span attributes:
https://nginx.org/en/docs/ngx_otel_module.html#span
This configuration enables basic request tracing, capturing tracing information for every incoming request, even in non-distributed environments.
http {
otel_trace on;
server {
location / {
proxy_pass http://backend;
}
}
}This configuration enables parent-based tracing, where NGINX Plus captures and propagates trace information from incoming requests, allowing tracing contexts to be inherited from the parent request. It is useful in scenarios where NGINX Plus is used as a reverse proxy within a distributed tracing system.
http {
server {
location / {
otel_trace $otel_parent_sampled;
otel_trace_context propagate;
proxy_pass http://backend;
}
}
}This configuration enables sampling of a specified percentage of requests or user sessions for tracing, based on configurable ratios.
http {
# trace 10% of requests
split_clients $otel_trace_id $ratio_sampler {
10% on;
* off;
}
# or we can trace 10% of user sessions
split_clients $cookie_sessionid $session_sampler {
10% on;
* off;
}
server {
location / {
otel_trace $ratio_sampler;
otel_trace_context inject;
proxy_pass http://backend;
}
}
}