Add service entity support for EMF exporter #291
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the issue
To support the Explore related feature in CloudWatch, the CloudWatch Agent sends an "Entity", which includes relevant metadata to correlate metrics or logs between resources (e.g., an EKS cluster) and services (e.g., a Java application). In the case of exporting custom metrics received by OTLP or from scraping Prometheus targets, we need to export a service "Entity" for EMF, which includes the following attributes:
Service
,Environment
,EKS.Cluster
/K8s.Cluster
,K8s.Namespace
,K8s.Workload
,K8s.Node
,AWS.ServiceNameSource
,PlatformType
, andEC2.InstanceId
.Right now, in the CloudWatch Agent's entity processor, we generate these "Entity" fields, but they're in the following format:
com.amazonaws.cloudwatch.entity.internal.<field>
. We then filter them out when creating labels in the EMF exporter.We need to convert them into their expected format when exporting for EMF logs.
Description of changes
Important
Co-PRs: aws/amazon-cloudwatch-agent#1529; aws-observability/helm-charts#171
entityattributes.go
to hold entity constants and field retrieval logic.License
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Tests
CloudWatch Agent Logs
2025-02-06T17:27:40Z D! {"caller":"awsemfexporter@v0.103.0/emf_exporter.go:160","msg":"Finish processing resource metrics","kind":"exporter","data_type":"metrics","name":"awsemf","labels":{"com.amazonaws.cloudwatch.entity.internal.aws.account.id":"637423426239","com.amazonaws.cloudwatch.entity.internal.deployment.environment":"eks:entity-cluster-2/default","com.amazonaws.cloudwatch.entity.internal.instance.id":"i-0da7f196c5fa59a25","com.amazonaws.cloudwatch.entity.internal.k8s.cluster.name":"entity-cluster-2","com.amazonaws.cloudwatch.entity.internal.k8s.namespace.name":"default","com.amazonaws.cloudwatch.entity.internal.k8s.node.name":"ip-XXX-XX-XX-XX.us-west-2.compute.internal","com.amazonaws.cloudwatch.entity.internal.k8s.workload.name":"sample-app","com.amazonaws.cloudwatch.entity.internal.platform.type":"AWS::EKS","com.amazonaws.cloudwatch.entity.internal.service.name":"unknown_service:java","com.amazonaws.cloudwatch.entity.internal.service.name.source":"Instrumentation","com.amazonaws.cloudwatch.entity.internal.type":"Service","host.arch":"amd64","host.name":"sample-app-54d797bb9b-nkb77", "k8s.deployment.name":"sample-app","k8s.namespace.name":"default","k8s.node.name":"ip-XXX-XX-XX-XX.us-west-2.compute.internal","k8s.pod.ip":"XXX.XX.XX.XX","k8s.pod.name":"sample-app-54d797bb9b-nkb77","k8s.replicaset.name":"sample-app-54d797bb9b","os.description":"Linux 6.1.119-129.201.amzn2023.x86_64","os.type":"linux","process.command_line":"/usr/lib/jvm/java-17-openjdk-amd64:bin:java -javaagent:/aws-observability/classpath/aws-opentelemetry-agent-1.17.0.jar","process.executable.path":"/usr/lib/jvm/java-17-openjdk-amd64:bin:java","process.pid":"","process.runtime.description":"Debian OpenJDK 64-Bit Server VM 17.0.4+8-Debian-1deb11u1","process.runtime.name":"OpenJDK Runtime Environment","process.runtime.version":"17.0.4+8-Debian-1deb11u1","service.name":"unknown_service:java","telemetry.auto.version":"1.17.0-aws","telemetry.sdk.language":"java","telemetry.sdk.name":"opentelemetry","telemetry.sdk.version":"1.17.0"}}
EMF Log