Skip to content

Commit

Permalink
rpc.system has priority to determine aws namespace in awsxrayexporter (
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanielRN authored Oct 20, 2021
1 parent 7c9f65b commit 99c1c32
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
12 changes: 11 additions & 1 deletion exporter/awsxrayexporter/internal/translator/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,23 @@ func MakeSegment(span pdata.Span, resource pdata.Resource, indexedAttrs []string
name = peerService.StringVal()
}

if namespace == "" {
if rpcSystem, ok := attributes.Get(conventions.AttributeRPCSystem); ok {
if rpcSystem.StringVal() == "aws-api" {
namespace = conventions.AttributeCloudProviderAWS
}
}
}

if name == "" {
if awsService, ok := attributes.Get(awsxray.AWSServiceAttribute); ok {
// Generally spans are named something like "Method" or "Service.Method" but for AWS spans, X-Ray expects spans
// to be named "Service"
name = awsService.StringVal()

namespace = "aws"
if namespace == "" {
namespace = conventions.AttributeCloudProviderAWS
}
}
}

Expand Down
35 changes: 33 additions & 2 deletions exporter/awsxrayexporter/internal/translator/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,38 @@ var (
testWriters = newWriterPool(2048)
)

func TestClientSpanWithAwsSdkClient(t *testing.T) {
func TestClientSpanWithRpcAwsSdkClientAttributes(t *testing.T) {
spanName := "AmazonDynamoDB.getItem"
parentSpanID := newSegmentID()
user := "testingT"
attributes := make(map[string]interface{})
attributes[conventions.AttributeHTTPMethod] = "POST"
attributes[conventions.AttributeHTTPScheme] = "https"
attributes[conventions.AttributeHTTPHost] = "dynamodb.us-east-1.amazonaws.com"
attributes[conventions.AttributeHTTPTarget] = "/"
attributes[conventions.AttributeRPCService] = "DynamoDB"
attributes[conventions.AttributeRPCMethod] = "GetItem"
attributes[conventions.AttributeRPCSystem] = "aws-api"
attributes[awsxray.AWSRequestIDAttribute] = "18BO1FEPJSSAOGNJEDPTPCMIU7VV4KQNSO5AEMVJF66Q9ASUAAJG"
attributes[awsxray.AWSTableNameAttribute] = "otel-dev-Testing"
resource := constructDefaultResource()
span := constructClientSpan(parentSpanID, spanName, 0, "OK", attributes)

segment, _ := MakeSegment(span, resource, nil, false)
assert.Equal(t, "DynamoDB", *segment.Name)
assert.Equal(t, conventions.AttributeCloudProviderAWS, *segment.Namespace)
assert.Equal(t, "subsegment", *segment.Type)

jsonStr, err := MakeSegmentDocumentString(span, resource, nil, false)

assert.NotNil(t, jsonStr)
assert.Nil(t, err)
assert.True(t, strings.Contains(jsonStr, "DynamoDB"))
assert.False(t, strings.Contains(jsonStr, user))
assert.False(t, strings.Contains(jsonStr, "user"))
}

func TestClientSpanWithLegacyAwsSdkClientAttributes(t *testing.T) {
spanName := "AmazonDynamoDB.getItem"
parentSpanID := newSegmentID()
user := "testingT"
Expand All @@ -60,7 +91,7 @@ func TestClientSpanWithAwsSdkClient(t *testing.T) {

segment, _ := MakeSegment(span, resource, nil, false)
assert.Equal(t, "DynamoDB", *segment.Name)
assert.Equal(t, "aws", *segment.Namespace)
assert.Equal(t, conventions.AttributeCloudProviderAWS, *segment.Namespace)
assert.Equal(t, "subsegment", *segment.Type)

jsonStr, err := MakeSegmentDocumentString(span, resource, nil, false)
Expand Down

0 comments on commit 99c1c32

Please sign in to comment.