简体   繁体   中英

AWS X Ray node js trails not showing

I am using Lambda (Node 8.10) and working with AWS X Ray. I am calling an external ip address using promise. When I call, other traces are shown but cannot get custom segment. I am not using any frameworks just a pure node js.

const AWSXRay = require('aws-xray-sdk-core');

AWSXRay.enableManualMode();
AWSXRay.captureHTTPsGlobal(require('https'));

const https = AWSXRay.captureHTTPs(require('https'));

exports.handler = async (event, context, callback) => {
// other code

const response = await doSomething(event);
    return callback(error, response);
};

async doSomething(event) {
return new Promise((resolve, reject) => {
    const segment = new AWSXRay.Segment('custom_segment_here');

    AWSXRay.captureAsyncFunc('send', (subsegment) => {
        const options = {
                    hostname: host,
                    port: 443,
                    path: '/',
                    method: 'GET',
                    XRaySegment: subsegment,
                };

        const req = https.request(options, (res) => {
            code = res.statusCode;
            resolve(code);
        });

        req.on('error', (error) => {
                    subsegment.addError(error);
                    reject(error);
                });

                subsegment.close();
                req.end();
    }, segment);

}

}

In Lambda scenario, Lambda is responsible for creating Segments and AWS X-Ray SDKs only create Subsegments and then emits them. Based on your code snippet, you created a segment (const segment = new AWSXRay.Segment('custom_segment_here');) inside a lambda function which couldn't be emitted so that you cannot see it in our console. Hope my answer is clear. :)

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