Repository: open-telemetry/opentelemetry-go-contrib
Pull request #3617 (2023-03-21 13:31:13)

Sync aws sdk attributes with semantic conventions
Solves #3521 for DynamoDB and AWS SDK.

Making AWS SDK attributes consistent with RPC clients:

1 Rename "aws.operation" attribute to "rpc.method"
2 Rename "aws.service" attribute to "rpc.service"
3 Add "rpc.system" attribute and set it to "aws-api" value

According to [semconv](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/instrumentation/aws-sdk.md)

codecov[bot]: ## [Codecov](https://codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/3617?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) Report
> Merging [#3617](https://codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/3617?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) (9727329) into [main](https://codecov.io/gh/open-telemetry/opentelemetry-go-contrib/commit/83b942ad88a86e3a3d0c92579122597854d2f2ff?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) (83b942a) will **increase** coverage by `0.0%`.
> The diff coverage is `100.0%`.

> :exclamation: Current head 9727329 differs from pull request most recent head 7a3577d. Consider uploading reports for the commit 7a3577d to get more accurate results

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/3617/graphs/tree.svg?width=650&height=150&src=pr&token=P6F3W9WA7Q&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)](https://codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/3617?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)

```diff
@@          Coverage Diff          @@
##            main   #3617   +/-   ##
=====================================
  Coverage   70.0%   70.0%           
=====================================
  Files        147     147           
  Lines       6956    6959    +3     
=====================================
+ Hits        4870    4876    +6     
+ Misses      1961    1959    -2     
+ Partials     125     124    -1     
```


| [Impacted Files](https://codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/3617?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | Coverage Δ | |
|---|---|---|
| [...github.com/aws/aws-sdk-go-v2/otelaws/attributes.go](https://codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/3617?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-aW5zdHJ1bWVudGF0aW9uL2dpdGh1Yi5jb20vYXdzL2F3cy1zZGstZ28tdjIvb3RlbGF3cy9hdHRyaWJ1dGVzLmdv) | `82.3% <100.0%> (+2.3%)` | :arrow_up: |
| [...tation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go](https://codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/3617?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-aW5zdHJ1bWVudGF0aW9uL2dpdGh1Yi5jb20vYXdzL2F3cy1zZGstZ28tdjIvb3RlbGF3cy9hd3MuZ28=) | `94.2% <100.0%> (+<0.1%)` | :arrow_up: |

... and [1 file with indirect coverage changes](https://codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/3617/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)

</details>

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0e7903315..59a346498 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
@@ -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)
 
diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes.go b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes.go
index 29dc8b4ca..bfe74ca6b 100644
--- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes.go
+++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes.go
@@ -23,14 +23,14 @@ 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{
@@ -38,9 +38,14 @@ var servicemap = map[string]AttributeSetter{
 	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.
@@ -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.
diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go
index 4bb01253b..021baec23 100644
--- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go
+++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go
@@ -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),


Test patch:
diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes_test.go b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes_test.go
index 8696583d8..455be3d9a 100644
--- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes_test.go
+++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes_test.go
@@ -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)
 }
 
 func TestRegionAttr(t *testing.T) {
@@ -37,7 +38,7 @@ 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) {
@@ -45,3 +46,8 @@ func TestRequestIDAttr(t *testing.T) {
 	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)
+}
diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/aws_test.go b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/aws_test.go
index 382e607e6..0bc18e60c 100644
--- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/aws_test.go
+++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/aws_test.go
@@ -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()
diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/dynamodbattributes_test.go b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/dynamodbattributes_test.go
index 7660499e7..10911eed9 100644
--- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/dynamodbattributes_test.go
+++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/dynamodbattributes_test.go
@@ -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"},
 		))
@@ -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"},
 		))