This guide provides step-by-step instructions for setting up OpenTelemetry (OTel) instrumentation in your Nginx web server to enable distributed tracing. The official ngx_otel_module dynamic module allows Nginx to participate in distributed traces by creating spans for proxied requests and propagating W3C trace context headers. Once your telemetry data is captured, you can configure an exporter to send it to Atatus via the OTel Collector for advanced monitoring and insights. The process of setting up OpenTelemetry in Nginx involves three key steps: Installing the OTel Module: Add the ngx_otel_module dynamic module to your Nginx installation.
Configuring the Exporter: Set up Nginx to export traces to the OTel Collector, which forwards them to Atatus.
Validating the Setup: Verify that the configuration is working and that your data is being correctly sent to Atatus.

Requirements

  • NGINX 1.25.3 or newer
  • OpenTelemetry Collector

Install NGINX with the OTel Module

Choose the installation method that matches your deployment environment.

Host / VM (Alpine Linux)

Add the nginx.org repository and install the module:

Host / VM (Debian / Ubuntu)

Add the nginx.org repository and install the module:

Docker

Create a Dockerfile that adds the OTel module to the official Nginx Alpine image:
Build the image:

Kubernetes

Use the same Docker image from the Docker section above and deploy it as a Kubernetes Deployment. The OTel Collector can run as a sidecar container in the same pod or as a separate service in the cluster.
In this sidecar setup, the Nginx container sends traces to localhost:4317 (the OTel Collector running in the same pod).

Prerequisites: Set Up the OTel Collector

The Nginx OTel module exports traces via OTLP/gRPC and does not support custom authentication headers, so an OTel Collector is required to add the Atatus API key and forward traces to Atatus. Before configuring Nginx, set up the OTel Collector by following the OTel Collector Configuration guide. Once the Collector is running and forwarding traces to Atatus, proceed with the steps below.

Send Telemetry Traces to Atatus

Step 1: Configure Nginx

Add the following to your nginx.conf, replacing <OTEL_COLLECTOR_HOST> with the address of your OTel Collector:
OTel Collector endpoint by deployment environment: Replace my-nginx with a descriptive service name for your Nginx instance. Key directives: You can disable tracing for specific locations (e.g., health checks) to reduce noise:

Step 2: Verify

Send a request through Nginx and check that traces appear in Atatus:
Traces should appear in your Atatus dashboard under the service name you configured in otel_service_name.

Additional Configuration

Custom Span Attributes

Add custom attributes to your spans for better filtering:

Sampling

Control the trace sampling rate using a variable:

Exporter Tuning

Adjust the export batch settings for high-traffic environments: