dd-trace
Version:
Datadog APM tracing client for JavaScript
47 lines (38 loc) • 1.46 kB
JavaScript
class DynamoDb {
generateTags (params, operation, response) {
const tags = {}
if (params) {
if (params.TableName) {
Object.assign(tags, {
'resource.name': `${operation} ${params.TableName}`,
'aws.dynamodb.table_name': params.TableName
})
}
// batch operations have different format, collect table name for batch
// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#batchGetItem-property`
// dynamoDB batch TableName
if (params.RequestItems) {
if (typeof params.RequestItems === 'object') {
if (Object.keys(params.RequestItems).length === 1) {
const tableName = Object.keys(params.RequestItems)[0]
// also add span type to match serverless convention
Object.assign(tags, {
'resource.name': `${operation} ${tableName}`,
'aws.dynamodb.table_name': tableName
})
}
}
}
// TODO: DynamoDB.DocumentClient does batches on multiple tables
// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#batchGet-property
// it may be useful to have a different resource naming convention here to show all table names
}
// also add span type to match serverless convention
Object.assign(tags, {
'span.type': 'dynamodb'
})
return tags
}
}
module.exports = DynamoDb