简体   繁体   中英

aws xray not monitoring dynamo dax client in nodejs

I recently started using dynamodb dax within my node lambda function, however with 'amazon-dax-client' framework, i cannot longer capture transparently with http requests made by the framework, like so;

 const AWS = AWSXRay.captureAWS(require('aws-sdk')); const dynamoDB = AWSXRay.captureAWSClient(new AWS.DynamoDB(defaults.db.config));

I know i could create an async capture. but i am wondering if there is a better way to do this, like in the previous way and if i someone managed to capture requests, made with dax-client in the same way as with the dynamo client from aws framework.

DAX doesn't currently support XRay, because DAX doesn't use the standard AWS SDK HTTP client (it doesn't use HTTP at all).

The team has received other requests for XRay support so it's certainly something we're considering.

While there is no official support for XRAY from DAX team. I wrote a little snippet as a workaround.

const db = new Proxy(documentClient, {
    get: (target: any, prop: any) => {
      if (typeof target[prop] === "function") {
        return (...args: any) => {
          const segment = xray
            .getSegment()
            ?.addNewSubsegment(`DynamoDB::${prop}`);

          const request = target[prop](...args);

          const promise = request
            .promise()
            .then((response: any) => {
              segment?.close();
              return response;
            })
            .catch((err: any) => {
              segment?.close();
              return Promise.reject(err);
            });

          return {
            ...request,
            promise: () => promise,
          };
        };
      }

      return target[prop];
    },
  });

const response await = db.query(...).promise();

Tested in AWS Lambda under VPC private su.net and AWS XRAY service endpoint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM