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

otelaws: adding dynamodb attributes #1582

Merged
merged 16 commits into from Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -32,7 +32,7 @@ const (
)

var servicemap map[string]AttributeSetter = map[string]AttributeSetter{
"dynamodb": DynamodbAttributeSetter,
"dynamodb": DynamoDBAttributeSetter,
}

func OperationAttr(operation string) attribute.KeyValue {
Expand All @@ -51,6 +51,8 @@ func RequestIDAttr(requestID string) attribute.KeyValue {
return RequestIDKey.String(requestID)
}

// DefaultAttributeSetter checks to see if there are service specific attributes available to set for the aws service.
jennynilsen marked this conversation as resolved.
Show resolved Hide resolved
// If there are service specific attributes available then they will be included.
func DefaultAttributeSetter(ctx context.Context, in middleware.InitializeInput) []attribute.KeyValue {
MrAlias marked this conversation as resolved.
Show resolved Hide resolved

serviceID := v2Middleware.GetServiceID(ctx)
Expand Down
5 changes: 3 additions & 2 deletions instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go
Expand Up @@ -35,6 +35,7 @@ const (

type spanTimestampKey struct{}

// AttributeSetter returns an array of KeyValue pairs, it can be used to set custom attributes.
type AttributeSetter func(context.Context, middleware.InitializeInput) []attribute.KeyValue
MrAlias marked this conversation as resolved.
Show resolved Hide resolved

type otelMiddlewares struct {
Expand Down Expand Up @@ -65,7 +66,7 @@ func (m otelMiddlewares) initializeMiddlewareAfter(stack *middleware.Stack) erro
RegionAttr(v2Middleware.GetRegion(ctx)),
OperationAttr(v2Middleware.GetOperationName(ctx)),
}
for _, setter := range m.attributesetter {
for _, setter := range m.attributeSetter {
attributes = append(attributes, setter(ctx, in)...)
}

Expand Down Expand Up @@ -128,7 +129,7 @@ func AppendMiddlewares(apiOptions *[]func(*middleware.Stack) error, opts ...Opti

m := otelMiddlewares{tracer: cfg.TracerProvider.Tracer(tracerName,
trace.WithInstrumentationVersion(SemVersion())),
attributesetter: cfg.AttributeSetter}
attributeSetter: cfg.AttributeSetter}
*apiOptions = append(*apiOptions, m.initializeMiddlewareBefore, m.initializeMiddlewareAfter, m.deserializeMiddleware)

}
Expand Up @@ -25,14 +25,10 @@ import (
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
)

// DynamoDBAttributeSetter sets DynamoDB specific attributes depending on the the DynamoDB operation being performed.
func DynamoDBAttributeSetter(ctx context.Context, in middleware.InitializeInput) []attribute.KeyValue {

dynamodbAttributes := []attribute.KeyValue{
{
Key: semconv.DBSystemKey,
Value: attribute.StringValue("dynamodb"),
},
}
dynamodbAttributes := []attribute.KeyValue{semconv.DBSystemKey.String("dynamodb")}

switch v := in.Parameters.(type) {
case *dynamodb.GetItemInput:
Expand Down
Expand Up @@ -41,7 +41,7 @@ func TestDynamodbTagsBatchGetItemInput(t *testing.T) {
},
}

attributes := DynamodbAttributeSetter(context.TODO(), input)
attributes := DynamoDBAttributeSetter(context.TODO(), input)

assert.Contains(t, attributes, attribute.StringSlice("aws.dynamodb.table_names", []string{"table1"}))
}
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestDynamodbTagsBatchWriteItemInput(t *testing.T) {
},
}

attributes := DynamodbAttributeSetter(context.TODO(), input)
attributes := DynamoDBAttributeSetter(context.TODO(), input)

assert.Contains(t, attributes, attribute.StringSlice("aws.dynamodb.table_names", []string{"table1"}))
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestDynamodbTagsCreateTableInput(t *testing.T) {
},
}

attributes := DynamodbAttributeSetter(context.TODO(), input)
attributes := DynamoDBAttributeSetter(context.TODO(), input)

assert.Contains(t, attributes, attribute.String("aws.dynamodb.table_names", "table1"))
assert.Contains(t, attributes, attribute.String("aws.dynamodb.global_secondary_indexes", "[{\"IndexName\":\"index1\",\"KeySchema\":[{\"AttributeName\":\"attributename\",\"KeyType\":\"HASH\"}],\"Projection\":{\"NonKeyAttributes\":[\"non-key-attributes\"],\"ProjectionType\":\"\"},\"ProvisionedThroughput\":null}]"))
Expand All @@ -142,7 +142,7 @@ func TestDynamodbTagsDeleteItemInput(t *testing.T) {
TableName: aws.String("table1"),
},
}
attributes := DynamodbAttributeSetter(context.TODO(), input)
attributes := DynamoDBAttributeSetter(context.TODO(), input)

assert.Contains(t, attributes, attribute.String("aws.dynamodb.table_names", "table1"))
}
Expand All @@ -153,7 +153,7 @@ func TestDynamodbTagsDeleteTableInput(t *testing.T) {
TableName: aws.String("table1"),
},
}
attributes := DynamodbAttributeSetter(context.TODO(), input)
attributes := DynamoDBAttributeSetter(context.TODO(), input)

assert.Contains(t, attributes, attribute.String("aws.dynamodb.table_names", "table1"))

Expand All @@ -165,7 +165,7 @@ func TestDynamodbTagsDescribeTableInput(t *testing.T) {
TableName: aws.String("table1"),
},
}
attributes := DynamodbAttributeSetter(context.TODO(), input)
attributes := DynamoDBAttributeSetter(context.TODO(), input)

assert.Contains(t, attributes, attribute.String("aws.dynamodb.table_names", "table1"))
}
Expand All @@ -177,7 +177,7 @@ func TestDynamodbTagsListTablesInput(t *testing.T) {
Limit: aws.Int32(10),
},
}
attributes := DynamodbAttributeSetter(context.TODO(), input)
attributes := DynamoDBAttributeSetter(context.TODO(), input)

assert.Contains(t, attributes, attribute.String("aws.dynamodb.exclusive_start_table", "table1"))
assert.Contains(t, attributes, attribute.Int("aws.dynamodb.limit", 10))
Expand All @@ -196,7 +196,7 @@ func TestDynamodbTagsPutItemInput(t *testing.T) {
},
}

attributes := DynamodbAttributeSetter(context.TODO(), input)
attributes := DynamoDBAttributeSetter(context.TODO(), input)

assert.Contains(t, attributes, attribute.String("aws.dynamodb.table_names", "table1"))
}
Expand All @@ -222,7 +222,7 @@ func TestDynamodbTagsQueryInput(t *testing.T) {
},
}

attributes := DynamodbAttributeSetter(context.TODO(), input)
attributes := DynamoDBAttributeSetter(context.TODO(), input)

assert.Contains(t, attributes, attribute.String("aws.dynamodb.table_names", "table1"))
assert.Contains(t, attributes, attribute.Bool("aws.dynamodb.consistent_read", true))
Expand All @@ -248,7 +248,7 @@ func TestDynamodbTagsScanInput(t *testing.T) {
},
}

attributes := DynamodbAttributeSetter(context.TODO(), input)
attributes := DynamoDBAttributeSetter(context.TODO(), input)

assert.Contains(t, attributes, attribute.String("aws.dynamodb.table_names", "my-table"))
assert.Contains(t, attributes, attribute.Bool("aws.dynamodb.consistent_read", true))
Expand All @@ -275,7 +275,7 @@ func TestDynamodbTagsUpdateItemInput(t *testing.T) {
},
}

attributes := DynamodbAttributeSetter(context.TODO(), input)
attributes := DynamoDBAttributeSetter(context.TODO(), input)

assert.Contains(t, attributes, attribute.String("aws.dynamodb.table_names", "my-table"))

Expand Down Expand Up @@ -315,7 +315,7 @@ func TestDynamodbTagsUpdateTableInput(t *testing.T) {
},
}

attributes := DynamodbAttributeSetter(context.TODO(), input)
attributes := DynamoDBAttributeSetter(context.TODO(), input)

assert.Contains(t, attributes, attribute.String("aws.dynamodb.table_names", "my-table"))
assert.Contains(t, attributes, attribute.String("aws.dynamodb.attribute_definitions", "[{\"AttributeName\":\"id\",\"AttributeType\":\"S\"}]"))
Expand Down
Expand Up @@ -80,7 +80,7 @@ func TestDynamodbTags(t *testing.T) {
},
}, func(options *dynamodb.Options) {
otelaws.AppendMiddlewares(
&options.APIOptions, otelaws.WithAttributeSetter(otelaws.DynamodbAttributeSetter), otelaws.WithTracerProvider(provider))
&options.APIOptions, otelaws.WithAttributeSetter(otelaws.DynamoDBAttributeSetter), otelaws.WithTracerProvider(provider))
})

if cases.expectedError == codes.Unset {
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestDynamodbTagsCustomSetter(t *testing.T) {
},
}, func(options *dynamodb.Options) {
otelaws.AppendMiddlewares(
&options.APIOptions, otelaws.WithAttributeSetter(otelaws.DynamodbAttributeSetter, mycustomsetter), otelaws.WithTracerProvider(provider))
&options.APIOptions, otelaws.WithAttributeSetter(otelaws.DynamoDBAttributeSetter, mycustomsetter), otelaws.WithTracerProvider(provider))
})

if cases.expectedError == codes.Unset {
Expand Down