Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise(resolve => {
AWSXRay.setDaemonAddress('127.0.0.1:2000');
AWSXRay.enableAutomaticMode();
const segment = new AWSXRay.Segment('aws-xray-lambda-promise-subsegment');
const namespace = AWSXRay.getNamespace();
namespace.run(async function () {
AWSXRay.setSegment(segment);
console.log('segment', segment);
try {
await functionToHaveTraced(segment);
segment.close();
} catch (error) {
console.error(error);
segment.close(error);
}
resolve();
});
});
}
nameSpace.run(() => {
nameSpace.set('segment', new AWSXRay.Segment('annotations'))
const result = handler(event, context, callback)
if (result != null) {
Promise.resolve(result).then(
resolved => {
console.log('Result:')
console.log(JSON.stringify(resolved))
},
rejected => {
console.log('Error:')
console.log(rejected)
}
)
}
})
}