Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync aws sdk attributes with semantic conventions #3617

Merged
merged 13 commits into from
Mar 28, 2023
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Added

- AWS SDK add `rpc.system` attribute in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`. (#3582, #3617)
- Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108)

## [1.16.0-rc.2/0.41.0-rc.2/0.10.0-rc.2] - 2023-03-23
Expand All @@ -20,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Fixed

- AWS SDK rename attributes `aws.operation`, `aws.service` to `rpc.method`,`rpc.service` in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`. (#3582, #3617)
- AWS SDK span name to be of the format `Service.Operation` in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`. (#3582, #3521)
- Prevent sampler configuration reset from erroneously sampling first span in `go.opentelemetry.io/contrib/samplers/jaegerremote`. (#3603, #3604)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,29 @@ import (
"github.com/aws/smithy-go/middleware"

"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
)

// AWS attributes.
const (
OperationKey attribute.Key = "aws.operation"
RegionKey attribute.Key = "aws.region"
ServiceKey attribute.Key = "aws.service"
RequestIDKey attribute.Key = "aws.request_id"
AWSSystemVal string = "aws-api"
)

var servicemap = map[string]AttributeSetter{
dynamodb.ServiceID: DynamoDBAttributeSetter,
sqs.ServiceID: SQSAttributeSetter,
}

// SystemAttr return the AWS RPC system attribute.
func SystemAttr() attribute.KeyValue {
return semconv.RPCSystemKey.String(AWSSystemVal)
}

// OperationAttr returns the AWS operation attribute.
func OperationAttr(operation string) attribute.KeyValue {
return OperationKey.String(operation)
return semconv.RPCMethod(operation)
}

// RegionAttr returns the AWS region attribute.
Expand All @@ -50,7 +55,7 @@ func RegionAttr(region string) attribute.KeyValue {

// ServiceAttr returns the AWS service attribute.
func ServiceAttr(service string) attribute.KeyValue {
return ServiceKey.String(service)
return semconv.RPCService(service)
}

// RequestIDAttr returns the AWS request ID attribute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (
"github.com/stretchr/testify/assert"

"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
)

func TestOperationAttr(t *testing.T) {
operation := "test-operation"
attr := OperationAttr(operation)
assert.Equal(t, attribute.String("aws.operation", operation), attr)
assert.Equal(t, attribute.String("rpc.method", operation), attr)
dmathieu marked this conversation as resolved.
Show resolved Hide resolved
}

func TestRegionAttr(t *testing.T) {
Expand All @@ -37,11 +38,16 @@ func TestRegionAttr(t *testing.T) {
func TestServiceAttr(t *testing.T) {
service := "test-service"
attr := ServiceAttr(service)
assert.Equal(t, attribute.String("aws.service", service), attr)
assert.Equal(t, semconv.RPCService(service), attr)
}

func TestRequestIDAttr(t *testing.T) {
requestID := "test-request-id"
attr := RequestIDAttr(requestID)
assert.Equal(t, attribute.String("aws.request_id", requestID), attr)
}

func TestSystemAttribute(t *testing.T) {
attr := SystemAttr()
assert.Equal(t, semconv.RPCSystemKey.String("aws-api"), attr)
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (m otelMiddlewares) initializeMiddlewareAfter(stack *middleware.Stack) erro
region := v2Middleware.GetRegion(ctx)

attributes := []attribute.KeyValue{
SystemAttr(),
ServiceAttr(serviceID),
RegionAttr(region),
OperationAttr(operation),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ func TestAppendMiddlewares(t *testing.T) {
if c.expectedRequestID != "" {
assert.Contains(t, attrs, attribute.String("aws.request_id", c.expectedRequestID))
}
assert.Contains(t, attrs, attribute.String("aws.service", "Route 53"))
assert.Contains(t, attrs, attribute.String("rpc.system", "aws-api"))
assert.Contains(t, attrs, attribute.String("rpc.service", "Route 53"))
assert.Contains(t, attrs, attribute.String("aws.region", c.expectedRegion))
assert.Contains(t, attrs, attribute.String("aws.operation", "ChangeResourceRecordSets"))
assert.Contains(t, attrs, attribute.String("rpc.method", "ChangeResourceRecordSets"))
})

srv.Close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ func TestDynamodbTags(t *testing.T) {
assert.Equal(t, trace.SpanKindClient, span.SpanKind())
attrs := span.Attributes()
assert.Contains(t, attrs, attribute.Int("http.status_code", cases.expectedStatusCode))
assert.Contains(t, attrs, attribute.String("aws.service", "DynamoDB"))
assert.Contains(t, attrs, attribute.String("rpc.service", "DynamoDB"))
assert.Contains(t, attrs, attribute.String("aws.region", cases.expectedRegion))
assert.Contains(t, attrs, attribute.String("aws.operation", "GetItem"))
assert.Contains(t, attrs, attribute.String("rpc.method", "GetItem"))
assert.Contains(t, attrs, attribute.String("rpc.system", "aws-api"))
assert.Contains(t, attrs, attribute.StringSlice(
"aws.dynamodb.table_names", []string{"table1"},
))
Expand Down Expand Up @@ -186,9 +187,9 @@ func TestDynamodbTagsCustomSetter(t *testing.T) {
assert.Equal(t, trace.SpanKindClient, span.SpanKind())
attrs := span.Attributes()
assert.Contains(t, attrs, attribute.Int("http.status_code", cases.expectedStatusCode))
assert.Contains(t, attrs, attribute.String("aws.service", "DynamoDB"))
assert.Contains(t, attrs, attribute.String("rpc.service", "DynamoDB"))
assert.Contains(t, attrs, attribute.String("aws.region", cases.expectedRegion))
assert.Contains(t, attrs, attribute.String("aws.operation", "GetItem"))
assert.Contains(t, attrs, attribute.String("rpc.method", "GetItem"))
assert.Contains(t, attrs, attribute.StringSlice(
"aws.dynamodb.table_names", []string{"table1"},
))
Expand Down