Skip to content

Commit 05c3847

Browse files
jennynilsenMrAlias
andauthored
Apply suggestions from code review
Co-authored-by: Tyler Yahn <[email protected]>
1 parent ba6e751 commit 05c3847

File tree

5 files changed

+10
-25
lines changed

5 files changed

+10
-25
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
99
## [Unreleased]
1010

1111
### Added
12-
- Dynamodb spans will now have the appropriate attributes added for the operation being performed, this is detected automatically but it is also now possible to provide a custom function to set attributes using `WithAttributeSetter`
12+
13+
- Dynamodb spans created with the `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/` package will now have the appropriate database attributes added for the operation being performed.
14+
These attributes are detected automatically, but it is also now possible to provide a custom function to set attributes using `WithAttributeSetter`. (#1582)
1315

1416
- Add `WithClientTrace` option to `otelhttp.Transport` (#875)
1517

instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type AttributeSetter func(context.Context, middleware.InitializeInput) []attribu
3939

4040
type otelMiddlewares struct {
4141
tracer trace.Tracer
42-
attributesetter []AttributeSetter
42+
attributeSetter []AttributeSetter
4343
}
4444

4545
func (m otelMiddlewares) initializeMiddlewareBefore(stack *middleware.Stack) error {
@@ -60,7 +60,8 @@ func (m otelMiddlewares) initializeMiddlewareAfter(stack *middleware.Stack) erro
6060

6161
serviceID := v2Middleware.GetServiceID(ctx)
6262

63-
attributes := []attribute.KeyValue{ServiceAttr(serviceID),
63+
attributes := []attribute.KeyValue{
64+
ServiceAttr(serviceID),
6465
RegionAttr(v2Middleware.GetRegion(ctx)),
6566
OperationAttr(v2Middleware.GetOperationName(ctx)),
6667
}

instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/config.go

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func WithTracerProvider(provider trace.TracerProvider) Option {
4949
// WithAttributeSetter specifies an attribute setter function for setting service specific attributes.
5050
// If none is specified, the service will be determined by the DefaultAttributeSetter function and the corresponding attributes will be included.
5151
func WithAttributeSetter(attributesetters ...AttributeSetter) Option {
52-
5352
return optionFunc(func(cfg *config) {
5453
if len(attributesetters) > 0 {
5554
cfg.AttributeSetter = append(cfg.AttributeSetter, attributesetters...)

instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/dynamodbattributes.go

+3-20
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
2626
)
2727

28-
func DynamodbAttributeSetter(ctx context.Context, in middleware.InitializeInput) []attribute.KeyValue {
28+
func DynamoDBAttributeSetter(ctx context.Context, in middleware.InitializeInput) []attribute.KeyValue {
2929

3030
dynamodbAttributes := []attribute.KeyValue{
3131
{
@@ -47,14 +47,7 @@ func DynamodbAttributeSetter(ctx context.Context, in middleware.InitializeInput)
4747
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBProjectionKey.String(*v.ProjectionExpression))
4848
}
4949

50-
case *dynamodb.BatchGetItemInput:
51-
var tableNames []string
52-
for k, _ := range v.RequestItems {
53-
tableNames = append(tableNames, k)
54-
}
55-
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.StringSlice(tableNames))
56-
57-
case *dynamodb.BatchWriteItemInput:
50+
case *dynamodb.BatchGetItemInput, *dynamodb.BatchWriteItemInput:
5851
var tableNames []string
5952
for k, _ := range v.RequestItems {
6053
tableNames = append(tableNames, k)
@@ -79,13 +72,7 @@ func DynamodbAttributeSetter(ctx context.Context, in middleware.InitializeInput)
7972
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBProvisionedWriteCapacityKey.Int64(*v.ProvisionedThroughput.WriteCapacityUnits))
8073
}
8174

82-
case *dynamodb.DeleteItemInput:
83-
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName))
84-
85-
case *dynamodb.DeleteTableInput:
86-
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName))
87-
88-
case *dynamodb.DescribeTableInput:
75+
case *dynamodb.DeleteItemInput, *dynamodb.DeleteTableInput, *dynamodb.DescribeTableInput, *dynamodb.PutItemInput:
8976
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName))
9077

9178
case *dynamodb.ListTablesInput:
@@ -98,10 +85,6 @@ func DynamodbAttributeSetter(ctx context.Context, in middleware.InitializeInput)
9885
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBLimitKey.Int(int(*v.Limit)))
9986
}
10087

101-
case *dynamodb.PutItemInput:
102-
103-
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName))
104-
10588
case *dynamodb.QueryInput:
10689

10790
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName))

instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/dynamodbattributes_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"go.opentelemetry.io/otel/attribute"
2727
)
2828

29-
func TestDynamodbTagsBatchGetItemInput(t *testing.T) {
29+
func TestDynamoDBTagsBatchGetItemInput(t *testing.T) {
3030
input := middleware.InitializeInput{
3131
Parameters: &dynamodb.BatchGetItemInput{
3232
RequestItems: map[string]dtypes.KeysAndAttributes{

0 commit comments

Comments
 (0)