Skip to content

Commit

Permalink
1. bug fixes 2. rename SDK field in EMF log.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjrara committed May 17, 2024
1 parent 60b8a4f commit 39fce0b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion plugins/processors/awsapplicationsignals/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
AttributeEC2AutoScalingGroupName = "EC2.AutoScalingGroupName"
AttributeEC2InstanceId = "EC2.InstanceId"
AttributePlatformType = "PlatformType"
AttributeSDK = "SDK"
AttributeSDK = "Telemetry.SDK"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func Test_attributesNormalizer_appendNewAttributes(t *testing.T) {
}
n.appendNewAttributes(tt.attributes, tt.resourceAttributes, tt.isTrace)

if value, ok := tt.attributes.Get("SDK"); !ok {
if value, ok := tt.attributes.Get("Telemetry.SDK"); !ok {
if !tt.isTrace {
t.Errorf("attribute is not found.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ const (
)

var GenericInheritedAttributes = map[string]string{
attr.AWSHostedInEnvironment: attr.AWSLocalEnvironment,
semconv1.AttributeDeploymentEnvironment: attr.AWSLocalEnvironment,
attr.ResourceDetectionHostName: attr.ResourceDetectionHostName,
}

// DefaultInheritedAttributes is an allow-list that also renames attributes from the resource detection processor
var DefaultInheritedAttributes = map[string]string{
attr.AWSHostedInEnvironment: attr.AWSLocalEnvironment,
semconv1.AttributeDeploymentEnvironment: attr.AWSLocalEnvironment,
attr.ResourceDetectionASG: common.AttributeEC2AutoScalingGroupName,
attr.ResourceDetectionHostId: common.AttributeEC2InstanceId,
Expand Down Expand Up @@ -110,18 +108,22 @@ func newResourceAttributesResolver(defaultEnvPrefix, platformType string, attrib
func (h *resourceAttributesResolver) Process(attributes, resourceAttributes pcommon.Map) error {
for attrKey, mappingKey := range h.attributeMap {
if val, ok := resourceAttributes.Get(attrKey); ok {
attributes.PutStr(mappingKey, val.AsString())
attributes.PutStr(mappingKey, val.Str())
}
}
if _, ok := attributes.Get(attr.AWSLocalEnvironment); !ok {
if h.defaultEnvPrefix == appsignalsconfig.PlatformECS {
if clusterName, ok := getECSClusterName(resourceAttributes); ok {
attributes.PutStr(attr.AWSLocalEnvironment, GetDefaultEnvironment(h.defaultEnvPrefix, clusterName))
if val, found := resourceAttributes.Get(attr.AWSHostedInEnvironment); found {
attributes.PutStr(attr.AWSLocalEnvironment, val.Str())
} else {
if h.defaultEnvPrefix == appsignalsconfig.PlatformECS {
if clusterName, ok := getECSClusterName(resourceAttributes); ok {
attributes.PutStr(attr.AWSLocalEnvironment, GetDefaultEnvironment(h.defaultEnvPrefix, clusterName))
}
}
}
if h.defaultEnvPrefix == appsignalsconfig.PlatformEC2 {
if asgAttr, ok := resourceAttributes.Get(attr.ResourceDetectionASG); ok {
attributes.PutStr(attr.AWSLocalEnvironment, GetDefaultEnvironment(h.defaultEnvPrefix, asgAttr.Str()))
if h.defaultEnvPrefix == appsignalsconfig.PlatformEC2 {
if asgAttr, ok := resourceAttributes.Get(attr.ResourceDetectionASG); ok {
attributes.PutStr(attr.AWSLocalEnvironment, GetDefaultEnvironment(h.defaultEnvPrefix, asgAttr.Str()))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,14 +700,11 @@ func (h *kubernetesResourceAttributesResolver) Process(attributes, resourceAttri
namespace = "UnknownNamespace"
}

if val, ok := resourceAttributes.Get(semconv.AttributeDeploymentEnvironment); !ok {
if val, ok := attributes.Get(attr.AWSLocalEnvironment); !ok {
env := GetDefaultEnvironment(h.platformCode, h.clusterName+"/"+namespace)
if len(env) > 255 {
env = env[:255]
}
attributes.PutStr(common.MetricAttributeEnvironment, env)
attributes.PutStr(attr.AWSLocalEnvironment, env)
} else {
attributes.PutStr(common.MetricAttributeEnvironment, val.Str())
attributes.PutStr(attr.AWSLocalEnvironment, val.Str())
}

attributes.PutStr(common.AttributeK8SNamespace, namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ func TestK8sResourceAttributesResolverOnEKS(t *testing.T) {
map[string]string{},

map[string]string{
common.MetricAttributeEnvironment: "eks:test-cluster/test-namespace-3",
attr.AWSLocalEnvironment: "eks:test-cluster/test-namespace-3",
common.AttributeK8SNamespace: "test-namespace-3",
common.AttributeEKSClusterName: "test-cluster",
common.AttributeEC2InstanceId: "instance-id",
Expand All @@ -869,7 +869,7 @@ func TestK8sResourceAttributesResolverOnEKS(t *testing.T) {
semconv.AttributeDeploymentEnvironment: "custom-env",
},
map[string]string{
common.MetricAttributeEnvironment: "custom-env",
attr.AWSLocalEnvironment: "custom-env",
common.AttributeK8SNamespace: "test-namespace-3",
common.AttributeEKSClusterName: "test-cluster",
common.AttributeEC2InstanceId: "instance-id",
Expand Down Expand Up @@ -932,7 +932,7 @@ func TestK8sResourceAttributesResolverOnK8S(t *testing.T) {
map[string]string{},

map[string]string{
common.MetricAttributeEnvironment: "k8s:test-cluster/test-namespace-3",
attr.AWSLocalEnvironment: "k8s:test-cluster/test-namespace-3",
common.AttributeK8SNamespace: "test-namespace-3",
common.AttributeK8SClusterName: "test-cluster",
common.AttributeEC2InstanceId: "instance-id",
Expand All @@ -946,7 +946,7 @@ func TestK8sResourceAttributesResolverOnK8S(t *testing.T) {
semconv.AttributeDeploymentEnvironment: "custom-env",
},
map[string]string{
common.MetricAttributeEnvironment: "custom-env",
attr.AWSLocalEnvironment: "custom-env",
common.AttributeK8SNamespace: "test-namespace-3",
common.AttributeK8SClusterName: "test-cluster",
common.AttributeEC2InstanceId: "instance-id",
Expand Down Expand Up @@ -1006,10 +1006,10 @@ func TestK8sResourceAttributesResolverOnK8SOnPrem(t *testing.T) {
map[string]string{},

map[string]string{
common.MetricAttributeEnvironment: "k8s:test-cluster/test-namespace-3",
common.AttributeK8SNamespace: "test-namespace-3",
common.AttributeK8SClusterName: "test-cluster",
attr.ResourceDetectionHostName: "hostname",
attr.AWSLocalEnvironment: "k8s:test-cluster/test-namespace-3",
common.AttributeK8SNamespace: "test-namespace-3",
common.AttributeK8SClusterName: "test-cluster",
attr.ResourceDetectionHostName: "hostname",
},
},
{
Expand All @@ -1018,10 +1018,10 @@ func TestK8sResourceAttributesResolverOnK8SOnPrem(t *testing.T) {
semconv.AttributeDeploymentEnvironment: "custom-env",
},
map[string]string{
common.MetricAttributeEnvironment: "custom-env",
common.AttributeK8SNamespace: "test-namespace-3",
common.AttributeK8SClusterName: "test-cluster",
attr.ResourceDetectionHostName: "hostname",
attr.AWSLocalEnvironment: "custom-env",
common.AttributeK8SNamespace: "test-namespace-3",
common.AttributeK8SClusterName: "test-cluster",
attr.ResourceDetectionHostName: "hostname",
},
},
}
Expand Down

0 comments on commit 39fce0b

Please sign in to comment.