1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
|
=encoding utf-8
=head1 NAME
ngx_otel_module - Module ngx_otel_module
=head1
The C<ngx_otel_module> module (1.23.4) provides
L<OpenTelemetry|https://opentelemetry.io>
distributed tracing support.
The module supports
L<W3C|https://w3c.github.io/trace-context>
context propagation and OTLPE<sol>gRPC export protocol.
The source code of the module is available
L<here|https://github.com/nginxinc/nginx-otel>.
Download and install instructions are available
L<here|https://github.com/nginxinc/nginx-otel/blob/main/README.md>.
The module is also available in a prebuilt
C<nginx-module-otel>
L<package|linux_packages>
since 1.25.3
and in C<nginx-plus-module-otel> package
as part of our
commercial subscription.
=head1 Example Configuration
load_module modules/ngx_otel_module.so;
events {
}
http {
otel_exporter {
endpoint localhost:4317;
}
server {
listen 127.0.0.1:8080;
location / {
otel_trace on;
otel_trace_context inject;
proxy_pass http://backend;
}
}
}
=head1 Directives
=head2 otel_exporter
otel_exporter { B<...> }
B<context:> I<http>
Specifies OTel data export parameters:
=over
=item C<endpoint>
the address of OTLPE<sol>gRPC endpoint that will accept telemetry data.
=item C<interval>
the maximum interval between two exports,
by default is C<5> seconds.
=item C<batch_size>
the maximum number of spans to be sent in one batch per worker,
by default is C<512>.
=item C<batch_count>
the number of pending batches per worker,
spans exceeding the limit are dropped,
by default is C<4>.
=back
Example:
otel_exporter {
endpoint localhost:4317;
interval 5s;
batch_size 512;
batch_count 4;
}
=head2 otel_service_name
B<syntax:> otel_service_name I<I<C<name>>>
B<default:> I<unknown_service:nginx>
B<context:> I<http>
Sets the
“L<C<service.name>|https://opentelemetry.io/docs/reference/specification/resource/semantic_conventions/#service>”
attribute of the OTel resource.
=head2 otel_trace
B<syntax:> otel_trace I<C<on> E<verbar>
C<off> E<verbar>
C<$variable>>
B<default:> I<off>
B<context:> I<http>
B<context:> I<server>
B<context:> I<location>
Enables or disables OpenTelemetry tracing.
The directive can also be enabled by specifying a variable:
split_clients "$otel_trace_id" $ratio_sampler {
10% on;
* off;
}
server {
location / {
otel_trace $ratio_sampler;
otel_trace_context inject;
proxy_pass http://backend;
}
}
=head2 otel_trace_context
B<syntax:> otel_trace_context I<C<extract> E<verbar>
C<inject> E<verbar>
C<propagate> E<verbar>
C<ignore>>
B<default:> I<ignore>
B<context:> I<http>
B<context:> I<server>
B<context:> I<location>
Specifies how to propagate
L<traceparentE<sol>tracestate|https://www.w3.org/TR/trace-context/#design-overview> headers:
=over
=item C<extract>
uses an existing trace context from the request,
so that the identifiers of
a trace and
the parent span
are inherited from the incoming request.
=item C<inject>
adds a new context to the request, overwriting existing headers, if any.
=item C<propagate>
updates the existing context
(combines L</extract> and L</inject>).
=item C<ignore>
skips context headers processing.
=back
=head2 otel_span_name
B<syntax:> otel_span_name I<I<C<name>>>
B<context:> I<http>
B<context:> I<server>
B<context:> I<location>
Defines the name of the OTel
L<span|https://opentelemetry.io/docs/concepts/observability-primer/#spans>.
By default, it is a name of the location for a request.
The name can contain variables.
=head2 otel_span_attr
B<syntax:> otel_span_attr I<I<C<name>> I<C<value>>>
B<context:> I<http>
B<context:> I<server>
B<context:> I<location>
Adds a custom OTel span attribute.
The value can contain variables.
=head1 Default span attributes
The following L<span attributes|https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md>
are added automatically:
=over
=item *
C<http.method>
=item *
C<http.target>
=item *
C<http.route>
=item *
C<http.scheme>
=item *
C<http.flavor>
=item *
C<http.user_agent>
=item *
C<http.request_content_length>
=item *
C<http.response_content_length>
=item *
C<http.status_code>
=item *
C<net.host.name>
=item *
C<net.host.port>
=item *
C<net.sock.peer.addr>
=item *
C<net.sock.peer.port>
=back
=head1 Embedded Variables
=over
=item C<$otel_trace_id>
the identifier of the trace the current span belongs to,
for example, C<56552bc4daa3bf39c08362527e1dd6c4>
=item C<$otel_span_id>
the identifier of the current span,
for example, C<4c0b8531ec38ca59>
=item C<$otel_parent_id>
the identifier of the parent span,
for example, C<dc94d281b0f884ea>
=item C<$otel_parent_sampled>
the “C<sampled>” flag of the parent span,
can be “C<1>” or “C<0>”
=back
|