|
1 | | -# One worker process per CPU core |
| 1 | +# Load the OpenTelemetry (OTel) module for NGINX |
2 | 2 | load_module modules/ngx_otel_module.so; |
3 | | -worker_processes auto; |
4 | | -pid /tmp/nginx.pid; |
5 | | -env OTEL_EXPORTER_OTLP_ENDPOINT; |
| 3 | + |
| 4 | +worker_processes auto; # Use one worker per CPU core |
| 5 | +pid /tmp/nginx.pid; # PID file in /tmp (container-friendly) |
| 6 | +env OTEL_EXPORTER_OTLP_ENDPOINT; # Inherit the environment variable into NGINX |
6 | 7 |
|
7 | 8 | events { |
8 | | - worker_connections 2048; |
9 | | - use epoll; |
10 | | - multi_accept on; |
| 9 | + worker_connections 2048; # Max connections per worker |
| 10 | + use epoll; # Efficient Linux event notification mechanism |
| 11 | + multi_accept on; # Accept multiple connections at once |
11 | 12 | } |
12 | 13 |
|
13 | 14 | http { |
14 | | - map $env_OTEL_EXPORTER_OTLP_ENDPOINT $otel_exporter_endpoint { |
15 | | - default $env_OTEL_EXPORTER_OTLP_ENDPOINT; |
| 15 | + # Map the environment variable to a configuration variable, with fallback |
| 16 | + map $OTEL_EXPORTER_OTLP_ENDPOINT $otel_exporter_endpoint { |
| 17 | + default $OTEL_EXPORTER_OTLP_ENDPOINT; |
16 | 18 | "" "http://grafana-tempo.grafana:4317"; |
17 | 19 | } |
18 | 20 |
|
| 21 | + # OpenTelemetry exporter configuration |
19 | 22 | otel_exporter { |
20 | | - endpoint $otel_exporter_endpoint; |
21 | | - interval 1s; |
22 | | - batch_size 2048; |
23 | | - } |
24 | | - |
25 | | - map $request_time $adaptive_sample { |
26 | | - ~^0\.[0-4] 0.001; |
27 | | - ~^0\.[5-9] 0.01; |
28 | | - ~^[1-2]\. 0.1; |
29 | | - default 1.0; |
| 23 | + endpoint $otel_exporter_endpoint; # Send spans to this endpoint |
| 24 | + interval 1s; # Flush interval |
| 25 | + batch_size 2048; # Maximum spans per batch |
30 | 26 | } |
31 | 27 |
|
32 | | - otel_service_name "shortlink-ui"; |
33 | | - otel_trace on; |
34 | | - otel_trace_context propagate; |
| 28 | + otel_service_name "shortlink-ui"; # Service name seen in tracing backend |
| 29 | + otel_trace on; # Enable tracing for HTTP requests |
| 30 | + otel_trace_context propagate; # Propagate W3C trace context to upstream |
35 | 31 |
|
36 | | - # Temp paths (safe for container environments) |
| 32 | + # Temporary file paths (suitable for containers) |
37 | 33 | proxy_temp_path /tmp/proxy_temp; |
38 | 34 | client_body_temp_path /tmp/client_temp; |
39 | 35 | fastcgi_temp_path /tmp/fastcgi_temp; |
40 | 36 | uwsgi_temp_path /tmp/uwsgi_temp; |
41 | 37 | scgi_temp_path /tmp/scgi_temp; |
42 | 38 |
|
43 | | - # Static file optimizations |
| 39 | + # Static file & connection optimisations |
44 | 40 | sendfile on; |
45 | 41 | tcp_nopush on; |
46 | 42 | tcp_nodelay on; |
47 | 43 | keepalive_timeout 65s; |
48 | 44 | keepalive_requests 1000; |
49 | 45 |
|
50 | | - # MIME types |
51 | 46 | include /etc/nginx/mime.types; |
52 | 47 | default_type application/octet-stream; |
53 | 48 |
|
54 | | - # Logging |
| 49 | + # Logging in JSON format, including trace IDs |
55 | 50 | map $upstream_response_time $temprt { |
56 | 51 | default $upstream_response_time; |
57 | 52 | "" 0; |
58 | 53 | } |
59 | 54 |
|
60 | 55 | log_format json escape=json |
61 | | - '{ "@timestamp": "$time_iso8601", ' |
62 | | - '"remote_addr": "$remote_addr", ' |
63 | | - '"body_bytes_sent": "$body_bytes_sent", ' |
64 | | - '"status": $status, ' |
65 | | - '"request": "$request", ' |
66 | | - '"url": "$uri", ' |
67 | | - '"request_method": "$request_method", ' |
68 | | - '"response_time": $temprt, ' |
69 | | - '"trace_id": "$otel_trace_id", ' |
70 | | - '"span_id": "$otel_span_id", ' |
71 | | - '"http_referrer": "$http_referer", ' |
72 | | - '"http_user_agent": "$http_user_agent" }'; |
| 56 | + '{ "@timestamp":"$time_iso8601",' |
| 57 | + '"remote_addr":"$remote_addr",' |
| 58 | + '"body_bytes_sent":"$body_bytes_sent",' |
| 59 | + '"status":$status,' |
| 60 | + '"request":"$request",' |
| 61 | + '"url":"$uri",' |
| 62 | + '"request_method":"$request_method",' |
| 63 | + '"response_time":"$temprt",' |
| 64 | + '"trace_id":"$otel_trace_id",' |
| 65 | + '"span_id":"$otel_span_id",' |
| 66 | + '"http_referrer":"$http_referer",' |
| 67 | + '"http_user_agent":"$http_user_agent"}'; |
73 | 68 |
|
74 | | - access_log /var/log/nginx/access.log json; |
75 | | - error_log /var/log/nginx/error.log warn; |
| 69 | + access_log /var/log/nginx/access.log json; |
| 70 | + error_log /var/log/nginx/error.log warn; |
76 | 71 |
|
77 | | - # Gzip compression (no double-compress on already-compressed formats) |
| 72 | + # Gzip compression settings |
78 | 73 | gzip on; |
79 | 74 | gzip_min_length 10240; |
80 | 75 | gzip_proxied any; |
|
88 | 83 | application/javascript |
89 | 84 | image/svg+xml; |
90 | 85 |
|
| 86 | + # Include other server/location configs |
91 | 87 | include /etc/nginx/conf.d/*; |
92 | 88 | } |
0 commit comments