diff --git a/pkg/otlp/attributes/attributes.go b/pkg/otlp/attributes/attributes.go index 9b305c86..e022e871 100644 --- a/pkg/otlp/attributes/attributes.go +++ b/pkg/otlp/attributes/attributes.go @@ -152,10 +152,23 @@ func TagsFromAttributes(attrs pcommon.Map) []string { func OriginIDFromAttributes(attrs pcommon.Map) (originID string) { // originID is always empty. Container ID is preferred over Kubernetes pod UID. // Prefixes come from pkg/util/kubernetes/kubelet and pkg/util/containers. + // See https://github.com/DataDog/datadog-agent/tree/2b4f456/comp/core/tagger#entity-ids if containerID, ok := attrs.Get(conventions.AttributeContainerID); ok { originID = "container_id://" + containerID.AsString() + } else if containerImageName, ok := attrs.Get(conventions.AttributeContainerImageName); ok { + originID = "container_image_metadata://" + containerImageName.AsString() + } else if ecsTaskArn, ok := attrs.Get(conventions.AttributeAWSECSTaskARN); ok { + originID = "ecs_task://" + ecsTaskArn.AsString() + } else if deploymentName, ok := attrs.Get(conventions.AttributeK8SDeploymentName); ok { + originID = "deployment://" + deploymentName.AsString() + } else if namespace, ok := attrs.Get(conventions.AttributeK8SNamespaceName); ok { + originID = "namespace://" + namespace.AsString() + } else if nodeUid, ok := attrs.Get(conventions.AttributeK8SNodeUID); ok { + originID = "kubernetes_node_uid://" + nodeUid.AsString() } else if podUID, ok := attrs.Get(conventions.AttributeK8SPodUID); ok { originID = "kubernetes_pod_uid://" + podUID.AsString() + } else if processPid, ok := attrs.Get(conventions.AttributeProcessPID); ok { + originID = "process://" + processPid.AsString() } return } diff --git a/pkg/otlp/attributes/attributes_test.go b/pkg/otlp/attributes/attributes_test.go index c5bd0c84..3384d943 100644 --- a/pkg/otlp/attributes/attributes_test.go +++ b/pkg/otlp/attributes/attributes_test.go @@ -213,6 +213,50 @@ func TestOriginIDFromAttributes(t *testing.T) { }(), originID: "kubernetes_pod_uid://k8s_pod_uid_goes_here", }, + { + name: "only deployment name", + attrs: func() pcommon.Map { + attributes := pcommon.NewMap() + attributes.FromRaw(map[string]interface{}{ + conventions.AttributeK8SDeploymentName: "k8s_deployment_name_goes_here", + }) + return attributes + }(), + originID: "deployment://k8s_deployment_name_goes_here", + }, + { + name: "only namespace name", + attrs: func() pcommon.Map { + attributes := pcommon.NewMap() + attributes.FromRaw(map[string]interface{}{ + conventions.AttributeK8SNamespaceName: "k8s_namespace_goes_here", + }) + return attributes + }(), + originID: "namespace://k8s_namespace_goes_here", + }, + { + name: "only node UID", + attrs: func() pcommon.Map { + attributes := pcommon.NewMap() + attributes.FromRaw(map[string]interface{}{ + conventions.AttributeK8SNodeUID: "k8s_node_uid_goes_here", + }) + return attributes + }(), + originID: "kubernetes_node_uid://k8s_node_uid_goes_here", + }, + { + name: "only process pid", + attrs: func() pcommon.Map { + attributes := pcommon.NewMap() + attributes.FromRaw(map[string]interface{}{ + conventions.AttributeProcessPID: "process_pid_goes_here", + }) + return attributes + }(), + originID: "process://process_pid_goes_here", + }, { name: "none", attrs: pcommon.NewMap(),