OpenResty
설정¶
DDTrace 설정¶
Tracing 모듈 다운로드¶
https://github.com/DataDog/nginx-datadog/releases 에 접속하여 Assets에서 현재 프로세서 아키텍처와 버전에 맞는 모듈 openresty-ngx_http_datadog_module-<프로세서 아키텍처>-<버전>.so.tgz을 찾아 다운로드하세요.
Tracing 설치¶
- 모듈 경로 생성
- 압축 해제
root@root:/usr/local/openresty/nginx/modules$ tar xzvf openresty-ngx_http_datadog_module-<프로세서 아키텍처>-<버전>.so.tgz
Nginx 설정¶
/usr/local/openresty/nginx/samples/nginx.conf 에 다음 내용을 추가합니다.
# 모듈 로드
load_module modules/ngx_http_datadog_module.so;
worker_processes 1;
events {
worker_connections 1024;
}
http {
# Datakit URL 설정
datadog_agent_url http://localhost:9529;
# 서비스 이름 설정
datadog_service_name openresty-demo;
# 환경 이름 설정
datadog_environment test;
# 버전 이름 설정
datadog_version 1.0.0;
# 샘플링 비율 설정 0-1.0
datadog_sample_rate 1.0;
# 태그 설정
datadog_tag foo bar;
include mime.types;
default_type application/octet-stream;
# $datadog_trace_id 와 $datadog_span_id를 통해 로그에 trace_id와 span_id를 추가하며, 둘 다 16진수
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'"$datadog_trace_id" "$datadog_span_id"';
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
OpenResty 재시작¶
생략
DataKit 수집 활성화¶
ddtrace활성화
- DataKit 재시작
OpenTelemetry 설정¶
ngx_otel_module 모듈 빌드¶
- 빌드 도구와 의존 항목 설치
sudo apt update
sudo apt install cmake build-essential libssl-dev zlib1g-dev libpcre3-dev
sudo apt install pkg-config libc-ares-dev libre2-dev # for gRPC
- OpenResty에서 사용하는 Nginx 버전과 컴파일 설정 확인
다음은 출력 예시입니다.
openresty -V
#nginx version: openresty/1.25.3.2
#built with OpenSSL 1.1.1w 11 Sep 2023
#TLS SNI support enabled
#configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl111/include' --add-module=../ngx_devel_kit-0.3.3 ············
- 해당 버전의 Nginx 소스 코드 다운로드
git clone https://github.com/nginx/nginx.git
cd nginx
git checkout {OPENRESTY_NGINX_VERSION} # 해당 버전 Tag로 전환
{OPENRESTY_NGINX_VERSION}을 해당 버전 Tag로 바꿉니다. 예를 들어 1.25.3.2 버전의 경우 대응하는 버전 Tag는 release-1.25.3입니다.
- Nginx 컴파일 파라미터 설정
Nginx 소스 루트 디렉터리에서 다음 명령을 실행합니다.
{NGINX_CONFIGURE_ARGUMENTS}은 가져온 configure arguments 내용이며, --add-module 관련 파라미터 설정을 제거합니다.
- ngx_otel_module 모듈 소스 다운로드
- ngx_otel_module 모듈 컴파일
build 디렉터리를 생성하고 들어가서 컴파일하며, 컴파일이 완료되면 build 디렉터리에 ngx_otel_module.so 파일이 생성됩니다.
ngx_otel_module 모듈 활성화¶
- ngx_otel_module.so 모듈 파일을 nginx modules 디렉터리로 복사
mkdir -p /usr/local/openresty/nginx/modules/
cp ngx_otel_module.so /usr/local/openresty/nginx/modules/
- nginx.conf 설정
OpenResty에서 트레이스 추적을 사용하려면 Nginx 메인 설정 파일 /usr/local/openresty/nginx/conf/nginx.conf에서 ngx_otel_module 모듈을 로드하고 설정 항목을 추가해야 합니다. ngx_otel_module 모듈은 현재 gRPC 방식 전송만 지원하며 HTTP 방식 전송은 지원하지 않습니다. ngx_otel_module 모듈의 자세한 파라미터 설정은 ngx_otel_module 문서를 참고하세요.
load_module modules/ngx_otel_module.so; # ngx_otel_module 로드
...
http {
...
otel_exporter {
endpoint "127.0.0.1:4317"; # gRPC 접속 지점
#header Authentication "${GRPC_TOKEN}"; # 전제 조건에서 가져온 인증 Token
}
otel_trace on; # 트레이스 추적 활성화
otel_service_name openresty-otel; # 애플리케이션 이름
otel_trace_context propagate; # 하위 서비스로 Trace 컨텍스트 주입
...
}
- nginx.conf 설정이 올바른지 확인
- 설정 다시 로드
# 방법 1: openresty 명령으로 설정 다시 로드
openresty -s reload
# 방법 2: nginx 명령으로 설정 다시 로드
/usr/local/openresty/nginx/sbin/nginx -s reload
DataKit 수집 활성화¶
- OpenTelemetry 수집기 활성화
# 수집기 설정 파일 디렉터리로 이동
cd /usr/local/datakit/conf.d/samples
# 설정 파일 활성화
cp opentelemetry.conf.sample opentelemetry.conf
- Datakit 재시작