Skip to content

Commit

Permalink
Addressing PR and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
atshaw43 committed Oct 8, 2023
1 parent ddf9294 commit b79a0e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
23 changes: 15 additions & 8 deletions exporter/awsxrayexporter/internal/translator/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -237,6 +242,8 @@ func MakeNonLocalRootSegment(span ptrace.Span, resource pcommon.Resource, indexe
return nil, err
}

addNamespaceToSpansWithRemoteService(span, segment)

return []*awsxray.Segment{segment}, nil
}

Expand Down
11 changes: 8 additions & 3 deletions exporter/awsxrayexporter/internal/translator/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{} {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand Down

0 comments on commit b79a0e7

Please sign in to comment.