Reputation: 546
I'm trying to integrate AWS X-Ray with an Express Gateway application to trace incoming HTTP requests and monitor performance. However, I am facing issues accessing the internal Express instance to attach the X-Ray middleware properly.
AWS X-Ray SDK Setup: I also tried the usual setup for AWS X-Ray by calling AWSXRay.captureHTTPsGlobal(require('http')) to capture HTTP traffic globally, but the traces are not appearing in the AWS X-Ray console.
What I’m Looking For: A working solution to hook the AWS X-Ray middleware into Express Gateway’s internal Express app. Any official method or best practice to add custom middleware for tracing in Express Gateway. Code Example (What I've Tried):
const path = require("path");
const gateway = require("express-gateway");
const AWSXRay = require('aws-xray-sdk');
const nconf = require("nconf");
const { loadConfigurations } = require("./aws");
nconf.use('memory').env({ parseValues: true });
(async () => {
await loadConfigurations();
// Global capture of HTTP(S) requests with AWS X-Ray
AWSXRay.captureHTTPsGlobal(require('http'));
AWSXRay.captureHTTPsGlobal(require('https'));
const gatewayInstance = gateway().load(path.join(__dirname, "config"));
gatewayInstance.on('loaded', () => {
const expressApp = gatewayInstance.app; // Access the underlying Express app
// Add AWS X-Ray middleware
expressApp.use(AWSXRay.express.openSegment('appstore-gateway'));
expressApp.use(AWSXRay.express.closeSegment());
console.log('AWS X-Ray middleware applied.');
});
gatewayInstance.run(); // Start the Gateway
})();
Any help or insight into correctly hooking AWS X-Ray into Express Gateway would be greatly appreciated!
Upvotes: 0
Views: 31
Reputation: 36
My understanding is that AWSXRay.express
middleware is specifically for express
package. It is not officially used to support node Express Gateway
.
Otherwise, do you have the X-Ray Daemon running (required to send Segments to X-Ray).
Upvotes: 0