Skip to content

Commit

Permalink
Set the service name source to Instrumentation in entity when custome…
Browse files Browse the repository at this point in the history
…r sets the service name OTEL resource attribute (#1565)
  • Loading branch information
nathalapooja authored Mar 3, 2025
1 parent c23457c commit 20824f2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugins/processors/awsentity/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ func (p *awsEntityProcessor) processMetrics(_ context.Context, md pmetric.Metric
entityServiceName = podInfo.Workload
entityServiceNameSource = entitystore.ServiceNameSourceK8sWorkload
}
// Set the service name source to Instrumentation if the operator doesn't set it
if entityServiceName != EMPTY && entityServiceNameSource == EMPTY && getTelemetrySDKEnabledAttribute(resourceAttrs) {
entityServiceNameSource = entitystore.ServiceNameSourceInstrumentation
}
// Perform fallback mechanism for environment if it is empty
if entityEnvironmentName == EMPTY && ok && podInfo.Cluster != EMPTY && podInfo.Namespace != EMPTY {
if p.config.KubernetesMode == config.ModeEKS {
Expand Down Expand Up @@ -493,6 +497,13 @@ func getServiceAttributes(p pcommon.Map) string {
return EMPTY
}

func getTelemetrySDKEnabledAttribute(p pcommon.Map) bool {
if _, ok := p.Get(semconv.AttributeTelemetrySDKName); ok {
return true
}
return false
}

// scrapeK8sPodName gets the k8s pod name which is full pod name from the resource attributes
// This is needed to map the pod to the service/environment
func scrapeK8sPodName(p pcommon.Map) string {
Expand Down
28 changes: 28 additions & 0 deletions plugins/processors/awsentity/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ func TestProcessMetricsForAddingPodToServiceMap(t *testing.T) {
want: map[string]entitystore.ServiceEnvironment{"cloudwatch-agent-adhgaf": {ServiceName: "test-service", ServiceNameSource: entitystore.ServiceNameSourceUnknown}},
k8sMode: config.ModeEKS,
},
{
name: "WithPodNameAndServiceNameNoSourceWithTelemetryEnabled",
metrics: generateMetrics(attributeServiceName, "test-service", semconv.AttributeK8SPodName, "cloudwatch-agent-adhgaf", semconv.AttributeTelemetrySDKName, "opentelemetry"),
want: map[string]entitystore.ServiceEnvironment{"cloudwatch-agent-adhgaf": {ServiceName: "test-service", ServiceNameSource: entitystore.ServiceNameSourceInstrumentation}},
k8sMode: config.ModeEKS,
},
{
name: "WithPodNameAndServiceNameHasSource",
metrics: generateMetrics(attributeServiceName, "test-service", semconv.AttributeK8SPodName, "cloudwatch-agent-adhgaf", entityattributes.AttributeEntityServiceNameSource, "Instrumentation"),
Expand Down Expand Up @@ -451,6 +457,28 @@ func TestProcessMetricsResourceAttributeScraping(t *testing.T) {
attributeServiceName: "unknown_service:java",
},
},
{
name: "ResourceAttributeTelemetrySDKEnabled",
kubernetesMode: config.ModeEKS,
clusterName: "test-cluster",
metrics: generateMetrics(semconv.AttributeK8SNamespaceName, "test-namespace", semconv.AttributeK8SDeploymentName, "test-workload", semconv.AttributeK8SNodeName, "test-node", attributeServiceName, "test-service", semconv.AttributeTelemetrySDKName, "opentelemetry"),
want: map[string]any{
entityattributes.AttributeEntityType: "Service",
entityattributes.AttributeEntityServiceName: "test-service",
entityattributes.AttributeEntityDeploymentEnvironment: "eks:test-cluster/test-namespace",
entityattributes.AttributeEntityCluster: "test-cluster",
entityattributes.AttributeEntityNamespace: "test-namespace",
entityattributes.AttributeEntityNode: "test-node",
entityattributes.AttributeEntityWorkload: "test-workload",
entityattributes.AttributeEntityServiceNameSource: "Instrumentation",
entityattributes.AttributeEntityPlatformType: "AWS::EKS",
semconv.AttributeK8SNamespaceName: "test-namespace",
semconv.AttributeK8SDeploymentName: "test-workload",
semconv.AttributeK8SNodeName: "test-node",
attributeServiceName: "test-service",
semconv.AttributeTelemetrySDKName: "opentelemetry",
},
},
{
name: "ResourceAttributeEnvironmentFallbackToASG",
platform: config.ModeEC2,
Expand Down

0 comments on commit 20824f2

Please sign in to comment.