Skip to content

Commit 4a6ba5c

Browse files
dmehaladubloom
andauthoredJan 14, 2025··
Improve README.md (#162)
Co-authored-by: Louis Tricot <[email protected]>
1 parent 2031e8c commit 4a6ba5c

File tree

4 files changed

+178
-71
lines changed

4 files changed

+178
-71
lines changed
 

‎CONTRIBUTING.md

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Developing `nginx-datadog`
2+
3+
This document describes the development process for `nginx-datadog`.
4+
It is intended for anyone considering opening an issue or pull request.
5+
6+
Building locally
7+
----------------
8+
```shell
9+
NGINX_VERSION=1.25.2 make build
10+
```
11+
12+
The resulting nginx module is `.build/ngx_http_datadog_module.so`.
13+
14+
If you encounter some **difficulties** building the module on **MacOS**, please look at the [troubleshooting section](#Troubleshooting).
15+
16+
The `build` target does the following:
17+
18+
- Download a source release of nginx based on the `NGINX_VERSION` environment variable.
19+
- Initialize the source tree of `dd-trace-cpp` as a git submodule.
20+
- Initialize the source tree of `libddwaf`as a git submodule.
21+
- Build `dd-trace-cpp` and the Datadog nginx module together using
22+
CMake.
23+
24+
`make clean` deletes CMake's build directory. `make clobber` deletes
25+
everything done by the build.
26+
27+
Testing
28+
-------
29+
30+
The makefile contains two target for testing:
31+
- `build-and-test`: builds and use the resultant module for testing
32+
- `test`: use the existing built module for testing
33+
34+
To run one or the other, you can use:
35+
36+
### Linux, MacOS AMD64
37+
```shell
38+
NGINX_VERSION=1.25.2 make build-and-test
39+
```
40+
### MacOS with Apple Silicon
41+
```shell
42+
NGINX_VERSION=1.25.2 ARCH=aarch64 make build-and-test
43+
```
44+
By default, it will launch the test on the `nginx:${NGINX_VERSION}-alpine` docker image.
45+
If you want to use another nginx image you can use:
46+
```shell
47+
BASE_IMAGE=nginx:1.25.2-alpine-slim make build-and-test
48+
```
49+
50+
### Additional test options
51+
To run the tests related to AppSec:
52+
```shell
53+
WAF=ON NGINX_VERSION=1.25.2 make build-and-test
54+
```
55+
56+
To run the tests using an openresty image:
57+
```shell
58+
RESTY_VERSION=1.27.1.1 make test-openresty
59+
```
60+
You can also specificy the openresty base image rather then the version using the `BASE_IMAGE` parameter.
61+
62+
You can pass on arguments to test suites using :
63+
```shell
64+
TEST_ARGS="foo=bar" NGINX_VERSION=1.25.2 make test
65+
```
66+
67+
For more information on tests, see [test/README.md](test/README.md).
68+
69+
Troubleshooting
70+
----------------
71+
### fatal error: 'pcre2.h' file not found on MacOS
72+
73+
If during the build of the module, you encounter this error, please ensure that pcre2 is installed on your device. If not, you can install it with:
74+
```shell
75+
brew install pcre2
76+
```
77+
If the build still does not work, you can use the flag `PCRE2_PATH` to specify the pcre2 installation folder it:
78+
```shell
79+
PCRE2_PATH=/opt/homebrew/Cellar/pcre2/10.44 NGINX_VERSION=1.25.2 make build
80+
```
81+

‎LICENSE-3rdparty.csv

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ Component,Origin,License,Copyright
22
vendored,dd-trace-cpp,Apache 2.0,Copyright 2022 Datadog Inc.
33
vendored,nlohmann/json,MIT,Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>
44
build,cmake,BSD-3-Clause,Copyright 2000-2018 Kitware Inc and Contributors
5-
parent,nginx-opentracing,Apache 2.0,N/A
5+
parent,nginx-opentracing,Apache 2.0,N/A
6+
vendored,rapidjson,MIT, "Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip."

‎Makefile

+16-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ COVERAGE ?= OFF
1313
BUILD_TESTING ?= ON
1414
DOCKER_REPOS ?= public.ecr.aws/b1o7r7e0/nginx_musl_toolchain
1515
CIRCLE_CFG ?= .circleci/continue_config.yml
16+
ifneq ($(PCRE2_PATH),)
17+
CMAKE_PCRE_OPTIONS := -DCMAKE_C_FLAGS=-I$(PCRE2_PATH)/include/ -DCMAKE_CXX_FLAGS=-I$(PCRE2_PATH)/include/ -DCMAKE_LDFLAGS=-L$(PCRE2_PATH)/lib
18+
endif
1619

1720
SHELL := /bin/bash
1821

1922
.PHONY: build
2023
build: build-deps sources
21-
# -DCMAKE_C_FLAGS=-I/opt/homebrew/Cellar/pcre2/10.42/include/ -DCMAKE_CXX_FLAGS=-I/opt/homebrew/Cellar/pcre2/10.42/include/ -DCMAKE_LDFLAGS=-L/opt/homebrew/Cellar/pcre2/10.42/lib -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
22-
cmake -B$(BUILD_DIR) -DNGINX_SRC_DIR=$(NGINX_SRC_DIR) \
24+
cmake -B $(BUILD_DIR) -DNGINX_SRC_DIR=$(NGINX_SRC_DIR) \
2325
-DNGINX_COVERAGE=$(COVERAGE) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DNGINX_DATADOG_ASM_ENABLED=$(WAF) -DNGINX_DATADOG_RUM_ENABLED=$(RUM) . \
24-
-DBUILD_TESTING=$(BUILD_TESTING) \
26+
-DBUILD_TESTING=$(BUILD_TESTING) $(CMAKE_PCRE_OPTIONS)\
2527
&& cmake --build $(BUILD_DIR) -j $(MAKE_JOB_COUNT) -v
2628
chmod 755 $(BUILD_DIR)/ngx_http_datadog_module.so
2729
@echo 'build successful 👍'
@@ -155,12 +157,22 @@ build-openresty-aux:
155157
&& cmake --build .openresty-build -j $(MAKE_JOB_COUNT) -v --target ngx_http_datadog_module \
156158

157159
.PHONY: test
158-
test: build-musl
160+
test:
159161
cp -v .musl-build/ngx_http_datadog_module.so* test/services/nginx/
160162
test/bin/run $(TEST_ARGS)
161163

162164
.PHONY: test-openresty
163165
test-openresty:
166+
cp -v .openresty-build/ngx_http_datadog_module.so* test/services/nginx/
167+
RESTY_TEST=ON test/bin/run $(TEST_ARGS)
168+
169+
.PHONY: build-and-test
170+
build-and-test: build-musl
171+
cp -v .musl-build/ngx_http_datadog_module.so* test/services/nginx/
172+
test/bin/run $(TEST_ARGS)
173+
174+
.PHONY: build-and-test-openresty
175+
build-and-test-openresty: build-openresty
164176
cp -v .openresty-build/ngx_http_datadog_module.so* test/services/nginx/
165177
test/bin/run $(TEST_ARGS)
166178

‎README.md

+79-66
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<img alt="datadog tracing nginx" src="mascot.svg" height="200"/>
22

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
55
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.
77

8-
Usage
9-
-----
8+
## Usage
109
1. Download a gzipped tarball from a [recent release][12], extract it to
1110
wherever nginx looks for modules (e.g. `/usr/lib/nginx/modules/`).
1211
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;
1918
Tracing is automatically added to all endpoints by default. For more
2019
information, see [the API documentation](doc/API.md).
2120

22-
Compatibility
23-
-------------
21+
## Compatibility
2422
> [!IMPORTANT]
2523
> 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
2725
> the four most recent NGINX versions.
2826
>
2927
> If you plan to add tracing features to an older NGINX version using our
3028
> module, please check out [the build section](#build) for guidance.
3129
3230
There are two tarballs (the actual executable module and, separately, the debug
3331
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,
3533
`ngx_http_datadog_module.so`, which is the Datadog nginx module.
3634

3735
The naming convention is:
@@ -51,26 +49,22 @@ While it _may_ be possible to build the extension against an older version, this
5149
is not guaranteed; in particular, AppSec builds require a feature introduced in
5250
version 1.21.4.
5351

54-
55-
Default Behavior
56-
----------------
52+
## Default Behavior
5753
Unless otherwise configured, `ngx_http_datadog_module` adds the following
58-
default behavior to nginx:
54+
default behavior to NGINX:
5955

6056
### Tracing
6157
- Connect to the Datadog agent at `http://localhost:8126`.
6258
- Create one span per request:
6359
- Service name is "nginx".
6460
- Operation name is "nginx.request".
6561
- 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].
6863

6964
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].
7166

72-
Enabling AppSec
73-
---------------
67+
## Enabling AppSec
7468

7569
To enable AppSec, besides using the correct binary (the relase artifact with
7670
"-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
8276

8377
For more information, see [the documentation](doc/API.md).
8478

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+
8894
- Recent C and C++ toolchain (`clang` or `gcc/g++`) (must support at least some
8995
C++20 features).
96+
- make.
9097
- CMake `v3.24` or newer.
91-
- Architecture must be `x86_64` or `arm64`.
98+
- Architecture is either `x86_64` or `arm64`.
9299

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.
94103

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.
98107
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.
101111
102112
```shell
103-
WAF=ON NGINX_VERSION=1.25.2 make build
113+
WAF=ON ARCH=amd64 NGINX_VERSION=1.27.1 make build-musl
104114
```
105115

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.
107120

108-
The `build` target does the following:
121+
The NGINX module will be generated at `.musl-build\ngx_http_datadog_module.so`.
109122

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.
114126
115-
`make clean` deletes CMake's build directory. `make clobber` deletes
116-
everything done by the build.
127+
To build the module for OpenResty:
117128

118-
Build in Docker
119-
---------------
120129
```shell
121-
make build-musl
130+
WAF=ON ARCH=amd64 RESTY_VERSION=1.27.1.1 make build-openresty
122131
```
123132

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+
```
150147

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
151164
<!-- vim: set tw=80: -->

0 commit comments

Comments
 (0)
Please sign in to comment.