-
Notifications
You must be signed in to change notification settings - Fork 669
otelaws: adding dynamodb attributes #1582
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
Merged
Aneurysm9
merged 16 commits into
open-telemetry:main
from
jennynilsen:dynamodb-attributes
Feb 25, 2022
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ff18891
adding dynamodb attributes
jennynilsen 4fc9230
applying suggestions
jennynilsen 4300ac3
allowing users to use the default attribute setter in addition to the…
jennynilsen c74eee9
making setting attributesetters more flexible
jennynilsen ba6e751
fixing conflicts
jennynilsen 05c3847
Apply suggestions from code review
jennynilsen b4851a5
Revert "Apply suggestions from code review"
jennynilsen 1f3aa4c
Apply suggestions from code review
jennynilsen e553bd4
adding comments for exported functions and types
jennynilsen e3e2938
Merge branch 'main' into dynamodb-attributes
Aneurysm9 007cad8
Apply suggestions from code review
jennynilsen f888275
fixing test and applying suggestions
jennynilsen afb65b9
Merge branch 'main' into dynamodb-attributes
MrAlias 329ba3c
Merge branch 'main' into dynamodb-attributes
jennynilsen 7d86f77
fixing checks
jennynilsen 2197014
Merge branch 'main' into dynamodb-attributes
Aneurysm9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/dynamodbattributes.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package otelaws | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/dynamodb" | ||
"github.com/aws/smithy-go/middleware" | ||
|
||
"go.opentelemetry.io/otel/attribute" | ||
semconv "go.opentelemetry.io/otel/semconv/v1.7.0" | ||
) | ||
|
||
func DynamodbAttributeSetter(ctx context.Context, in middleware.InitializeInput) []attribute.KeyValue { | ||
jennynilsen marked this conversation as resolved.
Show resolved
Hide resolved
MrAlias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
dynamodbAttributes := []attribute.KeyValue{ | ||
{ | ||
Key: semconv.DBSystemKey, | ||
Value: attribute.StringValue("dynamodb"), | ||
MrAlias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
} | ||
|
||
switch v := in.Parameters.(type) { | ||
case *dynamodb.GetItemInput: | ||
|
||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName)) | ||
|
||
if v.ConsistentRead != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBConsistentReadKey.Bool(*v.ConsistentRead)) | ||
} | ||
|
||
if v.ProjectionExpression != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBProjectionKey.String(*v.ProjectionExpression)) | ||
} | ||
|
||
case *dynamodb.BatchGetItemInput: | ||
var tableNames []string | ||
for k, _ := range v.RequestItems { | ||
tableNames = append(tableNames, k) | ||
} | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.StringSlice(tableNames)) | ||
|
||
case *dynamodb.BatchWriteItemInput: | ||
MrAlias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var tableNames []string | ||
for k, _ := range v.RequestItems { | ||
tableNames = append(tableNames, k) | ||
} | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.StringSlice(tableNames)) | ||
|
||
case *dynamodb.CreateTableInput: | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName)) | ||
|
||
if v.GlobalSecondaryIndexes != nil { | ||
globalindexes, _ := json.Marshal(v.GlobalSecondaryIndexes) | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBGlobalSecondaryIndexesKey.String(string(globalindexes))) | ||
} | ||
|
||
if v.LocalSecondaryIndexes != nil { | ||
localindexes, _ := json.Marshal(v.LocalSecondaryIndexes) | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBLocalSecondaryIndexesKey.String(string(localindexes))) | ||
} | ||
|
||
if v.ProvisionedThroughput != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBProvisionedReadCapacityKey.Int64(*v.ProvisionedThroughput.ReadCapacityUnits)) | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBProvisionedWriteCapacityKey.Int64(*v.ProvisionedThroughput.WriteCapacityUnits)) | ||
} | ||
|
||
case *dynamodb.DeleteItemInput: | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName)) | ||
|
||
case *dynamodb.DeleteTableInput: | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName)) | ||
|
||
case *dynamodb.DescribeTableInput: | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName)) | ||
|
||
case *dynamodb.ListTablesInput: | ||
|
||
if v.ExclusiveStartTableName != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBExclusiveStartTableKey.String(*v.ExclusiveStartTableName)) | ||
} | ||
|
||
if v.Limit != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBLimitKey.Int(int(*v.Limit))) | ||
} | ||
|
||
case *dynamodb.PutItemInput: | ||
|
||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName)) | ||
MrAlias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
case *dynamodb.QueryInput: | ||
|
||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName)) | ||
|
||
if v.ConsistentRead != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBConsistentReadKey.Bool(*v.ConsistentRead)) | ||
} | ||
|
||
if v.IndexName != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBIndexNameKey.String(*v.IndexName)) | ||
} | ||
|
||
if v.Limit != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBLimitKey.Int(int(*v.Limit))) | ||
} | ||
|
||
if v.ScanIndexForward != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBScanForwardKey.Bool(*v.ScanIndexForward)) | ||
} | ||
|
||
if v.ProjectionExpression != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBProjectionKey.String(*v.ProjectionExpression)) | ||
} | ||
|
||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBSelectKey.String(string(v.Select))) | ||
|
||
case *dynamodb.ScanInput: | ||
|
||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName)) | ||
|
||
if v.ConsistentRead != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBConsistentReadKey.Bool(*v.ConsistentRead)) | ||
} | ||
|
||
if v.IndexName != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBIndexNameKey.String(*v.IndexName)) | ||
} | ||
|
||
if v.Limit != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBLimitKey.Int(int(*v.Limit))) | ||
} | ||
|
||
if v.ProjectionExpression != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBProjectionKey.String(*v.ProjectionExpression)) | ||
} | ||
|
||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBSelectKey.String(string(v.Select))) | ||
|
||
if v.Segment != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBSegmentKey.Int(int(*v.Segment))) | ||
} | ||
|
||
if v.TotalSegments != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTotalSegmentsKey.Int(int(*v.TotalSegments))) | ||
} | ||
|
||
case *dynamodb.UpdateItemInput: | ||
|
||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName)) | ||
|
||
case *dynamodb.UpdateTableInput: | ||
|
||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBTableNamesKey.String(*v.TableName)) | ||
|
||
if v.AttributeDefinitions != nil { | ||
attributedefinitions, _ := json.Marshal(v.AttributeDefinitions) | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBAttributeDefinitionsKey.String(string(attributedefinitions))) | ||
} | ||
|
||
if v.GlobalSecondaryIndexUpdates != nil { | ||
globalsecondaryindexupdates, _ := json.Marshal(v.GlobalSecondaryIndexUpdates) | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBGlobalSecondaryIndexUpdatesKey.String(string(globalsecondaryindexupdates))) | ||
} | ||
|
||
if v.ProvisionedThroughput != nil { | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBProvisionedReadCapacityKey.Int64(*v.ProvisionedThroughput.ReadCapacityUnits)) | ||
dynamodbAttributes = append(dynamodbAttributes, semconv.AWSDynamoDBProvisionedWriteCapacityKey.Int64(*v.ProvisionedThroughput.WriteCapacityUnits)) | ||
} | ||
|
||
} | ||
|
||
return dynamodbAttributes | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.