텔레메트리 변환
OpenTelemetry Collector는 데이터를 벤더나 다른 시스템으로 보내기 전에 변환하기 좋은 위치이며, 데이터 품질·거버넌스·비용·보안 측면에서 자주 활용됩니다.
출처: 문서
본문
OpenTelemetry Collector는 데이터를 벤더나 다른 시스템으로 보내기 전에 변환하기 좋은 위치입니다. 이는 데이터 품질, 거버넌스, 비용, 보안 등의 이유로 자주 수행됩니다.
Collector Contrib 저장소에서 제공하는 processor는 metric, span, log 데이터에 대해 수십 가지의 다양한 변환을 지원합니다. 다음 절에서는 자주 사용되는 몇 가지 processor로 시작하는 기본 예제를 제공합니다.
processor의 구성, 특히 고급 변환은 collector 성능에 상당한 영향을 줄 수 있습니다.
기본 필터링
Processor: filter processor
filter processor는 OTTL을 사용해 텔레메트리를 필터링할 수 있게 해줍니다. 어떤 조건과 일치하는 텔레메트리는 버려집니다(drop).
예를 들어 app1, app2, app3 서비스의 span 데이터만 허용하고 다른 모든 서비스의 데이터는 버리려면:
processors:
filter/ottl:
error_mode: ignore
traces:
span:
- |
resource.attributes["service.name"] != "app1" and
resource.attributes["service.name"] != "app2" and
resource.attributes["service.name"] != "app3"
service1이라는 서비스의 span만 버리고 다른 모든 span은 유지하려면:
processors:
filter/ottl:
error_mode: ignore
traces:
span:
- resource.attributes["service.name"] == "service1"
filter processor 문서에는 log와 metric 필터링을 포함한 더 많은 예제가 있습니다.
속성 추가 또는 삭제
Processor: attributes processor 또는 resource processor
attributes processor는 metric이나 trace에 존재하는 속성을 업데이트, 삽입, 삭제 또는 교체하는 데 사용할 수 있습니다. 예를 들어 다음 구성은 account_id라는 속성을 모든 span에 추가합니다:
processors:
attributes/accountid:
actions:
- key: account_id
value: 2245
action: insert
resource processor는 동일한 구성을 가지지만 resource 속성에만 적용됩니다. resource processor를 사용해 텔레메트리와 관련된 인프라 메타데이터를 수정하세요. 예를 들어 다음은 Kubernetes 클러스터 이름을 삽입합니다:
processors:
resource/k8s:
attributes:
- key: k8s.cluster.name
from_attribute: k8s-cluster
action: insert
Metric 또는 Metric 레이블 이름 바꾸기
Processor: metrics transform processor
metrics transform processor는 attributes processor와 일부 기능을 공유하지만, 이름 바꾸기와 같은 metric 특화 기능도 지원합니다.
processors:
metricstransform/rename:
transforms:
- include: system.cpu.usage
action: update
new_name: system.cpu.usage_time
metrics transform processor는 정규 표현식도 지원하여 여러 metric 이름이나 metric 레이블에 변환 규칙을 동시에 적용할 수 있습니다. 다음 예제는 모든 metric에 대해 cluster_name을 cluster-name으로 바꿉니다:
processors:
metricstransform/clustername:
transforms:
- include: ^.*$
match_type: regexp
action: update
operations:
- action: update_label
label: cluster_name
new_label: cluster-name
Resource 속성으로 텔레메트리 보강하기
Processor: resource detection processor와 k8sattributes processor
이 processor들은 관련 인프라 메타데이터로 텔레메트리를 보강하여 팀이 기본 인프라가 서비스 상태나 성능에 영향을 미칠 때 빠르게 식별하도록 도와줍니다.
resource detection processor는 관련 클라우드 또는 호스트 수준 정보를 텔레메트리에 추가합니다:
processors:
resourcedetection/system:
# Modify the list of detectors to match the cloud environment
detectors: [env, system, gcp, ec2, azure]
timeout: 2s
override: false
마찬가지로 K8s processor는 pod 이름, 노드 이름, 워크로드 이름과 같은 관련 Kubernetes 메타데이터로 텔레메트리를 보강합니다. collector pod는 특정 Kubernetes RBAC API에 대한 읽기 권한을 갖도록 구성되어야 합니다. 기본 옵션을 사용하려면 빈 블록으로 구성할 수 있습니다:
processors:
k8sattributes/default:
Span 상태 설정
Processor: transform processor
transform processor를 사용해 span의 상태를 설정하세요. 다음 예제는 http.request.status_code 속성이 400일 때 span 상태를 Ok로 설정합니다:
transform:
error_mode: ignore
trace_statements:
- set(span.status.code, STATUS_CODE_OK) where span.attributes["http.request.status_code"] == 400
span 이름을 속성에 따라 수정하거나 span 이름에서 span 속성을 추출하는 데에도 transform processor를 사용할 수 있습니다. 예제는 transform processor의 예제 config 파일을 참조하세요.
고급 변환
더 고급 속성 변환도 transform processor에서 사용할 수 있습니다. transform processor는 OpenTelemetry Transformation Language를 사용해 metric, log, trace에 대한 변환을 지정할 수 있게 해줍니다.