OTel SDK 투입
javaagent를 붙이니 SQL 통신 등도 알아서 추적이 됐고, 로그에도 trace_id와 span_id가 자동으로 붙더라. 애플리케이션 코드를 수정할 필요가 없어서 도입 부담이 거의 없었다.
# JVM 옵션에 javaagent 추가
-javaagent:/opentelemetry-javaagent.jar
-Dotel.resource.attributes=service.name=my-service
-Dotel.traces.exporter=otlp
-Dotel.exporter.otlp.endpoint=http://otel-collector.otel-collector.svc:4318trace_id와 span_id
javaagent가 MDC(Mapped Diagnostic Context)에 trace_id와 span_id를 주입한다. Spring Boot의 기본 로그 포맷에서 MDC 값을 출력하도록만 하면, 모든 로그 라인에 trace_id가 붙는다.
# logback-spring.xml
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] [%X{trace_id}] %-5level %logger - %msg%n</pattern>이제 로그에서 trace_id를 SigNoz에 검색하면, 해당 요청의 전체 분산 추적을 볼 수 있다.
otel collector 설정
collector는 daemonset으로 배포했다. 노드마다 하나씩 떠서 메트릭·로그·트레이스를 수집하고 SigNoz로 넘긴다.
# otel-collector values
mode: daemonset
config:
receivers:
kubeletstats:
auth_type: serviceAccount
collection_interval: 30s
endpoint: ${env:K8S_NODE_IP}:10250
insecure_skip_verify: true
metric_groups:
- pod
- node
- volume설정이 꽤나 간결한 편이다. (추가해야 하는 설정이 더 있을지 모르겠지만, 현재는 이 정도로 잘 돌고 있다.)