From 76691b314c208c39612fba63236c98c8b5ad50d0 Mon Sep 17 00:00:00 2001 From: ADOT Patch workflow Date: Thu, 8 Feb 2024 16:48:29 -0800 Subject: [PATCH] Delete a unneed annotation converter --- .../internal/translator/segment.go | 21 ------- .../internal/translator/segment_test.go | 60 ------------------- 2 files changed, 81 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/segment.go b/exporter/awsxrayexporter/internal/translator/segment.go index 17236c6023..e6132300d6 100644 --- a/exporter/awsxrayexporter/internal/translator/segment.go +++ b/exporter/awsxrayexporter/internal/translator/segment.go @@ -642,7 +642,6 @@ func makeXRayAttributes(attributes map[string]pcommon.Value, resource pcommon.Re annoVal := annotationValue(value) indexed := indexAllAttrs || indexedKeys[key] if annoVal != nil && indexed { - key = fixAnnotationKey(key) annotations[key] = annoVal } else { metaVal := value.AsRaw() @@ -656,7 +655,6 @@ func makeXRayAttributes(attributes map[string]pcommon.Value, resource pcommon.Re if indexAllAttrs { for key, value := range attributes { - key = fixAnnotationKey(key) annoVal := annotationValue(value) if annoVal != nil { annotations[key] = annoVal @@ -666,7 +664,6 @@ func makeXRayAttributes(attributes map[string]pcommon.Value, resource pcommon.Re for key, value := range attributes { switch { case indexedKeys[key]: - key = fixAnnotationKey(key) annoVal := annotationValue(value) if annoVal != nil { annotations[key] = annoVal @@ -734,24 +731,6 @@ func fixSegmentName(name string) string { return name } -// fixAnnotationKey removes any invalid characters from the annotaiton key. AWS X-Ray defines -// the list of valid characters here: -// https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html -func fixAnnotationKey(key string) string { - return strings.Map(func(r rune) rune { - switch { - case '0' <= r && r <= '9': - fallthrough - case 'A' <= r && r <= 'Z': - fallthrough - case 'a' <= r && r <= 'z': - return r - default: - return '_' - } - }, key) -} - func trimAwsSdkPrefix(name string, span ptrace.Span) string { if isAwsSdkSpan(span) && strings.HasPrefix(name, "AWS.SDK.") { return strings.TrimPrefix(name, "AWS.SDK.") diff --git a/exporter/awsxrayexporter/internal/translator/segment_test.go b/exporter/awsxrayexporter/internal/translator/segment_test.go index 218b4d7506..b93c8efb7a 100644 --- a/exporter/awsxrayexporter/internal/translator/segment_test.go +++ b/exporter/awsxrayexporter/internal/translator/segment_test.go @@ -406,15 +406,6 @@ func TestFixSegmentName(t *testing.T) { assert.Equal(t, defaultSegmentName, fixedName) } -func TestFixAnnotationKey(t *testing.T) { - validKey := "Key_1" - fixedKey := fixAnnotationKey(validKey) - assert.Equal(t, validKey, fixedKey) - invalidKey := "Key@1" - fixedKey = fixAnnotationKey(invalidKey) - assert.Equal(t, "Key_1", fixedKey) -} - func TestServerSpanWithNilAttributes(t *testing.T) { spanName := "/api/locations" parentSpanID := newSegmentID() @@ -483,57 +474,6 @@ func TestSpanWithResourceNotStoredIfSubsegment(t *testing.T) { assert.Nil(t, segment.Metadata["default"]["otel.resource.array.key"]) } -func TestSpanWithAttributesPartlyIndexed(t *testing.T) { - spanName := "/api/locations" - parentSpanID := newSegmentID() - attributes := make(map[string]any) - attributes["attr1@1"] = "val1" - attributes["attr2@2"] = "val2" - resource := constructDefaultResource() - span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeError, "OK", attributes) - - segment, _ := MakeSegment(span, resource, []string{"attr1@1", "not_exist"}, false, nil, false) - - assert.NotNil(t, segment) - assert.Equal(t, 1, len(segment.Annotations)) - assert.Equal(t, "val1", segment.Annotations["attr1_1"]) - assert.Equal(t, "val2", segment.Metadata["default"]["attr2@2"]) -} - -func TestSpanWithAnnotationsAttribute(t *testing.T) { - spanName := "/api/locations" - parentSpanID := newSegmentID() - attributes := make(map[string]any) - attributes["attr1@1"] = "val1" - attributes["attr2@2"] = "val2" - attributes[awsxray.AWSXraySegmentAnnotationsAttribute] = []string{"attr2@2", "not_exist"} - resource := constructDefaultResource() - span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeError, "OK", attributes) - - segment, _ := MakeSegment(span, resource, nil, false, nil, false) - - assert.NotNil(t, segment) - assert.Equal(t, 1, len(segment.Annotations)) - assert.Equal(t, "val2", segment.Annotations["attr2_2"]) - assert.Equal(t, "val1", segment.Metadata["default"]["attr1@1"]) -} - -func TestSpanWithAttributesAllIndexed(t *testing.T) { - spanName := "/api/locations" - parentSpanID := newSegmentID() - attributes := make(map[string]any) - attributes["attr1@1"] = "val1" - attributes["attr2@2"] = "val2" - resource := constructDefaultResource() - span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) - - segment, _ := MakeSegment(span, resource, []string{"attr1@1", "not_exist"}, true, nil, false) - - assert.NotNil(t, segment) - assert.Equal(t, "val1", segment.Annotations["attr1_1"]) - assert.Equal(t, "val2", segment.Annotations["attr2_2"]) -} - func TestSpanWithAttributesSegmentMetadata(t *testing.T) { spanName := "/api/locations" parentSpanID := newSegmentID()