You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor the AbstractController.register function to properly use XRay. Should look like this:
// you can override invoke in a subclass to adjust the return type
protected async invoke(event): Promise<any> {
return new Promise<any>((resolve, reject)=>{
// add X-Ray telemetry passing the subsegment
AWSXRay.captureAsyncFunc(this.getSegmentName(), async (subsegment) => {
try {
const result = await this.processRequest(event);
resolve(result);
} catch(e) {
this.log(LogLevels.ERROR, e.message, event, e);
reject(e);
} finally {
subsegment.close();
}
});
});
}
protected async processRequest(event): Promise<any> {
// to open a subsegment for x-ray call AWSXRay.captureAsyncFunc
// you'll have to promisfy the call or wrap in a promise like invoke
// log request received
this.log(LogLevels.INFO, this.getSegmentName() + ' Request received', event);
try {
// first validate the incoming request.
this.checkValidation(event);
// stub for override
// in your sub classes you should supply value for result and error
return null;
} catch (e) {
// log error response
this.log(LogLevels.ERROR, e.message, null, e);
throw e;
}
}
In index.ts make sure we are opening up the main segment and closing it as follows
var AWSXRay = require('aws-xray-sdk');
app.use(AWSXRay.express.openSegment('defaultName')); // required at the start of your routes
app.get('/', function (req, res) {
res.render('index');
});
app.use(AWSXRay.express.closeSegment()); //Required at the end of your routes / first in error handling routes
Refactor the AbstractController.register function to properly use XRay. Should look like this:
In index.ts make sure we are opening up the main segment and closing it as follows
Reference is at: https://docs.aws.amazon.com/xray-sdk-for-nodejs/latest/reference/
The text was updated successfully, but these errors were encountered: