fix(opentelemetry): restore and configure k8sattributes processor for enhanced metadata extraction

Signed-off-by: zhenyus <zhenyus@mathmast.com>
This commit is contained in:
zhenyus 2025-04-21 17:28:25 +08:00
parent c08ddf7f76
commit 9ceaaa3e0b

View File

@ -29,35 +29,44 @@ spec:
parse_from: body parse_from: body
parse_to: attributes parse_to: attributes
processors: processors:
# k8sattributes: k8sattributes:
# auth_type: serviceAccount auth_type: serviceAccount
# wait_for_metadata: true wait_for_metadata: true
# wait_for_metadata_timeout: 10s wait_for_metadata_timeout: 5s
# passthrough: false passthrough: false
# extract: extract:
# metadata: metadata:
# - k8s.pod.name - k8s.pod.name
# - k8s.pod.ip - k8s.pod.ip
# - k8s.pod.uid - k8s.pod.uid
# - k8s.deployment.name - k8s.deployment.name
# - k8s.deployment.uid - k8s.deployment.uid
# - k8s.namespace.name - k8s.namespace.name
# - k8s.node.name - k8s.node.name
# resource: pod_association:
# attributes: - sources:
# - action: upsert - from: resource_attributes
# key: application name: k8s.pod.name
# from_attribute: context.app - sources:
# - action: upsert - from: resource_attributes
# key: environment name: k8s.pod.uid
# from_attribute: context.env - source:
- from: connection
transform: transform:
log_statements: log_statements:
- context: log - context: log
statements: statements:
- set(log.body["kubernetes"], log.attributes["kubernetes"])
- set(resource.attributes["application"], log.attributes["context"]["app"]) - set(resource.attributes["application"], log.attributes["context"]["app"])
- set(resource.attributes["environment"], log.attributes["context"]["env"]) - set(resource.attributes["environment"], log.attributes["context"]["env"])
- set(resource.attributes["kubernetes_node_name"])
- set(log.body["kubernetes"]["pod"], resource.attributes["k8s.pod.name"])
- set(log.body["kubernetes"]["namespace"], resource.attributes["k8s.namespace.name"])
- set(log.body["kubernetes"]["pod_ip"], resource.attributes["k8s.pod.ip"])
- set(log.body["kubernetes"]["pod_uid"], resource.attributes["k8s.pod.uid"])
- set(log.body["kubernetes"]["deployment"], resource.attributes["k8s.deployment.name"])
- set(log.body["kubernetes"]["deployment_uid"], resource.attributes["k8s.deployment.uid"])
- set(log.body["kubernetes"]["node"], resource.attributes["k8s.node.name"])
- set(log.body["kubernetes"]["namespace"], resource.attributes["k8s.namespace.name"])
batch: batch:
send_batch_size: 5 send_batch_size: 5
timeout: 10s timeout: 10s
@ -75,6 +84,6 @@ spec:
pipelines: pipelines:
logs: logs:
receivers: [filelog] receivers: [filelog]
processors: [transform, batch] processors: [k8sattributes, transform, batch]
exporters: [otlphttp/logs, debug] exporters: [otlphttp/logs, debug]
{{- end }} {{- end }}