Skip to content

Commit

Permalink
Fallback to rpc.method for segment operation when aws.operation is no…
Browse files Browse the repository at this point in the history
…t present
  • Loading branch information
NathanielRN committed Nov 10, 2021
1 parent 0d46bae commit 7d0b686
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion exporter/awsxrayexporter/internal/translator/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,18 @@ func makeAws(attributes map[string]pdata.AttributeValue, resource pdata.Resource
return true
})

if awsOperation, ok := attributes[awsxray.AWSOperationAttribute]; ok {
operation = awsOperation.StringVal()
} else if rpcMethod, ok := attributes[conventions.AttributeRPCMethod]; ok {
operation = rpcMethod.StringVal()
}

for key, value := range attributes {
switch key {
case conventions.AttributeRPCMethod:
// Determinstically handled with if else above
case awsxray.AWSOperationAttribute:
operation = value.StringVal()
// Determinstically handled with if else above
case awsxray.AWSAccountAttribute:
if value.Type() != pdata.AttributeValueTypeEmpty {
account = value.StringVal()
Expand Down
5 changes: 5 additions & 0 deletions exporter/awsxrayexporter/internal/translator/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ func TestClientSpanWithRpcAwsSdkClientAttributes(t *testing.T) {
segment, _ := MakeSegment(span, resource, nil, false)
assert.Equal(t, "DynamoDB", *segment.Name)
assert.Equal(t, conventions.AttributeCloudProviderAWS, *segment.Namespace)
assert.Equal(t, "GetItem", *segment.AWS.Operation)
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.True(t, strings.Contains(jsonStr, "GetItem"))
assert.False(t, strings.Contains(jsonStr, user))
assert.False(t, strings.Contains(jsonStr, "user"))
}
Expand All @@ -83,6 +85,7 @@ func TestClientSpanWithLegacyAwsSdkClientAttributes(t *testing.T) {
attributes[conventions.AttributeHTTPHost] = "dynamodb.us-east-1.amazonaws.com"
attributes[conventions.AttributeHTTPTarget] = "/"
attributes[awsxray.AWSServiceAttribute] = "DynamoDB"
attributes[conventions.AttributeRPCMethod] = "FalseAWSOperationAttribute"
attributes[awsxray.AWSOperationAttribute] = "GetItem"
attributes[awsxray.AWSRequestIDAttribute] = "18BO1FEPJSSAOGNJEDPTPCMIU7VV4KQNSO5AEMVJF66Q9ASUAAJG"
attributes[awsxray.AWSTableNameAttribute] = "otel-dev-Testing"
Expand All @@ -92,13 +95,15 @@ func TestClientSpanWithLegacyAwsSdkClientAttributes(t *testing.T) {
segment, _ := MakeSegment(span, resource, nil, false)
assert.Equal(t, "DynamoDB", *segment.Name)
assert.Equal(t, conventions.AttributeCloudProviderAWS, *segment.Namespace)
assert.Equal(t, "GetItem", *segment.AWS.Operation)
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.True(t, strings.Contains(jsonStr, "GetItem"))
assert.False(t, strings.Contains(jsonStr, user))
assert.False(t, strings.Contains(jsonStr, "user"))
}
Expand Down

0 comments on commit 7d0b686

Please sign in to comment.