1
1
<img alt =" datadog tracing nginx " src =" mascot.svg " height =" 200 " />
2
2
3
- Datadog NGINX Module
4
- ====================
3
+ [ ![ codecov ] ( https://codecov.io/gh/DataDog/nginx-datadog/graph/badge.svg?token=SZCZI1FAYU )] ( https://codecov.io/gh/DataDog/nginx-datadog )
4
+ # Datadog NGINX Module
5
5
This repository contains the source code for the ` ngx_http_datadog_module ` , an NGINX module
6
- that integrates Datadog [ APM] [ 13 ] and [ Application Security Management] [ 14 ] into NGINX.
6
+ that integrates Datadog [ APM] [ 1 ] and [ Application Security Management] [ 2 ] into NGINX.
7
7
8
- Usage
9
- -----
8
+ ## Usage
10
9
1 . Download a gzipped tarball from a [ recent release] [ 12 ] , extract it to
11
10
wherever nginx looks for modules (e.g. ` /usr/lib/nginx/modules/ ` ).
12
11
2 . Add the following line to the top of the main nginx configuration (e.g.
@@ -19,19 +18,18 @@ load_module modules/ngx_http_datadog_module.so;
19
18
Tracing is automatically added to all endpoints by default. For more
20
19
information, see [ the API documentation] ( doc/API.md ) .
21
20
22
- Compatibility
23
- -------------
21
+ ## Compatibility
24
22
> [ !IMPORTANT]
25
23
> We provide support for NGINX versions up to their End Of Life, extended by one
26
- > year. [ Aligned with the NGINX release cycle] [ 11 ] , this entails support for
24
+ > year. [ Aligned with the NGINX release cycle] [ 4 ] , this entails support for
27
25
> the four most recent NGINX versions.
28
26
>
29
27
> If you plan to add tracing features to an older NGINX version using our
30
28
> module, please check out [ the build section] ( #build ) for guidance.
31
29
32
30
There are two tarballs (the actual executable module and, separately, the debug
33
31
symbols) per each combination of: 1) nginx version, 2) architecture, 3) whether
34
- AppSec is built in or not. The main tarball contains a single file,
32
+ AppSec is built in or not. The main tarball contains a single file,
35
33
` ngx_http_datadog_module.so ` , which is the Datadog nginx module.
36
34
37
35
The naming convention is:
@@ -51,26 +49,22 @@ While it _may_ be possible to build the extension against an older version, this
51
49
is not guaranteed; in particular, AppSec builds require a feature introduced in
52
50
version 1.21.4.
53
51
54
-
55
- Default Behavior
56
- ----------------
52
+ ## Default Behavior
57
53
Unless otherwise configured, ` ngx_http_datadog_module ` adds the following
58
- default behavior to nginx :
54
+ default behavior to NGINX :
59
55
60
56
### Tracing
61
57
- Connect to the Datadog agent at ` http://localhost:8126 ` .
62
58
- Create one span per request:
63
59
- Service name is "nginx".
64
60
- Operation name is "nginx.request".
65
61
- Resource name is ` "$request_method $uri" ` , e.g. "GET /api/book/0-345-24223-8/title".
66
- - Includes multiple ` http.* ` [ tags] [ 8 ] .
67
-
62
+ - Includes multiple ` http.* ` [ tags] [ 5 ] .
68
63
69
64
Custom configuration can be specified via the [ datadog\_ * ] ( doc/API.md ) family of
70
- directives in nginx's configuration file, or via [ environment variables] [ 9 ] .
65
+ directives in nginx's configuration file, or via [ environment variables] [ 6 ] .
71
66
72
- Enabling AppSec
73
- ---------------
67
+ ## Enabling AppSec
74
68
75
69
To enable AppSec, besides using the correct binary (the relase artifact with
76
70
"-appsec") in the name, it's necessary to edit the nginx configuration:
@@ -82,70 +76,89 @@ To enable AppSec, besides using the correct binary (the relase artifact with
82
76
83
77
For more information, see [ the documentation] ( doc/API.md ) .
84
78
85
- Build
86
- -----
87
- Requirements:
79
+ ## Building the module
80
+ If the version of NGINX you’re using is no longer supported by this repository,
81
+ you can build the module by following the steps below.
82
+
83
+ This repository uses [ git submodules] [ 7 ] for some of its dependencies.
84
+ To ensure all dependencies are available or updated before building, run the
85
+ following command:
86
+
87
+ ``` shell
88
+ git submodule update --init --recursive
89
+ ```
90
+
91
+ ### Prerequisites
92
+ Before building the module, ensure your environment meets the following requirements:
93
+
88
94
- Recent C and C++ toolchain (` clang ` or ` gcc/g++ ` ) (must support at least some
89
95
C++20 features).
96
+ - make.
90
97
- CMake ` v3.24 ` or newer.
91
- - Architecture must be ` x86_64 ` or ` arm64 ` .
98
+ - Architecture is either ` x86_64 ` or ` arm64 ` .
92
99
93
- For enhanced usability, we provide a [ GNU make] [ 1 ] compatible [ Makefile] ( Makefile ) .
100
+ ### Building using Docker
101
+ We recommend using Docker which greatly simplify the build process for various environments.
102
+ Below are specific commands and options for different build targets.
94
103
95
- ``` shell
96
- NGINX_VERSION=1.25.2 make build
97
- ```
104
+ > [ !IMPORTANT ]
105
+ > Be sure to match the version of NGINX, OpenResty, or ingress-nginx with the version you
106
+ > are using in your environment to avoid compatibility issues.
98
107
99
- You can set the environment variable ` WAF ` to ` ON ` to build an AppSec-supporting
100
- module:
108
+ #### Building for NGINX
109
+ > [ !NOTE]
110
+ > The ` build-musl ` target builds against [ musl] ( https://www.musl-libc.org/ ) to guarantee portability.
101
111
102
112
``` shell
103
- WAF=ON NGINX_VERSION=1.25.2 make build
113
+ WAF=ON ARCH=amd64 NGINX_VERSION=1.27.1 make build-musl
104
114
```
105
115
106
- The resulting nginx module is ` .build/ngx\_http\_datadog\_module.so `
116
+ Options:
117
+ - ` WAF=<ON|OFF> ` : Enable (` ON ` ) or disable (` OFF ` ) AppSec.
118
+ - ` ARCH=<amd64|aarch64> ` : Specify the CPU architecture.
119
+ - ` NGINX_VERSION=<version> ` : Specify the NGINX version to build.
107
120
108
- The ` build ` target does the following:
121
+ The NGINX module will be generated at ` .musl-build\ngx_http_datadog_module.so ` .
109
122
110
- - Download a source release of nginx based on the ` NGINX\_VERSION ` environment variable.
111
- - Initialize the source tree of ` dd-trace-cpp ` as a git submodule.
112
- - Build ` dd-trace-cpp ` and the Datadog nginx module together using
113
- CMake.
123
+ ### Building for OpenResty using Docker
124
+ > [ !NOTE]
125
+ > The ` build-openresty ` target builds against [ musl] ( https://www.musl-libc.org/ ) to guarantee portability.
114
126
115
- ` make clean ` deletes CMake's build directory. ` make clobber ` deletes
116
- everything done by the build.
127
+ To build the module for OpenResty:
117
128
118
- Build in Docker
119
- ---------------
120
129
``` shell
121
- make build-musl
130
+ WAF=ON ARCH=amd64 RESTY_VERSION=1.27.1.1 make build-openresty
122
131
```
123
132
124
- The ` build-musl ` target builds against musl and libc++ a glibc-compatible
125
- module. The Dockerfile for the docker image used in the process can be found in
126
- [ build_env/Dockerfile] ( ./build_env/Dockerfile ) .
127
-
128
- Test
129
- ----
130
- See [ test/README.md] ( test/README.md ) .
131
-
132
- Acknowledgements
133
- ----------------
134
- This project is based largely on previous work. See [ CREDITS.md] ( CREDITS.md ) .
135
-
136
- [ 1 ] : https://www.gnu.org/software/make/
137
- [ 2 ] : https://www.docker.com/
138
- [ 3 ] : https://hub.docker.com/_/nginx?tab=tags
139
- [ 4 ] : https://cmake.org/
140
- [ 5 ] : https://hub.docker.com/layers/nginx/library/nginx/1.19.1-alpine/images/sha256-966f134cf5ddeb12a56ede0f40fff754c0c0a749182295125f01a83957391d84
141
- [ 6 ] : https://www.gnu.org/software/libc/
142
- [ 7 ] : https://www.musl-libc.org/
143
- [ 8 ] : https://github.com/DataDog/nginx-datadog/blob/535a291ce96d8ca80cb12b22febac1e138e45847/src/tracing_library.cpp#L187-L203
144
- [ 9 ] : https://github.com/DataDog/dd-trace-cpp/blob/main/include/datadog/environment.h
145
- [ 10 ] : https://hub.docker.com/_/amazonlinux
146
- [ 11 ] : https://www.nginx.com/blog/nginx-1-18-1-19-released/
147
- [ 12 ] : https://github.com/DataDog/nginx-datadog/releases
148
- [ 13 ] : https://docs.datadoghq.com/tracing/
149
- [ 14 ] : https://docs.datadoghq.com/security/application_security/
133
+ Options:
134
+ - ` WAF=<ON|OFF> ` : Enable (` ON ` ) or disable (` OFF ` ) AppSec.
135
+ - ` ARCH=<amd64|aarch64> ` : Specify the CPU architecture.
136
+ - ` RESTY_VERSION=<version> ` : Specify the OpenResty version to build.
137
+
138
+ ### Building for ingress-nginx using Docker
139
+ > [ !NOTE]
140
+ > The ` build-ingress-nginx ` target builds against [ musl] ( https://www.musl-libc.org/ ) to guarantee portability.
141
+
142
+ To build the module for [ ingress-nginx] [ 8 ] :
143
+
144
+ ``` shell
145
+ WAF=ON ARCH=amd64 INGRESS_NGINX_VERSION=1.11.2 make build-ingress-nginx
146
+ ```
150
147
148
+ Options:
149
+ - ` WAF=<ON|OFF> ` : Enable (` ON ` ) or disable (` OFF ` ) AppSec.
150
+ - ` ARCH=<amd64|aarch64> ` : Specify the CPU architecture.
151
+ - ` INGRESS_NGINX_VERSION=<version> ` : Specify the version [ ingress-nginx] [ 8 ] to build.
152
+
153
+ ## Acknowledgements
154
+ This project is based largely on previous work. See [ CREDITS.md] ( CREDITS.md ) .
155
+
156
+ [ 1 ] : https://docs.datadoghq.com/tracing/
157
+ [ 2 ] : https://docs.datadoghq.com/security/application_security/
158
+ [ 3 ] : https://github.com/DataDog/nginx-datadog/releases
159
+ [ 4 ] : https://www.nginx.com/blog/nginx-1-18-1-19-released/
160
+ [ 5 ] : https://github.com/DataDog/nginx-datadog/blob/535a291ce96d8ca80cb12b22febac1e138e45847/src/tracing_library.cpp#L187-L203
161
+ [ 6 ] : https://github.com/DataDog/dd-trace-cpp/blob/main/include/datadog/environment.h
162
+ [ 7 ] : https://git-scm.com/book/en/v2/Git-Tools-Submodules
163
+ [ 8 ] : https://github.com/kubernetes/ingress-nginx
151
164
<!-- vim: set tw=80: -->
0 commit comments