Skip to content

client-node x-ray integration #191

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

Closed
rafaelrpinto opened this issue Aug 14, 2019 · 4 comments
Closed

client-node x-ray integration #191

rafaelrpinto opened this issue Aug 14, 2019 · 4 comments

Comments

@rafaelrpinto
Copy link

Hi,

I've been looking into the source code and issues but could not find a way to trace the KMS requests made by client-node using AWS X-Ray.

Could you please confirm if that's possible?

Thank you.

@seebees
Copy link
Contributor

seebees commented Aug 14, 2019

I will try and get you a clear answer. What environment are you running this in? AWS Lambda?

@rafaelrpinto
Copy link
Author

@seebees

Yes, we are running APIG + Labdas with Node 10. Thank you.

@seebees
Copy link
Contributor

seebees commented Aug 15, 2019

The KmsKeyringNode uses a clientProvider to create the needed KMS Clients.
The default is the cacheKmsClients that will cache the clients per region.
To use AWS X-Ray, you need to wrap the KMS Clients.

You can create your own clientProvider
to wrap your own version of the AWS SDK with captureAWS like this.

const AWSXRay = require('aws-xray-sdk')
const { getClient, cacheClients } = require('@aws-crypto/client-node')
const { KMS } = AWSXRay.captureAWS(require('aws-sdk'))

const clientProvider = cacheClients(getClient(KMS))

Or you can wrap the KMS Client returned by getKmsClient with captureAWSClient from aws-xray-sdk.

const AWSXRay = require('aws-xray-sdk')
const { getKmsClient, cacheClients } = require('@aws-crypto/client-node')

const clientProvider = cacheClients(region => AWSXRay.captureAWSClient(getKmsClient(region)))

Now that you have a clientProvider that does what you want,
just pass this to the KmsKeyringNode

const keyring = new KmsKeyringNode({ clientProvider, /* Your generatorKeyId, and keyIds here */})

@rafaelrpinto
Copy link
Author

@seebees

Thanks a lot for the explanation. That's exactly what we needed.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants