ngx_otel_module 모듈
ngx_otel_module 모듈은 OpenTelemetry 분산 추적 지원을 제공해요. 이 모듈은 W3C 컨텍스트 전파와 OTLP/gRPC 내보내기 프로토콜을 지원해요.
모듈의 소스 코드는 여기에서 확인할 수 있고, 다운로드 및 설치 방법은 여기에서 확인할 수 있어요.
이 모듈은 1.25.3부터 사전 빌드된 nginx-module-otel 패키지로도 제공되며, 상용 구독의 일부로 1.23.4부터 nginx-plus-module-otel 패키지로도 제공돼요.
출처: 문서
본문
예시 구성 (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;
}
}
}
지시어 (Directives)
| Syntax: | otel_exporter { ... } |
|---|---|
| Default: | — |
| Context: | http |
OTel 데이터 내보내기 매개변수를 지정해요:
endpoint [(http|https)://]host:port;
텔레메트리 데이터를 수락할 OTLP/gRPC 엔드포인트예요. TLS는 0.1.2부터 지원돼요.
trusted_certificate path;
TLS 엔드포인트를 검증하는 데 사용하는 PEM 형식의 CA 인증서 파일이에요 (0.1.2부터). 기본값은 OS가 제공하는 CA 번들이에요.
header name value;
텔레메트리 내보내기 요청에 추가할 사용자 정의 HTTP 헤더예요 (0.1.2부터).
interval time;
두 번의 내보내기 사이의 최대 간격이에요. 기본값은 5초예요.
batch_size number;
워커당 한 배치로 보낼 수 있는 최대 스팬 수예요. 기본값은 512예요.
batch_count number;
워커당 대기 중인 배치 수예요. 한도를 초과하는 스팬은 버려져요. 기본값은 4예요.
예시:
otel_exporter {
endpoint https://otel-example.nginx.com:4317;
header X-API-Token "my-token-value";
}
| Syntax: | otel_service_name name; |
|---|---|
| Default: | ``` |
| otel_service_name unknown_service:nginx; | |
| ``` | |
| Context: | http |
OTel 리소스의 "service.name" 속성을 설정해요.
| Syntax: | otel_resource_attr name value; |
|---|---|
| Default: | — |
| Context: | http |
이 지시어는 0.1.2 버전에서 추가되었어요.
사용자 정의 OTel 리소스 속성을 설정해요.
| Syntax: | otel_trace on | off | $variable; |
|---|---|---|---|
| Default: | ``` | ||
| otel_trace off; | |||
| ``` | |||
| Context: | http, server, location |
OpenTelemetry 추적을 활성화하거나 비활성화해요. 변수를 지정해서도 활성화할 수 있어요:
split_clients "$otel_trace_id" $ratio_sampler {
10% on;
* off;
}
server {
location / {
otel_trace $ratio_sampler;
otel_trace_context inject;
proxy_pass http://backend;
}
}
| Syntax: | otel_trace_context extract | inject | propagate | ignore; |
|---|---|---|---|---|
| Default: | ``` | |||
| otel_trace_context ignore; | ||||
| ``` | ||||
| Context: | http, server, location |
traceparent/tracestate 헤더를 어떻게 전파할지 지정해요:
extract
요청에서 기존 트레이스 컨텍스트를 사용해요. 따라서 트레이스와 부모 스팬의 식별자가 들어오는 요청에서 상속돼요.
inject
요청에 새 컨텍스트를 추가하고, 기존 헤더가 있으면 덮어써요.
propagate
기존 컨텍스트를 갱신해요 (extract와 inject를 결합한 방식).
ignore
컨텍스트 헤더 처리를 건너뛰어요.
| Syntax: | otel_span_name name; |
|---|---|
| Default: | — |
| Context: | http, server, location |
OTel 스팬의 이름을 정의해요. 기본값은 요청에 대한 location의 이름이에요. 이름에는 변수를 포함할 수 있어요.
| Syntax: | otel_span_attr name value; |
|---|---|
| Default: | — |
| Context: | http, server, location |
사용자 정의 OTel 스팬 속성을 추가해요. 값에는 변수를 포함할 수 있어요.
기본 스팬 속성
다음 스팬 속성들이 자동으로 추가돼요:
- http.method
- http.target
- http.route
- http.scheme
- http.flavor
- http.user_agent
- http.request_content_length
- http.response_content_length
- http.status_code
- net.host.name
- net.host.port
- net.sock.peer.addr
- net.sock.peer.port
내장 변수 (Embedded Variables)
$otel_trace_id
현재 스팬이 속한 트레이스의 식별자예요. 예를 들어 56552bc4daa3bf39c08362527e1dd6c4
$otel_span_id
현재 스팬의 식별자예요. 예를 들어 4c0b8531ec38ca59
$otel_parent_id
부모 스팬의 식별자예요. 예를 들어 dc94d281b0f884ea
$otel_parent_sampled
부모 스팬의 "sampled" 플래그로, "1" 또는 "0"이 될 수 있어요.