Skip to content

Commit

Permalink
feat: Add capacity information when applicable to dynamodb spans
Browse files Browse the repository at this point in the history
  • Loading branch information
nordfjord committed Jan 29, 2023
1 parent aae03f2 commit 5739917
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ export class DynamodbServiceExtension implements ServiceExtension {
responseHook(
response: NormalizedResponse,
span: Span,
tracer: Tracer,
config: AwsSdkInstrumentationConfig
_tracer: Tracer,
_config: AwsSdkInstrumentationConfig
) {
const operation = response.request.commandName;

if (operation === 'BatchGetItem') {
if (Array.isArray(response.data?.ConsumedCapacity)) {
span.setAttribute(
SemanticAttributes.AWS_DYNAMODB_CONSUMED_CAPACITY,
response.data.ConsumedCapacity.map(
(x: { [DictionaryKey: string]: any }) => JSON.stringify(x)
)
);
}
if ("ConsumedCapacity" in response.data) {
span.setAttribute(
SemanticAttributes.AWS_DYNAMODB_CONSUMED_CAPACITY,
toArray(response.data.ConsumedCapacity).map(
(x: { [DictionaryKey: string]: any }) => JSON.stringify(x)
)
);
}
}
}

function toArray<T>(values: T | T[]): T[] {
return Array.isArray(values) ? values : [values];
}

0 comments on commit 5739917

Please sign in to comment.