Skip to content

Commit

Permalink
Update segment conversion logic (amazon-contributing#115)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thpierce authored and lisguo committed Oct 20, 2023
1 parent 8054715 commit 514b01d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions exporter/awsxrayexporter/internal/translator/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 514b01d

Please sign in to comment.