Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nginx instrumentation #494

Merged
merged 18 commits into from
Nov 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove toml config
compile with latest nginx
add new configuration options to replace toml
  • Loading branch information
seemk committed Nov 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 80761b56040eb83aa8b9e09bdf2341914d42bdfd
12 changes: 4 additions & 8 deletions .github/workflows/nginx.yml
Original file line number Diff line number Diff line change
@@ -19,20 +19,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-24.04, debian-11]
nginx-rel: [mainline, stable]
nginx-version: [mainline, stable]
steps:
- name: checkout otel nginx
uses: actions/checkout@v3
- name: setup
run: |
sudo ./instrumentation/nginx/ci/setup_environment.sh
- name: generate dockerfile
run: |
cd instrumentation/nginx/test/instrumentation
mix local.hex --force --if-missing
mix local.rebar --force --if-missing
mix deps.get
mix dockerfiles .. ${{ matrix.os }}:${{ matrix.nginx-rel }}
- name: setup buildx
id: buildx
uses: docker/setup-buildx-action@master
@@ -73,6 +66,9 @@ jobs:
- name: run tests
run: |
cd instrumentation/nginx/test/instrumentation
mix local.hex --force --if-missing
mix local.rebar --force --if-missing
mix deps.get
mix test
- name: copy artifacts
id: artifacts
2 changes: 0 additions & 2 deletions instrumentation/nginx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/nginx.cmake)

add_library(otel_ngx_module SHARED
src/nginx_config.cpp
src/toml.c
src/agent_config.cpp
src/trace_context.cpp
src/otel_ngx_module.cpp
src/otel_ngx_module_modules.c
74 changes: 8 additions & 66 deletions instrumentation/nginx/README.md
Original file line number Diff line number Diff line change
@@ -10,20 +10,14 @@ Supported propagation types:

* OS: Linux. Test suite currently runs on Ubuntu 18.04, 20.04, 20.10.
* [Nginx](http://nginx.org/en/download.html)
* both stable (`1.18.0`) and mainline (`1.19.8`)
* Nginx modules
* ngx_http_upstream_module (proxy_pass)
* ngx_http_fastcgi_module (fastcgi_pass)

Additional platforms and/or versions coming soon.


## Dependencies (for building)

1. [gRPC](https://github.com/grpc/grpc) - currently the only supported exporter is OTLP_GRPC. This requirement will be lifted
once more exporters become available.
2. [opentelemetry-cpp](https://github.com/open-telemetry/opentelemetry-cpp) - opentelemetry-cpp needs to be built with
position independent code and OTLP_GRPC support, e.g.:
position independent code, e.g.:
```
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DWITH_OTLP_GRPC=ON ..
```
@@ -37,15 +31,18 @@ cmake ..
make
```

## Usage
## Quick usage

Download the .so file from the latest [GitHub Action run](https://github.com/open-telemetry/opentelemetry-cpp-contrib/actions/workflows/nginx.yml) or follow the instructions above to build. Then modify nginx.conf, or see the [example](test/conf/nginx.conf)

```
load_module /path/to/otel_ngx_module.so;

processor = "simple"

http {
opentelemetry_config /conf/otel-nginx.toml;
opentelemetry_service_name "nginx-proxy";
opentelemetry_otlp_traces_endpoint "http://collector:4318/v1/traces"

server {
listen 80;
@@ -56,7 +53,7 @@ http {
location = / {
opentelemetry_operation_name my_example_backend;
opentelemetry_propagate;
proxy_pass http://localhost:3500/;
proxy_pass http://localhost:3501/;
}

location = /b3 {
@@ -79,52 +76,6 @@ http {

```

Example [otel-nginx.toml](test/conf/otel-nginx.toml):
```toml
exporter = "otlp"
processor = "batch"

[exporters.otlp]
# Alternatively the OTEL_EXPORTER_OTLP_ENDPOINT environment variable can also be used.
host = "localhost"
port = 4317
# Optional: enable SSL, for endpoints that support it
# use_ssl = true
# Optional: set a filesystem path to a pem file to be used for SSL encryption
# (when use_ssl = true)
# ssl_cert_path = "/path/to/cert.pem"

[processors.batch]
max_queue_size = 2048
schedule_delay_millis = 5000
max_export_batch_size = 512

[service]
# Can also be set by the OTEL_SERVICE_NAME environment variable.
name = "nginx-proxy" # Opentelemetry resource name

[sampler]
name = "AlwaysOn" # Also: AlwaysOff, TraceIdRatioBased
ratio = 0.1
parent_based = false
```

Here's what it would look like if you used the OTLP exporter, but only set the endpoint with an environment variables (e.g. `OTEL_EXPORTER_OTLP_ENDPOINT="localhost:4317"`).
```toml
exporter = "otlp"
processor = "batch"

[exporters.otlp]

[processors.batch]
max_queue_size = 2048
schedule_delay_millis = 5000
max_export_batch_size = 512

[service]
name = "nginx-proxy" # Opentelemetry resource name
```

To use other environment variables defined in the [specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md), must add the "env" directive.

```
@@ -164,14 +115,6 @@ Adds a custom attribute to the span. It is possible to access nginx variables, e
- **syntax**: `opentelemetry_attribute <key> <value>`
- **block**: `http`, `server`, `location`

### `opentelemetry_config`

Exporters, processors

- **required**: `true`
- **syntax**: `opentelemetry_config /path/to/config.toml`
- **block**: `http`

### `opentelemetry_operation_name`

Set the operation name when starting a new span.
@@ -274,8 +217,7 @@ apk --no-cache add docker-compose docker-cli

```
cd test/instrumentation
mix dockerfiles .. ubuntu-20.04:mainline
docker build -t otel-nginx-test/nginx -f ../Dockerfile.ubuntu-20.04.mainline ../..
docker build -t otel-nginx-test/nginx -f ../Dockerfile ../..
docker build -t otel-nginx-test/express-backend -f ../backend/simple_express/Dockerfile ../backend/simple_express
mix test
```
3 changes: 0 additions & 3 deletions instrumentation/nginx/config
Original file line number Diff line number Diff line change
@@ -9,16 +9,13 @@ ngx_module_deps=" \
$ngx_addon_dir/src/nginx_utils.h \
$ngx_addon_dir/src/propagate.h \
$ngx_addon_dir/src/script.h \
$ngx_addon_dir/src/toml.h \
$ngx_addon_dir/src/trace_context.h \
"
ngx_module_srcs=" \
$ngx_addon_dir/src/agent_config.cpp \
$ngx_addon_dir/src/nginx_config.cpp \
$ngx_addon_dir/src/otel_ngx_module.cpp \
$ngx_addon_dir/src/propagate.cpp \
$ngx_addon_dir/src/script.cpp \
$ngx_addon_dir/src/toml.c \
$ngx_addon_dir/src/trace_context.cpp \
"
ngx_module_libs=" \
Loading