Skip to content

Commit 1661cd8

Browse files
committed
Configure OpenTelemetry in nginx
1 parent ea80f2d commit 1661cd8

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

container/config-generator/templates/nginx.default.conf.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ server {
4242
server_name <%= env!('HOSTNAME') %>;
4343
<% end %>
4444

45+
<% if env?('OPENTELEMETRY_ENABLED') -%>
46+
otel_trace on;
47+
otel_trace_context propagate;
48+
otel_span_name "$request_method $request_uri";
49+
<% end -%>
50+
4551
location = /graphql {
4652
proxy_pass http://sagittarius_rails_web;
4753
proxy_set_header Host $host;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<% if env?('OPENTELEMETRY_ENABLED') -%>
2+
otel_exporter {
3+
endpoint <%= env!('OPENTELEMETRY_GRPC_HOST') %>;
4+
interval 5s;
5+
batch_size 512;
6+
batch_count 4;
7+
}
8+
9+
otel_service_name <%= env('OPENTELEMETRY_SERVICE_NAME_NGINX', 'nginx') %>;
10+
<% end -%>

docker-compose/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ VELORUM_JWT_SECRET=088cfc7a7fc2b07696d8ee5e1ea9d642
7272

7373
# OpenTelemetry
7474
OPENTELEMETRY_ENABLED=false
75+
OPENTELEMETRY_GRPC_HOST=http://localhost:4317
7576
OPENTELEMETRY_LOGS_HTTP_ENDPOINT=http://localhost:4318/v1/logs
7677
OPENTELEMETRY_METRICS_HTTP_ENDPOINT=http://localhost:4318/v1/metrics
7778
OPENTELEMETRY_TRACES_HTTP_ENDPOINT=http://localhost:4318/v1/traces

docker-compose/docker-compose.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ services:
128128
- ide_velorum
129129

130130
nginx:
131-
image: nginx:1.31.1-alpine-slim
131+
image: nginx:1.31.1-alpine-otel
132132
depends_on:
133133
config-generator:
134134
condition: service_completed_successfully
@@ -146,6 +146,10 @@ services:
146146
entrypoint: |
147147
sh -c "
148148
cp /tmp/generated-configs/nginx.default.conf /etc/nginx/conf.d/default.conf
149+
if [ -s /tmp/generated-configs/nginx.otel.conf ]; then
150+
sed -i '1i load_module modules/ngx_otel_module.so;' /etc/nginx/nginx.conf
151+
cp /tmp/generated-configs/nginx.otel.conf /etc/nginx/conf.d/otel.conf
152+
fi
149153
nginx -t
150154
exec nginx -g 'daemon off;'
151155
"

0 commit comments

Comments
 (0)