Skip to content

Commit

Permalink
Delete a unneed annotation converter
Browse files Browse the repository at this point in the history
  • Loading branch information
ADOT Patch workflow committed Feb 9, 2024
1 parent 591e510 commit 76691b3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 81 deletions.
21 changes: 0 additions & 21 deletions exporter/awsxrayexporter/internal/translator/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.")
Expand Down
60 changes: 0 additions & 60 deletions exporter/awsxrayexporter/internal/translator/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 76691b3

Please sign in to comment.