Skip to content

Nginx Tracing

Configuration

Supported Versions

NGINX version line nginx-datadog supported version range Confirmed NGINX versions / notes Recommendation
1.31.* >= v1.17.0 Confirmed 1.31.0 Use v1.17.0 or later
1.30.* >= v1.16.0 1.30.0 is supported from v1.16.0; 1.30.1 from v1.17.0 Prefer v1.17.0+
1.29.* >= v1.8.0 Confirmed 1.29.0 ~ 1.29.8; some patch versions need a newer nginx-datadog Prefer v1.17.0+
1.28.* >= v1.8.0 Confirmed 1.28.0 ~ 1.28.3; some patch versions need a newer nginx-datadog Prefer v1.17.0+
1.27.* >= v1.8.0 Confirmed 1.27.0 ~ 1.27.5 Prefer v1.17.0+
1.26.* >= v1.8.0 Confirmed 1.26.0 ~ 1.26.3 Prefer v1.17.0+
1.25.* >= v1.0.1 1.25.0/1.25.1 from v1.0.1; 1.25.2 from v1.0.2; 1.25.3/1.25.4 from v1.0.5; 1.25.5 is supported in later releases Recommend v1.7.0+, latest preferred
1.24.* v0.6.1 ~ v1.16.0 Confirmed 1.24.0; support is removed in v1.16.1+ Use at most v1.16.0
1.23.* v0.3.4 / v0.5.3 / v0.6.1 ~ v1.6.2 1.23.2 from v0.3.4; 1.23.3 from v0.5.3; 1.23.4 from v0.6.1 Pin to v1.6.2 or build yourself
1.22.* v0.3.4 ~ v1.6.2 Confirmed 1.22.1 Pin to v1.6.2 or build yourself
1.19.* v0.1.0 ~ v1.6.2 Only 1.19.1 is confirmed Other 1.19.x need asset checks or a custom build
1.18.* v0.1.0 ~ v1.6.2 Only 1.18.0-alpine is confirmed Non-alpine or other patches need asset checks or a custom build
1.14.* v0.5.2 ~ v1.6.2 Only 1.14.1 is confirmed Other 1.14.x need asset checks or a custom build

Configure Nginx

Download Tracing Module

Visit https://github.com/DataDog/nginx-datadog/releases, and find and download the module that matches your processor architecture and version in the Assets section: ngx_http_datadog_module-<processor architecture>-<version>.so.tgz

Install Tracing

  • Create Module Path
cd /usr/local/nginx
mkdir modules && cd $_
  • Extract
root@root:/usr/local/nginx/modules$  tar xzvf ngx_http_datadog_module-<processor architecture>-<version>.so.tgz

Configure Nginx

Add the following content to /usr/local/nginx/conf/nginx.conf:

# Load Module
load_module modules/ngx_http_datadog_module.so;

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    # Configure Datakit URL
    datadog_agent_url http://localhost:9529;
    # Configure Service Name
    datadog_service_name nginx-demo;
    # Configure Environment Name
    datadog_environment test;
    # Configure Version Name
    datadog_version 1.0.0;
    # Configure Sampling Rate 0-1.0
    datadog_sample_rate 1.0;
    # Configure Tags
    datadog_tag foo bar;

    include       mime.types;
    default_type  application/octet-stream;

    # Add trace_id and span_id to logs using $datadog_trace_id and $datadog_span_id, both in hexadecimal
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"'
                      '"$datadog_trace_id" "$datadog_span_id"';

    access_log  logs/access.log  main;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

Restart Nginx

Enable DataKit Collection

  • Enable ddtrace
cd /usr/local/datakit/conf.d/ddtrace/
cp ddtrace.conf.sample ddtrace.conf
  • Restart DataKit
datakit service -R