How to use the aws-xray-sdk.express function in aws-xray-sdk

To help you get started, we’ve selected a few aws-xray-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudacademy / aws-xray-microservices-calc / node-subtract / server.js View on Github external
};

    sqs.sendMessage(params, function(err, data) {
        if (err) {
            console.log(`sqs error for ${serviceName} service`, data.MessageId);            
        } else {
            console.log(`sqs success for ${serviceName} service`, data.MessageId);            
        }
    });    
});

// REGISTER OUR ROUTES -------------------------------
// all of our routes will be prefixed with /api
app.use('/api', router);

app.use(xray.express.closeSegment());

// START THE SERVER
// =============================================================================
app.listen(port);
console.log(`${serviceName} service listening on port: ` + port);
github cloudacademy / aws-xray-microservices-calc / node-postfix / server.js View on Github external
var express     = require('express');        // call express
var app         = express();                 // define our app using express
var bodyParser  = require('body-parser');
var mathsolver  = require("./mathsolver.js");
var xray        = require('aws-xray-sdk');
var aws         = require('aws-sdk');

var serviceName = "POSTFIX";
var servicePort = 9090;

// Initializes X-Ray
xray.middleware.setSamplingRules('sampling-rules.json');

// Starts X-Ray Segment
app.use(xray.express.openSegment(serviceName));

var sqs = xray.captureAWSClient(new aws.SQS());

// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var port = process.env.PORT || servicePort;

var calcSQSQueue = process.env.CALC_SQS_QUEUE_URL

// ROUTES FOR OUR API
// =============================================================================
var router = express.Router();
github aws-samples / aws-xray-kubernetes / demo-app / service-b / server.js View on Github external
var XRay = require('aws-xray-sdk');
var AWS = XRay.captureAWS(require('aws-sdk'));

const express = require('express');

// Constants
const PORT = 8080;

// App
const app = express();

XRay.config([XRay.plugins.EC2Plugin, XRay.plugins.ECSPlugin]);
XRay.middleware.enableDynamicNaming();

app.use(XRay.express.openSegment('service-b'));

function randomIntInc(low, high) {
  return Math.floor(Math.random() * (high - low + 1) + low);
}

function sleep(callback) {
  var now = new Date().getTime();
  while (new Date().getTime() < now + randomIntInc(0, 1000)) { /* */ }
  callback();
}

app.get('/health', function(req, res) {
  res.status(200).send("Healthy");
});

app.post('/create', function(req, res) {
github cloudacademy / aws-xray-microservices-calc / node-subtract / server.js View on Github external
var express     = require('express');
var app         = express();
var bodyParser  = require('body-parser');
var xray        = require('aws-xray-sdk');
var aws         = require('aws-sdk');

var serviceName = "SUBTRACT";
var servicePort = 8082;

app.use(xray.express.openSegment(serviceName));

var sqs = xray.captureAWSClient(new aws.SQS());

// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var port = process.env.PORT || servicePort;

var calcSQSQueue = process.env.CALC_SQS_QUEUE_URL

// ROUTES FOR OUR API
// =============================================================================
var router = express.Router();
github alphagov / pay-selfservice / app / routes.js View on Github external
module.exports.bind = function (app) {
  AWSXRay.enableManualMode()
  AWSXRay.setLogger(logger)
  AWSXRay.middleware.setSamplingRules('aws-xray.rules')
  AWSXRay.config([AWSXRay.plugins.ECSPlugin])
  app.use(AWSXRay.express.openSegment('pay_selfservice'))

  createNamespace(clsXrayConfig.nameSpaceName)

  app.get('/style-guide', (req, res) => response(req, res, 'style_guide'))

  // APPLY CORRELATION MIDDLEWARE
  app.use('*', correlationIdMiddleware, getRequestContext)

  app.use((req, res, next) => {
    const namespace = getNamespace(clsXrayConfig.nameSpaceName)
    namespace.bindEmitter(req)
    namespace.bindEmitter(res)
    namespace.run(() => {
      next()
    })
  })
github cloudacademy / aws-xray-microservices-calc / node-add / server.js View on Github external
var express     = require('express');
var app         = express();
var bodyParser  = require('body-parser');
var xray        = require('aws-xray-sdk');
var aws         = require('aws-sdk');

var serviceName = "ADD";
var servicePort = 8081;

app.use(xray.express.openSegment(serviceName));

var sqs = xray.captureAWSClient(new aws.SQS());

// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

// set our port
var port = process.env.PORT || servicePort;

var calcSQSQueue = process.env.CALC_SQS_QUEUE_URL

// ROUTES FOR OUR API
// =============================================================================
var router = express.Router();
github aws-samples / aws-xray-fargate / src / service-b / server.js View on Github external
var XRay = require('aws-xray-sdk');
var AWS = XRay.captureAWS(require('aws-sdk'));

const express = require('express');

// Constants
const PORT = 8080;

// App
const app = express();

XRay.config([XRay.plugins.ECSPlugin]);
XRay.middleware.enableDynamicNaming();

app.use(XRay.express.openSegment('service-b'));

function randomIntInc(low, high) {
  return Math.floor(Math.random() * (high - low + 1) + low);
}

function sleep(callback) {
  var now = new Date().getTime();
  while (new Date().getTime() < now + randomIntInc(0, 1000)) { /* */ }
  callback();
}

app.get('/health', function(req, res) {
  res.status(200).send("Healthy");
});

app.post('/create', function(req, res) {
github cloudacademy / aws-xray-microservices-calc / node-divide / server.js View on Github external
var express     = require('express');
var app         = express();
var bodyParser  = require('body-parser');
var xray        = require('aws-xray-sdk');
var aws         = require('aws-sdk');

var serviceName = "DIVIDE";
var servicePort = 8084;

app.use(xray.express.openSegment(serviceName));

var sqs = xray.captureAWSClient(new aws.SQS());

// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var port = process.env.PORT || servicePort;

var calcSQSQueue = process.env.CALC_SQS_QUEUE_URL

// ROUTES FOR OUR API
// =============================================================================
var router = express.Router();
github cloudacademy / aws-xray-microservices-calc / node-power / server.js View on Github external
var express     = require('express');
var app         = express();
var bodyParser  = require('body-parser');
var xray        = require('aws-xray-sdk');
var aws         = require('aws-sdk');

var serviceName = "POWER";
var servicePort = 8085;

app.use(xray.express.openSegment(serviceName));

var sqs = xray.captureAWSClient(new aws.SQS());

// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var port = process.env.PORT || servicePort;

var calcSQSQueue = process.env.CALC_SQS_QUEUE_URL

// ROUTES FOR OUR API
// =============================================================================
var router = express.Router();
github aws-samples / aws-workshop-for-kubernetes / 03-path-application-development / 306-app-tracing-with-jaeger-and-x-ray / x-ray / nodejs-microservices / greeter / server.js View on Github external
app.get('/*', (req, res) => {
  	var greet = 'Hello';
	
	var seg = XRay.getSegment();
	seg.addAnnotation('greet_req', req.query['greet']);
	
  	console.log('greet[greet]: ' + req.query['greet']);

	if (req.query['greet'] == 'ho') {
		greet = 'Howdy';
	}

  res.send(greet);
});

app.use(XRay.express.closeSegment());
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);