From ee847deac28998226ec0b542268aee57ebe634cd Mon Sep 17 00:00:00 2001 From: Thomas Pierce Date: Thu, 12 Oct 2023 09:48:47 -0700 Subject: [PATCH] Update segment conversion logic (#115) In this commit, we are fixing a couple small bugs missed in the previous review. First, we are adding a nil-guard when settting dependencySubsegment.Name, to avoid the (unlikely, but possible) scenario where local root dependency spans are created without awsRemoteService. Second, we are updating the common logic for setting segment.Name, which previously only looked at CLIENT/PRODUCER spans, but now needs to look at CONSUMER spans. --- exporter/awsxrayexporter/internal/translator/segment.go | 8 ++++---- .../awsxrayexporter/internal/translator/segment_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/segment.go b/exporter/awsxrayexporter/internal/translator/segment.go index 21470e0e0dbd..682b83444979 100644 --- a/exporter/awsxrayexporter/internal/translator/segment.go +++ b/exporter/awsxrayexporter/internal/translator/segment.go @@ -152,9 +152,9 @@ func MakeDependencySubsegmentForLocalRootDependencySpan(span ptrace.Span, resour dependencySubsegment.Links = nil } - myAwsRemoteService, _ := span.Attributes().Get(awsRemoteService) - - dependencySubsegment.Name = awsxray.String(myAwsRemoteService.Str()) + if myAwsRemoteService, ok := span.Attributes().Get(awsRemoteService); ok { + dependencySubsegment.Name = awsxray.String(myAwsRemoteService.Str()) + } return dependencySubsegment, err } @@ -356,7 +356,7 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str } } - if span.Kind() == ptrace.SpanKindClient || span.Kind() == ptrace.SpanKindProducer { + if span.Kind() == ptrace.SpanKindClient || span.Kind() == ptrace.SpanKindProducer || span.Kind() == ptrace.SpanKindConsumer { if remoteServiceName, ok := attributes.Get(awsRemoteService); ok { name = remoteServiceName.Str() } diff --git a/exporter/awsxrayexporter/internal/translator/segment_test.go b/exporter/awsxrayexporter/internal/translator/segment_test.go index a9ca076c3659..4c5e5b470951 100644 --- a/exporter/awsxrayexporter/internal/translator/segment_test.go +++ b/exporter/awsxrayexporter/internal/translator/segment_test.go @@ -1464,7 +1464,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, "MyService", *segments[0].Name) + assert.Equal(t, "myRemoteService", *segments[0].Name) } func TestNotLocalRootClient(t *testing.T) {