aws-xray-sdk-node: Using `captureAWSClient` over directly referenced dynamodb client fails
The following code does not work:
const DynamoDB = require('aws-sdk/clients/dynamodb')
const xray = require('aws-xray-sdk-core')
const ddb = xray.captureAWSClient(new DynamoDB())
In theory, it should be just the same as encapsulating new AWS.DynamoDB()
coming straight from aws-sdk
, but it does not work.
This is specially problematic in AWS Lambda environment, where loading more than you need makes you use more memory and more time.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 27 (12 by maintainers)
Here is a workaround (from https://github.com/aws/aws-sdk-js/issues/1846)
Hi @phstc I got the same error instrumenting the Lambda, and I resolved by doing this:
That’s because the class Lambda extends an aws Service.
I’m using Typescript and Webpack - here’s how I’m instrumenting with the thin dynamoDB client, if that’s helpful:
Sure. This issue was just getting some clutter but the bug does still exist. Unfortunately this and #184 are reliant on the AWS SDK team to unify their client classes. Reopening to continue to track that progress.
My bad, I thought it doesn’t modify given object but returns new instrumented instance. Works! Thanks!
Hi @phstc, I hope your issue has been resolved by the follow up. If it hasn’t please open a new issue to avoid too much clutter on this one, and we will prioritize following up further. Please note that the X-Ray SDK for node.js does not support typescript at the moment and using typescript notation with our APIs can cause issues.