diff --git a/exporter/awsxrayexporter/internal/translator/segment.go b/exporter/awsxrayexporter/internal/translator/segment.go index af3b798c61e1..9e9222e1ec0d 100644 --- a/exporter/awsxrayexporter/internal/translator/segment.go +++ b/exporter/awsxrayexporter/internal/translator/segment.go @@ -116,6 +116,18 @@ func isLocalRoot(span ptrace.Span) bool { return false } +func addNamespaceToSpansWithRemoteService(span ptrace.Span, segment *awsxray.Segment) { + // We need to at least cover the + if (span.Kind() == ptrace.SpanKindClient || + span.Kind() == ptrace.SpanKindConsumer || + span.Kind() == ptrace.SpanKindProducer) && + segment.Namespace == nil { + if _, ok := span.Attributes().Get(awsRemoteService); ok { + segment.Namespace = awsxray.String("remote") + } + } +} + func MakeDependencySubsegmentForLocalRootDependencySpan(span ptrace.Span, resource pcommon.Resource, indexedAttrs []string, indexAllAttrs bool, logGroupNames []string, skipTimestampValidation bool, serviceSegmentID pcommon.SpanID) (*awsxray.Segment, error) { var dependencySpan = ptrace.NewSpan() span.CopyTo(dependencySpan) @@ -136,14 +148,7 @@ func MakeDependencySubsegmentForLocalRootDependencySpan(span ptrace.Span, resour // Make this a subsegment dependencySubsegment.Type = awsxray.String("subsegment") - if (span.Kind() == ptrace.SpanKindClient || - span.Kind() == ptrace.SpanKindConsumer || - span.Kind() == ptrace.SpanKindProducer) && - dependencySubsegment.Namespace == nil { - if _, ok := span.Attributes().Get(awsRemoteService); ok { - dependencySubsegment.Namespace = awsxray.String("remote") - } - } + addNamespaceToSpansWithRemoteService(span, dependencySubsegment) // Remove span links from consumer spans if span.Kind() == ptrace.SpanKindConsumer { @@ -237,6 +242,8 @@ func MakeNonLocalRootSegment(span ptrace.Span, resource pcommon.Resource, indexe return nil, err } + addNamespaceToSpansWithRemoteService(span, segment) + return []*awsxray.Segment{segment}, nil } diff --git a/exporter/awsxrayexporter/internal/translator/segment_test.go b/exporter/awsxrayexporter/internal/translator/segment_test.go index 36d7bc1d08a6..c2144d049531 100644 --- a/exporter/awsxrayexporter/internal/translator/segment_test.go +++ b/exporter/awsxrayexporter/internal/translator/segment_test.go @@ -1033,7 +1033,7 @@ func TestConsumerSpanWithAwsRemoteServiceName(t *testing.T) { attributes[awsRemoteService] = "ConsumerService" resource := constructDefaultResource() - span := constructConsumerSpan(parentSpanID, spanName, 0, "OK", attributes) + span := constructConsumerSpan(parentSpanID, spanName, 0, "Ok", attributes) segment, _ := MakeSegment(span, resource, nil, false, nil, false) assert.Equal(t, "ConsumerService", *segment.Name) @@ -1137,6 +1137,8 @@ func validateLocalRootServiceSegment(t *testing.T, segment *awsxray.Segment, spa assert.Nil(t, segment.AWS.QueueURL) assert.Nil(t, segment.AWS.TableName) assert.Nil(t, segment.Namespace) + + assert.Nil(t, segment.Namespace) } func getBasicAttributes() map[string]interface{} { @@ -1318,7 +1320,7 @@ func TestLocalRootProducer(t *testing.T) { attributes := getBasicAttributes() - span := constructProducerSpan(parentSpanID, spanName, 200, "OK", attributes) + span := constructProducerSpan(parentSpanID, spanName, 200, "Ok", attributes) addSpanLink(span) @@ -1469,7 +1471,7 @@ func TestNotLocalRootConsumer(t *testing.T) { // Validate segment assert.Equal(t, "subsegment", *segments[0].Type) - //assert.Equal(t, "remote", *segments[0].Namespace) + assert.Equal(t, "remote", *segments[0].Namespace) assert.Equal(t, "myRemoteService", *segments[0].Name) } @@ -1493,6 +1495,7 @@ func TestNotLocalRootClient(t *testing.T) { // Validate segment assert.Equal(t, "subsegment", *segments[0].Type) + assert.Equal(t, "remote", *segments[0].Namespace) assert.Equal(t, "myRemoteService", *segments[0].Name) } @@ -1516,6 +1519,7 @@ func TestNotLocalRootProducer(t *testing.T) { // Validate segment assert.Equal(t, "subsegment", *segments[0].Type) + assert.Equal(t, "remote", *segments[0].Namespace) assert.Equal(t, "myRemoteService", *segments[0].Name) } @@ -1541,6 +1545,7 @@ func TestNotLocalRootServer(t *testing.T) { // Validate segment assert.Nil(t, segments[0].Type) + assert.Nil(t, segments[0].Namespace) assert.Equal(t, "myLocalService", *segments[0].Name) }