aws / aws-xray-sdk-node

The official AWS X-Ray SDK for Node.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

captureAsyncFunc is not working for AWS Lambda with runtime nodejs 16

ujasur opened this issue · comments

I am experiencing strange issue with using captureAsyncFunc in my code that runs on aws lambda nodejs16x runtime.
Here is my environment:

  1. Lambda runtime is nodejs16.x
  2. The config for active tracing with XRAY is on. I see some traces but not the ones with captureAsyncFunc
  3. The lambda zip package is built with public.ecr.aws/lambda/nodejs:16 docker image
  4. The aws-xray-sdk is 3.5.1 and this only npm package dependencies of my code.
  5. If I remove the xray.captureHTTPsGlobal(require('https')); line, the #perform segment is shown on tracing graph in aws console however the url is not shown.
  6. Below attached my code
const xray = require('aws-xray-sdk');

xray.captureHTTPsGlobal(require('https'));
const https = require('https');

async function doWork() {
  await xray.captureAsyncFunc('perform', async (subsegment) => {
    const resp = await https.get('https://encrypted.google.com/');

    subsegment.close();
    console.log('fetched', resp.status);
  });
}

exports.handler = async (event, context) => {
  await doWork( event, context);
};

Can you try adding xray.capturePromise() before your xray.captureAsyncFunc() call? I was able to see the perform subsegment after adding this line (see this related issue for more information)