From a653bbf27b34cb5e1cfdfe198b3b34bb2c0684fa Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Wed, 22 Mar 2023 09:47:35 -0700 Subject: [PATCH 01/18] Adding span link attributes --- .gitignore | 1 + .../internal/translator/segment.go | 2 + .../internal/translator/spanLinks.go | 49 ++++++++ .../internal/translator/spanLinks_test.go | 111 ++++++++++++++++++ internal/aws/xray/tracesegment.go | 16 ++- 5 files changed, 175 insertions(+), 4 deletions(-) create mode 100644 exporter/awsxrayexporter/internal/translator/spanLinks.go create mode 100644 exporter/awsxrayexporter/internal/translator/spanLinks_test.go diff --git a/.gitignore b/.gitignore index 9d39ea0b8bcc..477e34a76840 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ local/ +vendor/ # GoLand IDEA /.idea/ diff --git a/exporter/awsxrayexporter/internal/translator/segment.go b/exporter/awsxrayexporter/internal/translator/segment.go index 6d45b82391ba..cee2ef3ea814 100644 --- a/exporter/awsxrayexporter/internal/translator/segment.go +++ b/exporter/awsxrayexporter/internal/translator/segment.go @@ -112,6 +112,7 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str sqlfiltered, sql = makeSQL(span, awsfiltered) additionalAttrs = addSpecialAttributes(sqlfiltered, indexedAttrs, attributes) user, annotations, metadata = makeXRayAttributes(additionalAttrs, resource, storeResource, indexedAttrs, indexAllAttrs) + spanLinks = makeSpanLinks(span.Links()) name string namespace string ) @@ -211,6 +212,7 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str Annotations: annotations, Metadata: metadata, Type: awsxray.String(segmentType), + Links: spanLinks, }, nil } diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks.go b/exporter/awsxrayexporter/internal/translator/spanLinks.go new file mode 100644 index 000000000000..7b31eaa78149 --- /dev/null +++ b/exporter/awsxrayexporter/internal/translator/spanLinks.go @@ -0,0 +1,49 @@ +// Copyright 2019, OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" + +import ( + awsxray "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray" + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/ptrace" +) + +func makeSpanLinks(links ptrace.SpanLinkSlice) []awsxray.SpanLinkData { + var spanLinkDataArray []awsxray.SpanLinkData + + for i := 0; i < links.Len(); i++ { + var spanLinkData awsxray.SpanLinkData + var link = links.At(i) + + var spanId = link.SpanID().String() + var traceId = link.TraceID().String() + + spanLinkData.SpanID = &spanId + spanLinkData.TraceID = &traceId + + if links.Len() > 0 { + spanLinkData.Attributes = make(map[string]interface{}) + } + + link.Attributes().Range(func(k string, v pcommon.Value) bool { + spanLinkData.Attributes[k] = v.AsRaw() + return true + }) + + spanLinkDataArray = append(spanLinkDataArray, spanLinkData) + } + + return spanLinkDataArray +} diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go new file mode 100644 index 000000000000..c6d7ffc3da6c --- /dev/null +++ b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go @@ -0,0 +1,111 @@ +// Copyright 2019, OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/ptrace" +) + +func TestSpanLinkSimple(t *testing.T) { + spanName := "ProcessingMessage" + parentSpanID := newSegmentID() + attributes := make(map[string]interface{}) + resource := constructDefaultResource() + span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) + + spanLink := span.Links().AppendEmpty() + spanLink.SetTraceID(newTraceID()) + spanLink.SetSpanID(newSegmentID()) + + jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) + + assert.True(t, strings.Contains(jsonStr, "links")) +} + +func TestSpanLinkAttributes(t *testing.T) { + spanName := "ProcessingMessage" + parentSpanID := newSegmentID() + attributes := make(map[string]interface{}) + resource := constructDefaultResource() + span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) + + spanLink := span.Links().AppendEmpty() + spanLink.SetTraceID(newTraceID()) + spanLink.SetSpanID(newSegmentID()) + spanLink.Attributes().PutStr("myKey1", "myValue") + spanLink.Attributes().PutBool("myKey2", true) + spanLink.Attributes().PutInt("myKey3", 8675309) + spanLink.Attributes().PutDouble("myKey4", 3.1415) + + var slice1 = spanLink.Attributes().PutEmptySlice("myKey5") + slice1.AppendEmpty().SetStr("apple") + slice1.AppendEmpty().SetStr("pear") + slice1.AppendEmpty().SetStr("banana") + + var slice2 = spanLink.Attributes().PutEmptySlice("myKey6") + slice2.AppendEmpty().SetBool(true) + slice2.AppendEmpty().SetBool(false) + slice2.AppendEmpty().SetBool(false) + slice2.AppendEmpty().SetBool(true) + + var slice3 = spanLink.Attributes().PutEmptySlice("myKey7") + slice3.AppendEmpty().SetInt(1234) + slice3.AppendEmpty().SetInt(5678) + slice3.AppendEmpty().SetInt(9012) + + var slice4 = spanLink.Attributes().PutEmptySlice("myKey8") + slice4.AppendEmpty().SetDouble(2.718) + slice4.AppendEmpty().SetDouble(1.618) + + jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) + + assert.True(t, strings.Contains(jsonStr, "links")) + + assert.True(t, strings.Contains(jsonStr, "myKey1")) + assert.True(t, strings.Contains(jsonStr, "myValue")) + + assert.True(t, strings.Contains(jsonStr, "myKey2")) + assert.True(t, strings.Contains(jsonStr, "true")) + + assert.True(t, strings.Contains(jsonStr, "myKey3")) + assert.True(t, strings.Contains(jsonStr, "8675309")) + + assert.True(t, strings.Contains(jsonStr, "myKey4")) + assert.True(t, strings.Contains(jsonStr, "3.1415")) + + assert.True(t, strings.Contains(jsonStr, "myKey5")) + assert.True(t, strings.Contains(jsonStr, "apple")) + assert.True(t, strings.Contains(jsonStr, "pear")) + assert.True(t, strings.Contains(jsonStr, "banana")) + + assert.True(t, strings.Contains(jsonStr, "myKey6")) + assert.True(t, strings.Contains(jsonStr, "apple")) + assert.True(t, strings.Contains(jsonStr, "pear")) + assert.True(t, strings.Contains(jsonStr, "banana")) + + assert.True(t, strings.Contains(jsonStr, "myKey7")) + assert.True(t, strings.Contains(jsonStr, "1234")) + assert.True(t, strings.Contains(jsonStr, "5678")) + assert.True(t, strings.Contains(jsonStr, "9012")) + + assert.True(t, strings.Contains(jsonStr, "myKey8")) + assert.True(t, strings.Contains(jsonStr, "2.718")) + assert.True(t, strings.Contains(jsonStr, "1.618")) +} diff --git a/internal/aws/xray/tracesegment.go b/internal/aws/xray/tracesegment.go index ebfd8c8c6865..ee60ca2ad852 100644 --- a/internal/aws/xray/tracesegment.go +++ b/internal/aws/xray/tracesegment.go @@ -45,10 +45,11 @@ type Segment struct { StartTime *float64 `json:"start_time"` // Segment-only optional fields - Service *ServiceData `json:"service,omitempty"` - Origin *string `json:"origin,omitempty"` - User *string `json:"user,omitempty"` - ResourceARN *string `json:"resource_arn,omitempty"` + Service *ServiceData `json:"service,omitempty"` + Origin *string `json:"origin,omitempty"` + User *string `json:"user,omitempty"` + ResourceARN *string `json:"resource_arn,omitempty"` + Links []SpanLinkData `json:"links,omitempty"` // Optional fields for both Segment and subsegments TraceID *string `json:"trace_id,omitempty"` @@ -280,3 +281,10 @@ type ServiceData struct { CompilerVersion *string `json:"compiler_version,omitempty"` Compiler *string `json:"compiler,omitempty"` } + +// SpanLinkData provides the shape for unmarshalling the service field. +type SpanLinkData struct { + TraceID *string `json:"trace_id"` + SpanID *string `json:"id"` + Attributes map[string]interface{} `json:"attributes,omitempty"` +} From 537401af5d45fc22d8d67fffe2eb318e4ab3dd4a Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Wed, 22 Mar 2023 11:08:12 -0700 Subject: [PATCH 02/18] Adding more tests --- .../internal/translator/spanLinks_test.go | 89 +++++++++++++++++-- 1 file changed, 83 insertions(+), 6 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go index c6d7ffc3da6c..86fa961888fa 100644 --- a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go +++ b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go @@ -34,12 +34,63 @@ func TestSpanLinkSimple(t *testing.T) { spanLink.SetTraceID(newTraceID()) spanLink.SetSpanID(newSegmentID()) + segment, _ := MakeSegment(span, resource, nil, false, nil) + + assert.Equal(t, 1, len(segment.Links)) + assert.Equal(t, spanLink.SpanID().String(), *segment.Links[0].SpanID) + assert.Equal(t, spanLink.TraceID().String(), *segment.Links[0].TraceID) + assert.Equal(t, 0, len(segment.Links[0].Attributes)) + jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) assert.True(t, strings.Contains(jsonStr, "links")) + assert.False(t, strings.Contains(jsonStr, "attributes")) + assert.True(t, strings.Contains(jsonStr, spanLink.TraceID().String())) + assert.True(t, strings.Contains(jsonStr, spanLink.SpanID().String())) } -func TestSpanLinkAttributes(t *testing.T) { +func TestTwoSpanLinks(t *testing.T) { + spanName := "ProcessingMessage" + parentSpanID := newSegmentID() + attributes := make(map[string]interface{}) + resource := constructDefaultResource() + span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) + + spanLink1 := span.Links().AppendEmpty() + spanLink1.SetTraceID(newTraceID()) + spanLink1.SetSpanID(newSegmentID()) + spanLink1.Attributes().PutStr("myKey1", "ABC") + + spanLink2 := span.Links().AppendEmpty() + spanLink2.SetTraceID(newTraceID()) + spanLink2.SetSpanID(newSegmentID()) + spanLink2.Attributes().PutStr("myKey2", "DEF") + + segment, _ := MakeSegment(span, resource, nil, false, nil) + + assert.Equal(t, 2, len(segment.Links)) + + assert.Equal(t, spanLink1.SpanID().String(), *segment.Links[0].SpanID) + assert.Equal(t, spanLink1.TraceID().String(), *segment.Links[0].TraceID) + assert.Equal(t, 1, len(segment.Links[0].Attributes)) + assert.Equal(t, "ABC", segment.Links[0].Attributes["myKey1"]) + + assert.Equal(t, spanLink2.SpanID().String(), *segment.Links[1].SpanID) + assert.Equal(t, spanLink2.TraceID().String(), *segment.Links[1].TraceID) + assert.Equal(t, 1, len(segment.Links[0].Attributes)) + assert.Equal(t, "DEF", segment.Links[1].Attributes["myKey2"]) + + jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) + + assert.True(t, strings.Contains(jsonStr, "attributes")) + assert.True(t, strings.Contains(jsonStr, "links")) + assert.True(t, strings.Contains(jsonStr, "myKey1")) + assert.True(t, strings.Contains(jsonStr, "myKey2")) + assert.True(t, strings.Contains(jsonStr, "ABC")) + assert.True(t, strings.Contains(jsonStr, "DEF")) +} + +func TestSpanLinkComplexAttributes(t *testing.T) { spanName := "ProcessingMessage" parentSpanID := newSegmentID() attributes := make(map[string]interface{}) @@ -51,7 +102,7 @@ func TestSpanLinkAttributes(t *testing.T) { spanLink.SetSpanID(newSegmentID()) spanLink.Attributes().PutStr("myKey1", "myValue") spanLink.Attributes().PutBool("myKey2", true) - spanLink.Attributes().PutInt("myKey3", 8675309) + spanLink.Attributes().PutInt("myKey3", 112233) spanLink.Attributes().PutDouble("myKey4", 3.1415) var slice1 = spanLink.Attributes().PutEmptySlice("myKey5") @@ -74,6 +125,34 @@ func TestSpanLinkAttributes(t *testing.T) { slice4.AppendEmpty().SetDouble(2.718) slice4.AppendEmpty().SetDouble(1.618) + segment, _ := MakeSegment(span, resource, nil, false, nil) + + assert.Equal(t, 1, len(segment.Links)) + assert.Equal(t, spanLink.SpanID().String(), *segment.Links[0].SpanID) + assert.Equal(t, spanLink.TraceID().String(), *segment.Links[0].TraceID) + assert.Equal(t, 8, len(segment.Links[0].Attributes)) + + assert.Equal(t, "myValue", segment.Links[0].Attributes["myKey1"]) + assert.Equal(t, true, segment.Links[0].Attributes["myKey2"]) + assert.Equal(t, int64(112233), segment.Links[0].Attributes["myKey3"]) + assert.Equal(t, 3.1415, segment.Links[0].Attributes["myKey4"]) + + assert.Equal(t, "apple", segment.Links[0].Attributes["myKey5"].([]interface{})[0]) + assert.Equal(t, "pear", segment.Links[0].Attributes["myKey5"].([]interface{})[1]) + assert.Equal(t, "banana", segment.Links[0].Attributes["myKey5"].([]interface{})[2]) + + assert.Equal(t, true, segment.Links[0].Attributes["myKey6"].([]interface{})[0]) + assert.Equal(t, false, segment.Links[0].Attributes["myKey6"].([]interface{})[1]) + assert.Equal(t, false, segment.Links[0].Attributes["myKey6"].([]interface{})[2]) + assert.Equal(t, true, segment.Links[0].Attributes["myKey6"].([]interface{})[0]) + + assert.Equal(t, int64(1234), segment.Links[0].Attributes["myKey7"].([]interface{})[0]) + assert.Equal(t, int64(5678), segment.Links[0].Attributes["myKey7"].([]interface{})[1]) + assert.Equal(t, int64(9012), segment.Links[0].Attributes["myKey7"].([]interface{})[2]) + + assert.Equal(t, 2.718, segment.Links[0].Attributes["myKey8"].([]interface{})[0]) + assert.Equal(t, 1.618, segment.Links[0].Attributes["myKey8"].([]interface{})[1]) + jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) assert.True(t, strings.Contains(jsonStr, "links")) @@ -85,7 +164,7 @@ func TestSpanLinkAttributes(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "true")) assert.True(t, strings.Contains(jsonStr, "myKey3")) - assert.True(t, strings.Contains(jsonStr, "8675309")) + assert.True(t, strings.Contains(jsonStr, "112233")) assert.True(t, strings.Contains(jsonStr, "myKey4")) assert.True(t, strings.Contains(jsonStr, "3.1415")) @@ -96,9 +175,7 @@ func TestSpanLinkAttributes(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "banana")) assert.True(t, strings.Contains(jsonStr, "myKey6")) - assert.True(t, strings.Contains(jsonStr, "apple")) - assert.True(t, strings.Contains(jsonStr, "pear")) - assert.True(t, strings.Contains(jsonStr, "banana")) + assert.True(t, strings.Contains(jsonStr, "false")) assert.True(t, strings.Contains(jsonStr, "myKey7")) assert.True(t, strings.Contains(jsonStr, "1234")) From 417bda7d13b75df951b80695800c0e0cc2d61511 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Wed, 22 Mar 2023 12:10:39 -0700 Subject: [PATCH 03/18] Adding TraceID conversion to X-Ray format and input testing traceId --- .../internal/translator/segment.go | 6 +- .../internal/translator/spanLinks.go | 16 +++-- .../internal/translator/spanLinks_test.go | 65 +++++++++++++++---- 3 files changed, 67 insertions(+), 20 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/segment.go b/exporter/awsxrayexporter/internal/translator/segment.go index cee2ef3ea814..347ed14cfa0c 100644 --- a/exporter/awsxrayexporter/internal/translator/segment.go +++ b/exporter/awsxrayexporter/internal/translator/segment.go @@ -112,11 +112,15 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str sqlfiltered, sql = makeSQL(span, awsfiltered) additionalAttrs = addSpecialAttributes(sqlfiltered, indexedAttrs, attributes) user, annotations, metadata = makeXRayAttributes(additionalAttrs, resource, storeResource, indexedAttrs, indexAllAttrs) - spanLinks = makeSpanLinks(span.Links()) + spanLinks, makeSpanLinkErr = makeSpanLinks(span.Links()) name string namespace string ) + if makeSpanLinkErr != nil { + return nil, makeSpanLinkErr + } + // X-Ray segment names are service names, unlike span names which are methods. Try to find a service name. // peer.service should always be prioritized for segment names when set because it is what the user decided. diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks.go b/exporter/awsxrayexporter/internal/translator/spanLinks.go index 7b31eaa78149..d794c0e07078 100644 --- a/exporter/awsxrayexporter/internal/translator/spanLinks.go +++ b/exporter/awsxrayexporter/internal/translator/spanLinks.go @@ -20,18 +20,22 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace" ) -func makeSpanLinks(links ptrace.SpanLinkSlice) []awsxray.SpanLinkData { +func makeSpanLinks(links ptrace.SpanLinkSlice) ([]awsxray.SpanLinkData, error) { var spanLinkDataArray []awsxray.SpanLinkData for i := 0; i < links.Len(); i++ { var spanLinkData awsxray.SpanLinkData var link = links.At(i) - var spanId = link.SpanID().String() - var traceId = link.TraceID().String() + var spanID = link.SpanID().String() + traceID, err := convertToAmazonTraceID(link.TraceID()) - spanLinkData.SpanID = &spanId - spanLinkData.TraceID = &traceId + if err != nil { + return nil, err + } + + spanLinkData.SpanID = &spanID + spanLinkData.TraceID = &traceID if links.Len() > 0 { spanLinkData.Attributes = make(map[string]interface{}) @@ -45,5 +49,5 @@ func makeSpanLinks(links ptrace.SpanLinkSlice) []awsxray.SpanLinkData { spanLinkDataArray = append(spanLinkDataArray, spanLinkData) } - return spanLinkDataArray + return spanLinkDataArray, nil } diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go index 86fa961888fa..e6accee0edfa 100644 --- a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go +++ b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go @@ -15,8 +15,10 @@ package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" import ( + "encoding/binary" "strings" "testing" + "time" "github.com/stretchr/testify/assert" @@ -30,25 +32,55 @@ func TestSpanLinkSimple(t *testing.T) { resource := constructDefaultResource() span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) + var traceID = newTraceID() + spanLink := span.Links().AppendEmpty() - spanLink.SetTraceID(newTraceID()) + spanLink.SetTraceID(traceID) spanLink.SetSpanID(newSegmentID()) segment, _ := MakeSegment(span, resource, nil, false, nil) + var convertedTraceId, _ = convertToAmazonTraceID(traceID) + assert.Equal(t, 1, len(segment.Links)) assert.Equal(t, spanLink.SpanID().String(), *segment.Links[0].SpanID) - assert.Equal(t, spanLink.TraceID().String(), *segment.Links[0].TraceID) + assert.Equal(t, convertedTraceId, *segment.Links[0].TraceID) assert.Equal(t, 0, len(segment.Links[0].Attributes)) jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) assert.True(t, strings.Contains(jsonStr, "links")) assert.False(t, strings.Contains(jsonStr, "attributes")) - assert.True(t, strings.Contains(jsonStr, spanLink.TraceID().String())) + assert.True(t, strings.Contains(jsonStr, convertedTraceId)) assert.True(t, strings.Contains(jsonStr, spanLink.SpanID().String())) } +func TestOldSpanLinkError(t *testing.T) { + spanName := "ProcessingMessage" + parentSpanID := newSegmentID() + attributes := make(map[string]interface{}) + resource := constructDefaultResource() + span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) + + const maxAge = 60 * 60 * 24 * 35 + ExpiredEpoch := time.Now().Unix() - maxAge - 1 + + var traceID = newTraceID() + binary.BigEndian.PutUint32(traceID[0:4], uint32(ExpiredEpoch)) + + spanLink := span.Links().AppendEmpty() + spanLink.SetTraceID(traceID) + spanLink.SetSpanID(newSegmentID()) + + _, error1 := MakeSegment(span, resource, nil, false, nil) + + assert.NotNil(t, error1) + + _, error2 := MakeSegmentDocumentString(span, resource, nil, false, nil) + + assert.NotNil(t, error2) +} + func TestTwoSpanLinks(t *testing.T) { spanName := "ProcessingMessage" parentSpanID := newSegmentID() @@ -56,29 +88,36 @@ func TestTwoSpanLinks(t *testing.T) { resource := constructDefaultResource() span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) + var traceID1 = newTraceID() + spanLink1 := span.Links().AppendEmpty() - spanLink1.SetTraceID(newTraceID()) + spanLink1.SetTraceID(traceID1) spanLink1.SetSpanID(newSegmentID()) spanLink1.Attributes().PutStr("myKey1", "ABC") + var traceID2 = newTraceID() + spanLink2 := span.Links().AppendEmpty() - spanLink2.SetTraceID(newTraceID()) + spanLink2.SetTraceID(traceID2) spanLink2.SetSpanID(newSegmentID()) - spanLink2.Attributes().PutStr("myKey2", "DEF") + spanLink2.Attributes().PutInt("myKey2", 1234) segment, _ := MakeSegment(span, resource, nil, false, nil) - assert.Equal(t, 2, len(segment.Links)) + var convertedTraceId1, _ = convertToAmazonTraceID(traceID1) + var convertedTraceId2, _ = convertToAmazonTraceID(traceID2) + assert.Equal(t, 2, len(segment.Links)) assert.Equal(t, spanLink1.SpanID().String(), *segment.Links[0].SpanID) - assert.Equal(t, spanLink1.TraceID().String(), *segment.Links[0].TraceID) + assert.Equal(t, convertedTraceId1, *segment.Links[0].TraceID) + assert.Equal(t, 1, len(segment.Links[0].Attributes)) assert.Equal(t, "ABC", segment.Links[0].Attributes["myKey1"]) assert.Equal(t, spanLink2.SpanID().String(), *segment.Links[1].SpanID) - assert.Equal(t, spanLink2.TraceID().String(), *segment.Links[1].TraceID) + assert.Equal(t, convertedTraceId2, *segment.Links[1].TraceID) assert.Equal(t, 1, len(segment.Links[0].Attributes)) - assert.Equal(t, "DEF", segment.Links[1].Attributes["myKey2"]) + assert.Equal(t, int64(1234), segment.Links[1].Attributes["myKey2"]) jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) @@ -87,7 +126,9 @@ func TestTwoSpanLinks(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "myKey1")) assert.True(t, strings.Contains(jsonStr, "myKey2")) assert.True(t, strings.Contains(jsonStr, "ABC")) - assert.True(t, strings.Contains(jsonStr, "DEF")) + assert.True(t, strings.Contains(jsonStr, "1234")) + assert.True(t, strings.Contains(jsonStr, convertedTraceId1)) + assert.True(t, strings.Contains(jsonStr, convertedTraceId2)) } func TestSpanLinkComplexAttributes(t *testing.T) { @@ -128,8 +169,6 @@ func TestSpanLinkComplexAttributes(t *testing.T) { segment, _ := MakeSegment(span, resource, nil, false, nil) assert.Equal(t, 1, len(segment.Links)) - assert.Equal(t, spanLink.SpanID().String(), *segment.Links[0].SpanID) - assert.Equal(t, spanLink.TraceID().String(), *segment.Links[0].TraceID) assert.Equal(t, 8, len(segment.Links[0].Attributes)) assert.Equal(t, "myValue", segment.Links[0].Attributes["myKey1"]) From f04e2617cccd2d29212f7d0054ccb46c4b38adf3 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Wed, 22 Mar 2023 15:28:20 -0700 Subject: [PATCH 04/18] Adding messaging field to segment --- .../internal/translator/messaging.go | 38 ++++++ .../internal/translator/messaging_test.go | 108 ++++++++++++++++++ .../internal/translator/segment.go | 4 +- internal/aws/xray/tracesegment.go | 11 +- 4 files changed, 155 insertions(+), 6 deletions(-) create mode 100644 exporter/awsxrayexporter/internal/translator/messaging.go create mode 100644 exporter/awsxrayexporter/internal/translator/messaging_test.go diff --git a/exporter/awsxrayexporter/internal/translator/messaging.go b/exporter/awsxrayexporter/internal/translator/messaging.go new file mode 100644 index 000000000000..4a77af3a3861 --- /dev/null +++ b/exporter/awsxrayexporter/internal/translator/messaging.go @@ -0,0 +1,38 @@ +// Copyright 2019, OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" + +import ( + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/ptrace" + "strings" +) + +func makeMessaging(span ptrace.Span, attributes map[string]pcommon.Value) (map[string]pcommon.Value, map[string]interface{}) { + var ( + filtered = make(map[string]pcommon.Value) + messaging = make(map[string]interface{}) + ) + + for key, value := range attributes { + if strings.HasPrefix(key, "messaging.") { + messaging[strings.TrimPrefix(key, "messaging.")] = value.AsRaw() + } else { + filtered[key] = value + } + } + + return filtered, messaging +} diff --git a/exporter/awsxrayexporter/internal/translator/messaging_test.go b/exporter/awsxrayexporter/internal/translator/messaging_test.go new file mode 100644 index 000000000000..8e121cde8d57 --- /dev/null +++ b/exporter/awsxrayexporter/internal/translator/messaging_test.go @@ -0,0 +1,108 @@ +// Copyright 2019, OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/ptrace" +) + +func TestMessagingSimple(t *testing.T) { + spanName := "ProcessingMessage" + parentSpanID := newSegmentID() + attributes := make(map[string]interface{}) + resource := constructDefaultResource() + span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) + + span.Attributes().PutStr("messaging.operation", "process") + span.Attributes().PutStr("messaging.system", "AmazonSQS") + span.Attributes().PutStr("notMessaging", "myValue") + + segment, _ := MakeSegment(span, resource, nil, false, nil) + + assert.Equal(t, 2, len(segment.Messaging)) + assert.Equal(t, "process", segment.Messaging["operation"]) + assert.Equal(t, "AmazonSQS", segment.Messaging["system"]) + assert.Equal(t, "myValue", segment.Metadata["default"]["notMessaging"]) + + jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) + + assert.True(t, strings.Contains(jsonStr, "messaging")) + + assert.True(t, strings.Contains(jsonStr, "operation")) + assert.True(t, strings.Contains(jsonStr, "process")) + + assert.True(t, strings.Contains(jsonStr, "system")) + assert.True(t, strings.Contains(jsonStr, "AmazonSQS")) + + assert.True(t, strings.Contains(jsonStr, "notMessaging")) + assert.True(t, strings.Contains(jsonStr, "myValue")) +} + +func TestMessagingComplex(t *testing.T) { + spanName := "ProcessingMessage" + parentSpanID := newSegmentID() + attributes := make(map[string]interface{}) + resource := constructDefaultResource() + span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) + + span.Attributes().PutStr("messaging.operation", "process") + span.Attributes().PutStr("messaging.system", "AmazonSQS") + span.Attributes().PutInt("messaging.message_count", 7) + span.Attributes().PutInt("messaging.payload_size_bytes", 2048) + span.Attributes().PutInt("messaging.payload_compressed_size_bytes", 1024) + span.Attributes().PutStr("messaging.conversation_id", "MyConversationId") + span.Attributes().PutStr("messaging.id", "452a7c7c7c7048c2f887f61572b18fc2") + + segment, _ := MakeSegment(span, resource, nil, false, nil) + + assert.Equal(t, 7, len(segment.Messaging)) + assert.Equal(t, "process", segment.Messaging["operation"]) + assert.Equal(t, "AmazonSQS", segment.Messaging["system"]) + assert.Equal(t, int64(7), segment.Messaging["message_count"]) + assert.Equal(t, int64(2048), segment.Messaging["payload_size_bytes"]) + assert.Equal(t, int64(1024), segment.Messaging["payload_compressed_size_bytes"]) + assert.Equal(t, "MyConversationId", segment.Messaging["conversation_id"]) + assert.Equal(t, "452a7c7c7c7048c2f887f61572b18fc2", segment.Messaging["id"]) + + jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) + + assert.True(t, strings.Contains(jsonStr, "messaging")) + + assert.True(t, strings.Contains(jsonStr, "operation")) + assert.True(t, strings.Contains(jsonStr, "process")) + + assert.True(t, strings.Contains(jsonStr, "system")) + assert.True(t, strings.Contains(jsonStr, "AmazonSQS")) + + assert.True(t, strings.Contains(jsonStr, "message_count")) + assert.True(t, strings.Contains(jsonStr, "7")) + + assert.True(t, strings.Contains(jsonStr, "payload_size_bytes")) + assert.True(t, strings.Contains(jsonStr, "2048")) + + assert.True(t, strings.Contains(jsonStr, "payload_compressed_size_bytes")) + assert.True(t, strings.Contains(jsonStr, "1024")) + + assert.True(t, strings.Contains(jsonStr, "conversation_id")) + assert.True(t, strings.Contains(jsonStr, "MyConversationId")) + + assert.True(t, strings.Contains(jsonStr, "id")) + assert.True(t, strings.Contains(jsonStr, "452a7c7c7c7048c2f887f61572b18fc2")) +} diff --git a/exporter/awsxrayexporter/internal/translator/segment.go b/exporter/awsxrayexporter/internal/translator/segment.go index 347ed14cfa0c..d94a6f1cbf07 100644 --- a/exporter/awsxrayexporter/internal/translator/segment.go +++ b/exporter/awsxrayexporter/internal/translator/segment.go @@ -110,7 +110,8 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str awsfiltered, aws = makeAws(causefiltered, resource, logGroupNames) service = makeService(resource) sqlfiltered, sql = makeSQL(span, awsfiltered) - additionalAttrs = addSpecialAttributes(sqlfiltered, indexedAttrs, attributes) + messagingFiltered, messaging = makeMessaging(span, sqlfiltered) + additionalAttrs = addSpecialAttributes(messagingFiltered, indexedAttrs, attributes) user, annotations, metadata = makeXRayAttributes(additionalAttrs, resource, storeResource, indexedAttrs, indexAllAttrs) spanLinks, makeSpanLinkErr = makeSpanLinks(span.Links()) name string @@ -217,6 +218,7 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str Metadata: metadata, Type: awsxray.String(segmentType), Links: spanLinks, + Messaging: messaging, }, nil } diff --git a/internal/aws/xray/tracesegment.go b/internal/aws/xray/tracesegment.go index ee60ca2ad852..d4fa126e6eca 100644 --- a/internal/aws/xray/tracesegment.go +++ b/internal/aws/xray/tracesegment.go @@ -45,11 +45,12 @@ type Segment struct { StartTime *float64 `json:"start_time"` // Segment-only optional fields - Service *ServiceData `json:"service,omitempty"` - Origin *string `json:"origin,omitempty"` - User *string `json:"user,omitempty"` - ResourceARN *string `json:"resource_arn,omitempty"` - Links []SpanLinkData `json:"links,omitempty"` + Service *ServiceData `json:"service,omitempty"` + Origin *string `json:"origin,omitempty"` + User *string `json:"user,omitempty"` + ResourceARN *string `json:"resource_arn,omitempty"` + Links []SpanLinkData `json:"links,omitempty"` + Messaging map[string]interface{} `json:"messaging,omitempty"` // Optional fields for both Segment and subsegments TraceID *string `json:"trace_id,omitempty"` From d54b86f6e1bd9af040fbccc59dda21c9b6c91ed2 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Wed, 22 Mar 2023 15:47:38 -0700 Subject: [PATCH 05/18] Polishing and adding empty field tests --- .../internal/translator/messaging_test.go | 16 ++++++++++++++++ .../internal/translator/spanLinks_test.go | 18 +++++++++++++++++- internal/aws/xray/tracesegment.go | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/messaging_test.go b/exporter/awsxrayexporter/internal/translator/messaging_test.go index 8e121cde8d57..0da8f10c9d24 100644 --- a/exporter/awsxrayexporter/internal/translator/messaging_test.go +++ b/exporter/awsxrayexporter/internal/translator/messaging_test.go @@ -55,6 +55,22 @@ func TestMessagingSimple(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "myValue")) } +func TestMessagingEmpty(t *testing.T) { + spanName := "ProcessingMessage" + parentSpanID := newSegmentID() + attributes := make(map[string]interface{}) + resource := constructDefaultResource() + span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) + + segment, _ := MakeSegment(span, resource, nil, false, nil) + + assert.Equal(t, 0, len(segment.Messaging)) + + jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) + + assert.False(t, strings.Contains(jsonStr, "messaging")) +} + func TestMessagingComplex(t *testing.T) { spanName := "ProcessingMessage" parentSpanID := newSegmentID() diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go index e6accee0edfa..30b9b6738c3c 100644 --- a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go +++ b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go @@ -55,6 +55,22 @@ func TestSpanLinkSimple(t *testing.T) { assert.True(t, strings.Contains(jsonStr, spanLink.SpanID().String())) } +func TestSpanLinkEmpty(t *testing.T) { + spanName := "ProcessingMessage" + parentSpanID := newSegmentID() + attributes := make(map[string]interface{}) + resource := constructDefaultResource() + span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) + + segment, _ := MakeSegment(span, resource, nil, false, nil) + + assert.Equal(t, 0, len(segment.Links)) + + jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) + + assert.False(t, strings.Contains(jsonStr, "links")) +} + func TestOldSpanLinkError(t *testing.T) { spanName := "ProcessingMessage" parentSpanID := newSegmentID() @@ -62,7 +78,7 @@ func TestOldSpanLinkError(t *testing.T) { resource := constructDefaultResource() span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) - const maxAge = 60 * 60 * 24 * 35 + const maxAge = 60 * 60 * 24 * 30 ExpiredEpoch := time.Now().Unix() - maxAge - 1 var traceID = newTraceID() diff --git a/internal/aws/xray/tracesegment.go b/internal/aws/xray/tracesegment.go index d4fa126e6eca..81334b8f5af4 100644 --- a/internal/aws/xray/tracesegment.go +++ b/internal/aws/xray/tracesegment.go @@ -283,7 +283,7 @@ type ServiceData struct { Compiler *string `json:"compiler,omitempty"` } -// SpanLinkData provides the shape for unmarshalling the service field. +// SpanLinkData provides the shape for unmarshalling the span links in the span link field. type SpanLinkData struct { TraceID *string `json:"trace_id"` SpanID *string `json:"id"` From fe027b653834b2ed3002a603940804cb0653c791 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Wed, 22 Mar 2023 19:21:37 -0700 Subject: [PATCH 06/18] Adding test for indexed attributes --- .../internal/translator/messaging_test.go | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/exporter/awsxrayexporter/internal/translator/messaging_test.go b/exporter/awsxrayexporter/internal/translator/messaging_test.go index 0da8f10c9d24..9a217116c191 100644 --- a/exporter/awsxrayexporter/internal/translator/messaging_test.go +++ b/exporter/awsxrayexporter/internal/translator/messaging_test.go @@ -40,6 +40,7 @@ func TestMessagingSimple(t *testing.T) { assert.Equal(t, "process", segment.Messaging["operation"]) assert.Equal(t, "AmazonSQS", segment.Messaging["system"]) assert.Equal(t, "myValue", segment.Metadata["default"]["notMessaging"]) + assert.Equal(t, 0, len(segment.Annotations)) jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) @@ -122,3 +123,34 @@ func TestMessagingComplex(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "id")) assert.True(t, strings.Contains(jsonStr, "452a7c7c7c7048c2f887f61572b18fc2")) } + +func TestMessagingWithIndexedAttributes(t *testing.T) { + spanName := "ProcessingMessage" + parentSpanID := newSegmentID() + attributes := make(map[string]interface{}) + resource := constructDefaultResource() + span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) + + span.Attributes().PutStr("messaging.operation", "process") + span.Attributes().PutStr("messaging.system", "AmazonSQS") + + segment, _ := MakeSegment(span, resource, []string{"messaging.system"}, false, nil) + + assert.Equal(t, 2, len(segment.Messaging)) + assert.Equal(t, "process", segment.Messaging["operation"]) + assert.Equal(t, "AmazonSQS", segment.Messaging["system"]) + assert.Equal(t, 1, len(segment.Annotations)) + assert.Equal(t, "AmazonSQS", segment.Annotations["messaging_system"]) + + jsonStr, _ := MakeSegmentDocumentString(span, resource, []string{"messaging.system"}, false, nil) + + assert.True(t, strings.Contains(jsonStr, "messaging")) + + assert.True(t, strings.Contains(jsonStr, "operation")) + assert.True(t, strings.Contains(jsonStr, "process")) + + assert.True(t, strings.Contains(jsonStr, "system")) + assert.True(t, strings.Contains(jsonStr, "AmazonSQS")) + assert.True(t, strings.Contains(jsonStr, "annotations")) + assert.True(t, strings.Contains(jsonStr, "messaging_system")) +} From 3aab1adcbd420eb35511aaa7a952d935e45c93dd Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Thu, 23 Mar 2023 09:50:02 -0700 Subject: [PATCH 07/18] Adding splice data to messaging test --- .../internal/translator/messaging_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/exporter/awsxrayexporter/internal/translator/messaging_test.go b/exporter/awsxrayexporter/internal/translator/messaging_test.go index 9a217116c191..98d6f8bab174 100644 --- a/exporter/awsxrayexporter/internal/translator/messaging_test.go +++ b/exporter/awsxrayexporter/internal/translator/messaging_test.go @@ -86,10 +86,13 @@ func TestMessagingComplex(t *testing.T) { span.Attributes().PutInt("messaging.payload_compressed_size_bytes", 1024) span.Attributes().PutStr("messaging.conversation_id", "MyConversationId") span.Attributes().PutStr("messaging.id", "452a7c7c7c7048c2f887f61572b18fc2") + var slice = span.Attributes().PutEmptySlice("messaging.sliceData") + slice.AppendEmpty().SetStr("alpha") + slice.AppendEmpty().SetStr("beta") segment, _ := MakeSegment(span, resource, nil, false, nil) - assert.Equal(t, 7, len(segment.Messaging)) + assert.Equal(t, 8, len(segment.Messaging)) assert.Equal(t, "process", segment.Messaging["operation"]) assert.Equal(t, "AmazonSQS", segment.Messaging["system"]) assert.Equal(t, int64(7), segment.Messaging["message_count"]) @@ -97,6 +100,8 @@ func TestMessagingComplex(t *testing.T) { assert.Equal(t, int64(1024), segment.Messaging["payload_compressed_size_bytes"]) assert.Equal(t, "MyConversationId", segment.Messaging["conversation_id"]) assert.Equal(t, "452a7c7c7c7048c2f887f61572b18fc2", segment.Messaging["id"]) + assert.Equal(t, "alpha", segment.Messaging["sliceData"].([]interface{})[0]) + assert.Equal(t, "beta", segment.Messaging["sliceData"].([]interface{})[1]) jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) @@ -122,6 +127,10 @@ func TestMessagingComplex(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "id")) assert.True(t, strings.Contains(jsonStr, "452a7c7c7c7048c2f887f61572b18fc2")) + + assert.True(t, strings.Contains(jsonStr, "sliceData")) + assert.True(t, strings.Contains(jsonStr, "alpha")) + assert.True(t, strings.Contains(jsonStr, "beta")) } func TestMessagingWithIndexedAttributes(t *testing.T) { From 69e9d5bbb791164eb4aa190a17484f9c0d719f0a Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Fri, 24 Mar 2023 16:00:51 -0700 Subject: [PATCH 08/18] Moving variable to const --- exporter/awsxrayexporter/internal/translator/messaging.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/messaging.go b/exporter/awsxrayexporter/internal/translator/messaging.go index 4a77af3a3861..8e04dd0d3401 100644 --- a/exporter/awsxrayexporter/internal/translator/messaging.go +++ b/exporter/awsxrayexporter/internal/translator/messaging.go @@ -20,6 +20,8 @@ import ( "strings" ) +const MessagingPrefix = "messaging." + func makeMessaging(span ptrace.Span, attributes map[string]pcommon.Value) (map[string]pcommon.Value, map[string]interface{}) { var ( filtered = make(map[string]pcommon.Value) @@ -27,8 +29,8 @@ func makeMessaging(span ptrace.Span, attributes map[string]pcommon.Value) (map[s ) for key, value := range attributes { - if strings.HasPrefix(key, "messaging.") { - messaging[strings.TrimPrefix(key, "messaging.")] = value.AsRaw() + if strings.HasPrefix(key, MessagingPrefix) { + messaging[strings.TrimPrefix(key, MessagingPrefix)] = value.AsRaw() } else { filtered[key] = value } From 32490a26d0d29fcf85a7b8485e3a2a16a03f3804 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Fri, 24 Mar 2023 16:21:20 -0700 Subject: [PATCH 09/18] Fixing bug --- .../awsxrayexporter/internal/translator/spanLinks.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks.go b/exporter/awsxrayexporter/internal/translator/spanLinks.go index d794c0e07078..e0cbae5ee0bc 100644 --- a/exporter/awsxrayexporter/internal/translator/spanLinks.go +++ b/exporter/awsxrayexporter/internal/translator/spanLinks.go @@ -37,14 +37,14 @@ func makeSpanLinks(links ptrace.SpanLinkSlice) ([]awsxray.SpanLinkData, error) { spanLinkData.SpanID = &spanID spanLinkData.TraceID = &traceID - if links.Len() > 0 { + if link.Attributes().Len() > 0 { spanLinkData.Attributes = make(map[string]interface{}) - } - link.Attributes().Range(func(k string, v pcommon.Value) bool { - spanLinkData.Attributes[k] = v.AsRaw() - return true - }) + link.Attributes().Range(func(k string, v pcommon.Value) bool { + spanLinkData.Attributes[k] = v.AsRaw() + return true + }) + } spanLinkDataArray = append(spanLinkDataArray, spanLinkData) } From 91c0bd4e55fab9e61144551c192e4e5ab040ed40 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Mon, 27 Mar 2023 11:25:18 -0700 Subject: [PATCH 10/18] Adding change log --- ...y-support-span-links-and-messaging-field.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .chloggen/awsxray-support-span-links-and-messaging-field.yaml diff --git a/.chloggen/awsxray-support-span-links-and-messaging-field.yaml b/.chloggen/awsxray-support-span-links-and-messaging-field.yaml new file mode 100644 index 000000000000..d90e48da2270 --- /dev/null +++ b/.chloggen/awsxray-support-span-links-and-messaging-field.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: awsxrayexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Adding translation support for span links and the messaging field for the aws x-ray exporter + +# One or more tracking issues related to the change +issues: [20353] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: From 0a38209a4c7a1a751509e3d282eade3e0c7e6f60 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Mon, 27 Mar 2023 11:34:49 -0700 Subject: [PATCH 11/18] Addressing linter --- .../internal/translator/messaging.go | 3 +-- .../internal/translator/segment.go | 2 +- .../internal/translator/spanLinks_test.go | 18 +++++++++--------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/messaging.go b/exporter/awsxrayexporter/internal/translator/messaging.go index 8e04dd0d3401..c5defcdf1fe0 100644 --- a/exporter/awsxrayexporter/internal/translator/messaging.go +++ b/exporter/awsxrayexporter/internal/translator/messaging.go @@ -16,13 +16,12 @@ package translator // import "github.com/open-telemetry/opentelemetry-collector- import ( "go.opentelemetry.io/collector/pdata/pcommon" - "go.opentelemetry.io/collector/pdata/ptrace" "strings" ) const MessagingPrefix = "messaging." -func makeMessaging(span ptrace.Span, attributes map[string]pcommon.Value) (map[string]pcommon.Value, map[string]interface{}) { +func makeMessaging(attributes map[string]pcommon.Value) (map[string]pcommon.Value, map[string]interface{}) { var ( filtered = make(map[string]pcommon.Value) messaging = make(map[string]interface{}) diff --git a/exporter/awsxrayexporter/internal/translator/segment.go b/exporter/awsxrayexporter/internal/translator/segment.go index d94a6f1cbf07..735254984bd2 100644 --- a/exporter/awsxrayexporter/internal/translator/segment.go +++ b/exporter/awsxrayexporter/internal/translator/segment.go @@ -110,7 +110,7 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str awsfiltered, aws = makeAws(causefiltered, resource, logGroupNames) service = makeService(resource) sqlfiltered, sql = makeSQL(span, awsfiltered) - messagingFiltered, messaging = makeMessaging(span, sqlfiltered) + messagingFiltered, messaging = makeMessaging(sqlfiltered) additionalAttrs = addSpecialAttributes(messagingFiltered, indexedAttrs, attributes) user, annotations, metadata = makeXRayAttributes(additionalAttrs, resource, storeResource, indexedAttrs, indexAllAttrs) spanLinks, makeSpanLinkErr = makeSpanLinks(span.Links()) diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go index 30b9b6738c3c..b1476b1faf1f 100644 --- a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go +++ b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go @@ -40,18 +40,18 @@ func TestSpanLinkSimple(t *testing.T) { segment, _ := MakeSegment(span, resource, nil, false, nil) - var convertedTraceId, _ = convertToAmazonTraceID(traceID) + var convertedTraceID, _ = convertToAmazonTraceID(traceID) assert.Equal(t, 1, len(segment.Links)) assert.Equal(t, spanLink.SpanID().String(), *segment.Links[0].SpanID) - assert.Equal(t, convertedTraceId, *segment.Links[0].TraceID) + assert.Equal(t, convertedTraceID, *segment.Links[0].TraceID) assert.Equal(t, 0, len(segment.Links[0].Attributes)) jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) assert.True(t, strings.Contains(jsonStr, "links")) assert.False(t, strings.Contains(jsonStr, "attributes")) - assert.True(t, strings.Contains(jsonStr, convertedTraceId)) + assert.True(t, strings.Contains(jsonStr, convertedTraceID)) assert.True(t, strings.Contains(jsonStr, spanLink.SpanID().String())) } @@ -120,18 +120,18 @@ func TestTwoSpanLinks(t *testing.T) { segment, _ := MakeSegment(span, resource, nil, false, nil) - var convertedTraceId1, _ = convertToAmazonTraceID(traceID1) - var convertedTraceId2, _ = convertToAmazonTraceID(traceID2) + var convertedTraceID1, _ = convertToAmazonTraceID(traceID1) + var convertedTraceID2, _ = convertToAmazonTraceID(traceID2) assert.Equal(t, 2, len(segment.Links)) assert.Equal(t, spanLink1.SpanID().String(), *segment.Links[0].SpanID) - assert.Equal(t, convertedTraceId1, *segment.Links[0].TraceID) + assert.Equal(t, convertedTraceID1, *segment.Links[0].TraceID) assert.Equal(t, 1, len(segment.Links[0].Attributes)) assert.Equal(t, "ABC", segment.Links[0].Attributes["myKey1"]) assert.Equal(t, spanLink2.SpanID().String(), *segment.Links[1].SpanID) - assert.Equal(t, convertedTraceId2, *segment.Links[1].TraceID) + assert.Equal(t, convertedTraceID2, *segment.Links[1].TraceID) assert.Equal(t, 1, len(segment.Links[0].Attributes)) assert.Equal(t, int64(1234), segment.Links[1].Attributes["myKey2"]) @@ -143,8 +143,8 @@ func TestTwoSpanLinks(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "myKey2")) assert.True(t, strings.Contains(jsonStr, "ABC")) assert.True(t, strings.Contains(jsonStr, "1234")) - assert.True(t, strings.Contains(jsonStr, convertedTraceId1)) - assert.True(t, strings.Contains(jsonStr, convertedTraceId2)) + assert.True(t, strings.Contains(jsonStr, convertedTraceID1)) + assert.True(t, strings.Contains(jsonStr, convertedTraceID2)) } func TestSpanLinkComplexAttributes(t *testing.T) { From 2c04e6018beb1c2c93f9b1f53e03a9f3c3164fc9 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Mon, 27 Mar 2023 11:57:38 -0700 Subject: [PATCH 12/18] Addressing PR --- exporter/awsxrayexporter/internal/translator/messaging.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/messaging.go b/exporter/awsxrayexporter/internal/translator/messaging.go index c5defcdf1fe0..100c3ee91cb5 100644 --- a/exporter/awsxrayexporter/internal/translator/messaging.go +++ b/exporter/awsxrayexporter/internal/translator/messaging.go @@ -19,7 +19,7 @@ import ( "strings" ) -const MessagingPrefix = "messaging." +const messagingPrefix = "messaging." func makeMessaging(attributes map[string]pcommon.Value) (map[string]pcommon.Value, map[string]interface{}) { var ( @@ -28,8 +28,8 @@ func makeMessaging(attributes map[string]pcommon.Value) (map[string]pcommon.Valu ) for key, value := range attributes { - if strings.HasPrefix(key, MessagingPrefix) { - messaging[strings.TrimPrefix(key, MessagingPrefix)] = value.AsRaw() + if strings.HasPrefix(key, messagingPrefix) { + messaging[strings.TrimPrefix(key, messagingPrefix)] = value.AsRaw() } else { filtered[key] = value } From fd7683f160870ec321f5a5dadbab2559b8f63d69 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Mon, 27 Mar 2023 13:02:19 -0700 Subject: [PATCH 13/18] Fixing linter --- exporter/awsxrayexporter/internal/translator/messaging.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exporter/awsxrayexporter/internal/translator/messaging.go b/exporter/awsxrayexporter/internal/translator/messaging.go index 100c3ee91cb5..ff1071ae82f5 100644 --- a/exporter/awsxrayexporter/internal/translator/messaging.go +++ b/exporter/awsxrayexporter/internal/translator/messaging.go @@ -15,8 +15,9 @@ package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" import ( - "go.opentelemetry.io/collector/pdata/pcommon" "strings" + + "go.opentelemetry.io/collector/pdata/pcommon" ) const messagingPrefix = "messaging." From 60a7162f527046b42f6d7ef3dc1885f3b4d76fcd Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Mon, 27 Mar 2023 13:18:56 -0700 Subject: [PATCH 14/18] Fixing linter --- exporter/awsxrayexporter/internal/translator/messaging_test.go | 1 - exporter/awsxrayexporter/internal/translator/spanLinks.go | 3 ++- exporter/awsxrayexporter/internal/translator/spanLinks_test.go | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/messaging_test.go b/exporter/awsxrayexporter/internal/translator/messaging_test.go index 98d6f8bab174..95d8cdac5754 100644 --- a/exporter/awsxrayexporter/internal/translator/messaging_test.go +++ b/exporter/awsxrayexporter/internal/translator/messaging_test.go @@ -19,7 +19,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/pdata/ptrace" ) diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks.go b/exporter/awsxrayexporter/internal/translator/spanLinks.go index e0cbae5ee0bc..3851cbcd4d35 100644 --- a/exporter/awsxrayexporter/internal/translator/spanLinks.go +++ b/exporter/awsxrayexporter/internal/translator/spanLinks.go @@ -15,9 +15,10 @@ package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" import ( - awsxray "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" + + awsxray "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray" ) func makeSpanLinks(links ptrace.SpanLinkSlice) ([]awsxray.SpanLinkData, error) { diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go index b1476b1faf1f..8c5a468f1a83 100644 --- a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go +++ b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go @@ -21,7 +21,6 @@ import ( "time" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/pdata/ptrace" ) From 83287e50f068a9fb4d93188e6c0e7279b28479e0 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Tue, 6 Jun 2023 09:26:58 -0700 Subject: [PATCH 15/18] Fixing linter issues --- .../internal/translator/messaging.go | 15 ++------------- .../internal/translator/messaging_test.go | 15 ++------------- .../internal/translator/spanLinks.go | 15 ++------------- .../internal/translator/spanLinks_test.go | 15 ++------------- 4 files changed, 8 insertions(+), 52 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/messaging.go b/exporter/awsxrayexporter/internal/translator/messaging.go index ff1071ae82f5..ca2b81c2d856 100644 --- a/exporter/awsxrayexporter/internal/translator/messaging.go +++ b/exporter/awsxrayexporter/internal/translator/messaging.go @@ -1,16 +1,5 @@ -// Copyright 2019, OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" diff --git a/exporter/awsxrayexporter/internal/translator/messaging_test.go b/exporter/awsxrayexporter/internal/translator/messaging_test.go index 95d8cdac5754..1ecc625c8b9c 100644 --- a/exporter/awsxrayexporter/internal/translator/messaging_test.go +++ b/exporter/awsxrayexporter/internal/translator/messaging_test.go @@ -1,16 +1,5 @@ -// Copyright 2019, OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks.go b/exporter/awsxrayexporter/internal/translator/spanLinks.go index 3851cbcd4d35..cae2ed11b72e 100644 --- a/exporter/awsxrayexporter/internal/translator/spanLinks.go +++ b/exporter/awsxrayexporter/internal/translator/spanLinks.go @@ -1,16 +1,5 @@ -// Copyright 2019, OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go index 8c5a468f1a83..1f7e4db54ca7 100644 --- a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go +++ b/exporter/awsxrayexporter/internal/translator/spanLinks_test.go @@ -1,16 +1,5 @@ -// Copyright 2019, OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" From 0fae7ebb8932ebce7f18de7335756d87b3107ecb Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Thu, 15 Jun 2023 15:05:12 -0700 Subject: [PATCH 16/18] Removing messaging field translation --- ...upport-span-links-and-messaging-field.yaml | 2 +- .../internal/translator/messaging.go | 29 ---- .../internal/translator/messaging_test.go | 153 ------------------ .../internal/translator/segment.go | 4 +- internal/aws/xray/tracesegment.go | 11 +- 5 files changed, 7 insertions(+), 192 deletions(-) delete mode 100644 exporter/awsxrayexporter/internal/translator/messaging.go delete mode 100644 exporter/awsxrayexporter/internal/translator/messaging_test.go diff --git a/.chloggen/awsxray-support-span-links-and-messaging-field.yaml b/.chloggen/awsxray-support-span-links-and-messaging-field.yaml index d90e48da2270..91946d67afa7 100644 --- a/.chloggen/awsxray-support-span-links-and-messaging-field.yaml +++ b/.chloggen/awsxray-support-span-links-and-messaging-field.yaml @@ -5,7 +5,7 @@ change_type: enhancement component: awsxrayexporter # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Adding translation support for span links and the messaging field for the aws x-ray exporter +note: Adding translation support for span links for the aws x-ray exporter # One or more tracking issues related to the change issues: [20353] diff --git a/exporter/awsxrayexporter/internal/translator/messaging.go b/exporter/awsxrayexporter/internal/translator/messaging.go deleted file mode 100644 index ca2b81c2d856..000000000000 --- a/exporter/awsxrayexporter/internal/translator/messaging.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" - -import ( - "strings" - - "go.opentelemetry.io/collector/pdata/pcommon" -) - -const messagingPrefix = "messaging." - -func makeMessaging(attributes map[string]pcommon.Value) (map[string]pcommon.Value, map[string]interface{}) { - var ( - filtered = make(map[string]pcommon.Value) - messaging = make(map[string]interface{}) - ) - - for key, value := range attributes { - if strings.HasPrefix(key, messagingPrefix) { - messaging[strings.TrimPrefix(key, messagingPrefix)] = value.AsRaw() - } else { - filtered[key] = value - } - } - - return filtered, messaging -} diff --git a/exporter/awsxrayexporter/internal/translator/messaging_test.go b/exporter/awsxrayexporter/internal/translator/messaging_test.go deleted file mode 100644 index 1ecc625c8b9c..000000000000 --- a/exporter/awsxrayexporter/internal/translator/messaging_test.go +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" - -import ( - "strings" - "testing" - - "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/pdata/ptrace" -) - -func TestMessagingSimple(t *testing.T) { - spanName := "ProcessingMessage" - parentSpanID := newSegmentID() - attributes := make(map[string]interface{}) - resource := constructDefaultResource() - span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) - - span.Attributes().PutStr("messaging.operation", "process") - span.Attributes().PutStr("messaging.system", "AmazonSQS") - span.Attributes().PutStr("notMessaging", "myValue") - - segment, _ := MakeSegment(span, resource, nil, false, nil) - - assert.Equal(t, 2, len(segment.Messaging)) - assert.Equal(t, "process", segment.Messaging["operation"]) - assert.Equal(t, "AmazonSQS", segment.Messaging["system"]) - assert.Equal(t, "myValue", segment.Metadata["default"]["notMessaging"]) - assert.Equal(t, 0, len(segment.Annotations)) - - jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) - - assert.True(t, strings.Contains(jsonStr, "messaging")) - - assert.True(t, strings.Contains(jsonStr, "operation")) - assert.True(t, strings.Contains(jsonStr, "process")) - - assert.True(t, strings.Contains(jsonStr, "system")) - assert.True(t, strings.Contains(jsonStr, "AmazonSQS")) - - assert.True(t, strings.Contains(jsonStr, "notMessaging")) - assert.True(t, strings.Contains(jsonStr, "myValue")) -} - -func TestMessagingEmpty(t *testing.T) { - spanName := "ProcessingMessage" - parentSpanID := newSegmentID() - attributes := make(map[string]interface{}) - resource := constructDefaultResource() - span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) - - segment, _ := MakeSegment(span, resource, nil, false, nil) - - assert.Equal(t, 0, len(segment.Messaging)) - - jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) - - assert.False(t, strings.Contains(jsonStr, "messaging")) -} - -func TestMessagingComplex(t *testing.T) { - spanName := "ProcessingMessage" - parentSpanID := newSegmentID() - attributes := make(map[string]interface{}) - resource := constructDefaultResource() - span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) - - span.Attributes().PutStr("messaging.operation", "process") - span.Attributes().PutStr("messaging.system", "AmazonSQS") - span.Attributes().PutInt("messaging.message_count", 7) - span.Attributes().PutInt("messaging.payload_size_bytes", 2048) - span.Attributes().PutInt("messaging.payload_compressed_size_bytes", 1024) - span.Attributes().PutStr("messaging.conversation_id", "MyConversationId") - span.Attributes().PutStr("messaging.id", "452a7c7c7c7048c2f887f61572b18fc2") - var slice = span.Attributes().PutEmptySlice("messaging.sliceData") - slice.AppendEmpty().SetStr("alpha") - slice.AppendEmpty().SetStr("beta") - - segment, _ := MakeSegment(span, resource, nil, false, nil) - - assert.Equal(t, 8, len(segment.Messaging)) - assert.Equal(t, "process", segment.Messaging["operation"]) - assert.Equal(t, "AmazonSQS", segment.Messaging["system"]) - assert.Equal(t, int64(7), segment.Messaging["message_count"]) - assert.Equal(t, int64(2048), segment.Messaging["payload_size_bytes"]) - assert.Equal(t, int64(1024), segment.Messaging["payload_compressed_size_bytes"]) - assert.Equal(t, "MyConversationId", segment.Messaging["conversation_id"]) - assert.Equal(t, "452a7c7c7c7048c2f887f61572b18fc2", segment.Messaging["id"]) - assert.Equal(t, "alpha", segment.Messaging["sliceData"].([]interface{})[0]) - assert.Equal(t, "beta", segment.Messaging["sliceData"].([]interface{})[1]) - - jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil) - - assert.True(t, strings.Contains(jsonStr, "messaging")) - - assert.True(t, strings.Contains(jsonStr, "operation")) - assert.True(t, strings.Contains(jsonStr, "process")) - - assert.True(t, strings.Contains(jsonStr, "system")) - assert.True(t, strings.Contains(jsonStr, "AmazonSQS")) - - assert.True(t, strings.Contains(jsonStr, "message_count")) - assert.True(t, strings.Contains(jsonStr, "7")) - - assert.True(t, strings.Contains(jsonStr, "payload_size_bytes")) - assert.True(t, strings.Contains(jsonStr, "2048")) - - assert.True(t, strings.Contains(jsonStr, "payload_compressed_size_bytes")) - assert.True(t, strings.Contains(jsonStr, "1024")) - - assert.True(t, strings.Contains(jsonStr, "conversation_id")) - assert.True(t, strings.Contains(jsonStr, "MyConversationId")) - - assert.True(t, strings.Contains(jsonStr, "id")) - assert.True(t, strings.Contains(jsonStr, "452a7c7c7c7048c2f887f61572b18fc2")) - - assert.True(t, strings.Contains(jsonStr, "sliceData")) - assert.True(t, strings.Contains(jsonStr, "alpha")) - assert.True(t, strings.Contains(jsonStr, "beta")) -} - -func TestMessagingWithIndexedAttributes(t *testing.T) { - spanName := "ProcessingMessage" - parentSpanID := newSegmentID() - attributes := make(map[string]interface{}) - resource := constructDefaultResource() - span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeOk, "OK", attributes) - - span.Attributes().PutStr("messaging.operation", "process") - span.Attributes().PutStr("messaging.system", "AmazonSQS") - - segment, _ := MakeSegment(span, resource, []string{"messaging.system"}, false, nil) - - assert.Equal(t, 2, len(segment.Messaging)) - assert.Equal(t, "process", segment.Messaging["operation"]) - assert.Equal(t, "AmazonSQS", segment.Messaging["system"]) - assert.Equal(t, 1, len(segment.Annotations)) - assert.Equal(t, "AmazonSQS", segment.Annotations["messaging_system"]) - - jsonStr, _ := MakeSegmentDocumentString(span, resource, []string{"messaging.system"}, false, nil) - - assert.True(t, strings.Contains(jsonStr, "messaging")) - - assert.True(t, strings.Contains(jsonStr, "operation")) - assert.True(t, strings.Contains(jsonStr, "process")) - - assert.True(t, strings.Contains(jsonStr, "system")) - assert.True(t, strings.Contains(jsonStr, "AmazonSQS")) - assert.True(t, strings.Contains(jsonStr, "annotations")) - assert.True(t, strings.Contains(jsonStr, "messaging_system")) -} diff --git a/exporter/awsxrayexporter/internal/translator/segment.go b/exporter/awsxrayexporter/internal/translator/segment.go index 721e6ea93bfe..3438e412f7bd 100644 --- a/exporter/awsxrayexporter/internal/translator/segment.go +++ b/exporter/awsxrayexporter/internal/translator/segment.go @@ -105,8 +105,7 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str awsfiltered, aws = makeAws(causefiltered, resource, logGroupNames) service = makeService(resource) sqlfiltered, sql = makeSQL(span, awsfiltered) - messagingFiltered, messaging = makeMessaging(sqlfiltered) - additionalAttrs = addSpecialAttributes(messagingFiltered, indexedAttrs, attributes) + additionalAttrs = addSpecialAttributes(sqlfiltered, indexedAttrs, attributes) user, annotations, metadata = makeXRayAttributes(additionalAttrs, resource, storeResource, indexedAttrs, indexAllAttrs) spanLinks, makeSpanLinkErr = makeSpanLinks(span.Links()) name string @@ -228,7 +227,6 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str Metadata: metadata, Type: awsxray.String(segmentType), Links: spanLinks, - Messaging: messaging, }, nil } diff --git a/internal/aws/xray/tracesegment.go b/internal/aws/xray/tracesegment.go index 7cebb9233e31..f33552ce7622 100644 --- a/internal/aws/xray/tracesegment.go +++ b/internal/aws/xray/tracesegment.go @@ -29,12 +29,11 @@ type Segment struct { StartTime *float64 `json:"start_time"` // Segment-only optional fields - Service *ServiceData `json:"service,omitempty"` - Origin *string `json:"origin,omitempty"` - User *string `json:"user,omitempty"` - ResourceARN *string `json:"resource_arn,omitempty"` - Links []SpanLinkData `json:"links,omitempty"` - Messaging map[string]interface{} `json:"messaging,omitempty"` + Service *ServiceData `json:"service,omitempty"` + Origin *string `json:"origin,omitempty"` + User *string `json:"user,omitempty"` + ResourceARN *string `json:"resource_arn,omitempty"` + Links []SpanLinkData `json:"links,omitempty"` // Optional fields for both Segment and subsegments TraceID *string `json:"trace_id,omitempty"` From 4300b77f154f685e1434c27d0b96e5d0993666e1 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Thu, 15 Jun 2023 15:43:53 -0700 Subject: [PATCH 17/18] Empty commit to re-run linter From efa6da28ffcd964c26f655a39f2c34978a3e8203 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Thu, 15 Jun 2023 16:35:44 -0700 Subject: [PATCH 18/18] Fixing case --- .../internal/translator/{spanLinks.go => span_links.go} | 0 .../internal/translator/{spanLinks_test.go => span_links_test.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename exporter/awsxrayexporter/internal/translator/{spanLinks.go => span_links.go} (100%) rename exporter/awsxrayexporter/internal/translator/{spanLinks_test.go => span_links_test.go} (100%) diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks.go b/exporter/awsxrayexporter/internal/translator/span_links.go similarity index 100% rename from exporter/awsxrayexporter/internal/translator/spanLinks.go rename to exporter/awsxrayexporter/internal/translator/span_links.go diff --git a/exporter/awsxrayexporter/internal/translator/spanLinks_test.go b/exporter/awsxrayexporter/internal/translator/span_links_test.go similarity index 100% rename from exporter/awsxrayexporter/internal/translator/spanLinks_test.go rename to exporter/awsxrayexporter/internal/translator/span_links_test.go