diff --git a/plugins/processors/awsapplicationsignals/internal/normalizer/attributesnormalizer.go b/plugins/processors/awsapplicationsignals/internal/normalizer/attributesnormalizer.go index dd08d63f44..b0966bca2c 100644 --- a/plugins/processors/awsapplicationsignals/internal/normalizer/attributesnormalizer.go +++ b/plugins/processors/awsapplicationsignals/internal/normalizer/attributesnormalizer.go @@ -8,7 +8,8 @@ import ( "strings" "go.opentelemetry.io/collector/pdata/pcommon" - semconv "go.opentelemetry.io/collector/semconv/v1.18.0" + deprecatedsemconv "go.opentelemetry.io/collector/semconv/v1.18.0" + semconv "go.opentelemetry.io/collector/semconv/v1.22.0" "go.uber.org/zap" "github.com/aws/amazon-cloudwatch-agent/internal/version" @@ -126,28 +127,38 @@ func (n *attributesNormalizer) normalizeTelemetryAttributes(attributes, resource } var ( - sdkName string - sdkVersion string + sdkName string + sdkVersion string + sdkLang string + ) + var ( + sdkAutoName string sdkAutoVersion string - sdkLang string ) sdkName, sdkVersion, sdkLang = "-", "-", "-" mode := instrumentationModeManual - // TODO read telemetry.auto.version from telemetry.distro.* from v1.22 resourceAttributes.Range(func(k string, v pcommon.Value) bool { switch k { case semconv.AttributeTelemetrySDKName: - sdkName = strings.ReplaceAll(v.Str(), " ", "") + sdkName = removeWhitespaces(v.Str()) case semconv.AttributeTelemetrySDKLanguage: - sdkLang = strings.ReplaceAll(v.Str(), " ", "") + sdkLang = removeWhitespaces(v.Str()) case semconv.AttributeTelemetrySDKVersion: - sdkVersion = strings.ReplaceAll(v.Str(), " ", "") - case semconv.AttributeTelemetryAutoVersion: - sdkAutoVersion = strings.ReplaceAll(v.Str(), " ", "") + sdkVersion = removeWhitespaces(v.Str()) + } + switch k { + case semconv.AttributeTelemetryDistroName: + sdkAutoName = removeWhitespaces(v.Str()) + case deprecatedsemconv.AttributeTelemetryAutoVersion, semconv.AttributeTelemetryDistroVersion: + sdkAutoVersion = removeWhitespaces(v.Str()) } return true }) + if sdkAutoName != "" { + sdkName = sdkAutoName + mode = instrumentationModeAuto + } if sdkAutoVersion != "" { sdkVersion = sdkAutoVersion mode = instrumentationModeAuto @@ -217,3 +228,7 @@ func truncateStringByLength(val string, length int) string { } return val } + +func removeWhitespaces(val string) string { + return strings.ReplaceAll(val, " ", "") +} diff --git a/plugins/processors/awsapplicationsignals/internal/normalizer/attributesnormalizer_test.go b/plugins/processors/awsapplicationsignals/internal/normalizer/attributesnormalizer_test.go index b8dff25844..18a45fcfe2 100644 --- a/plugins/processors/awsapplicationsignals/internal/normalizer/attributesnormalizer_test.go +++ b/plugins/processors/awsapplicationsignals/internal/normalizer/attributesnormalizer_test.go @@ -8,7 +8,8 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/pdata/pcommon" - conventions "go.opentelemetry.io/collector/semconv/v1.6.1" + deprecatedsemconv "go.opentelemetry.io/collector/semconv/v1.18.0" + conventions "go.opentelemetry.io/collector/semconv/v1.22.0" "go.uber.org/zap" attr "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/internal/attributes" @@ -139,7 +140,7 @@ func Test_attributesNormalizer_appendNewAttributes(t *testing.T) { completeResourceAttributes := pcommon.NewMap() completeResourceAttributes.PutStr(conventions.AttributeTelemetrySDKName, "opentelemetry") - completeResourceAttributes.PutStr(conventions.AttributeTelemetryAutoVersion, "0.0.1 auto") + completeResourceAttributes.PutStr(deprecatedsemconv.AttributeTelemetryAutoVersion, "0.0.1 auto") completeResourceAttributes.PutStr(conventions.AttributeTelemetrySDKVersion, "0.0.1 test") completeResourceAttributes.PutStr(conventions.AttributeTelemetrySDKLanguage, "go") diff --git a/plugins/processors/awsapplicationsignals/internal/resolver/attributesresolver.go b/plugins/processors/awsapplicationsignals/internal/resolver/attributesresolver.go index b7da12888b..94d7487606 100644 --- a/plugins/processors/awsapplicationsignals/internal/resolver/attributesresolver.go +++ b/plugins/processors/awsapplicationsignals/internal/resolver/attributesresolver.go @@ -10,7 +10,7 @@ import ( "strings" "go.opentelemetry.io/collector/pdata/pcommon" - semconv "go.opentelemetry.io/collector/semconv/v1.18.0" + semconv "go.opentelemetry.io/collector/semconv/v1.22.0" "go.uber.org/zap" "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/common" @@ -114,7 +114,9 @@ func (h *resourceAttributesResolver) Process(attributes, resourceAttributes pcom attributes.PutStr(attr.AWSLocalEnvironment, val.Str()) } else { if h.defaultEnvPrefix == appsignalsconfig.PlatformECS { - if clusterName, ok := getECSClusterName(resourceAttributes); ok { + if clusterName, _ := getECSClusterName(resourceAttributes); clusterName != "" { + attributes.PutStr(attr.AWSLocalEnvironment, getDefaultEnvironment(h.defaultEnvPrefix, clusterName)) + } else if clusterName = ecsutil.GetECSUtilSingleton().Cluster; clusterName != "" { attributes.PutStr(attr.AWSLocalEnvironment, getDefaultEnvironment(h.defaultEnvPrefix, clusterName)) } } else if h.defaultEnvPrefix == appsignalsconfig.PlatformEC2 { diff --git a/plugins/processors/awsapplicationsignals/internal/resolver/attributesresolver_test.go b/plugins/processors/awsapplicationsignals/internal/resolver/attributesresolver_test.go index ea6c1cd129..cf8fd05f57 100644 --- a/plugins/processors/awsapplicationsignals/internal/resolver/attributesresolver_test.go +++ b/plugins/processors/awsapplicationsignals/internal/resolver/attributesresolver_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "go.opentelemetry.io/collector/pdata/pcommon" - semconv "go.opentelemetry.io/collector/semconv/v1.18.0" + semconv "go.opentelemetry.io/collector/semconv/v1.22.0" "go.uber.org/zap" "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/common" diff --git a/plugins/processors/awsapplicationsignals/internal/resolver/kubernetes.go b/plugins/processors/awsapplicationsignals/internal/resolver/kubernetes.go index 979fad2900..fe5712976b 100644 --- a/plugins/processors/awsapplicationsignals/internal/resolver/kubernetes.go +++ b/plugins/processors/awsapplicationsignals/internal/resolver/kubernetes.go @@ -17,7 +17,7 @@ import ( mapset "github.com/deckarep/golang-set/v2" "go.opentelemetry.io/collector/pdata/pcommon" - semconv "go.opentelemetry.io/collector/semconv/v1.17.0" + semconv "go.opentelemetry.io/collector/semconv/v1.22.0" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" "k8s.io/client-go/informers" diff --git a/plugins/processors/awsapplicationsignals/internal/resolver/kubernetes_test.go b/plugins/processors/awsapplicationsignals/internal/resolver/kubernetes_test.go index 0687b64b93..20cb17a5cb 100644 --- a/plugins/processors/awsapplicationsignals/internal/resolver/kubernetes_test.go +++ b/plugins/processors/awsapplicationsignals/internal/resolver/kubernetes_test.go @@ -14,7 +14,7 @@ import ( mapset "github.com/deckarep/golang-set/v2" "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/pdata/pcommon" - semconv "go.opentelemetry.io/collector/semconv/v1.17.0" + semconv "go.opentelemetry.io/collector/semconv/v1.22.0" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"