How to use aws-xray-sdk - 10 common examples

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 pluto-net / scinapse-web-client / app / server / index.tsx View on Github external
const userType = getExpUserType(rawCookie || "");

  let bundledJsForBrowserPath: string;
  if (queryParamsObj && queryParamsObj.branch && queryParamsObj.branch === "master") {
    bundledJsForBrowserPath = `${DeployConfig.CDN_BASE_PATH}/${DeployConfig.AWS_S3_PRODUCTION_FOLDER_PREFIX}/${
      queryParamsObj.version
    }/bundleBrowser.js`;
    version = decodeURIComponent(queryParamsObj.branch);
  } else if (isDevDemoRequest) {
    bundledJsForBrowserPath = `${DeployConfig.CDN_BASE_PATH}/${
      DeployConfig.AWS_S3_DEV_FOLDER_PREFIX
    }/${decodeURIComponent(queryParamsObj.branch)}/bundleBrowser.js`;
    version = decodeURIComponent(queryParamsObj.branch);
  } else {
    AWSXRay.captureHTTPsGlobal(require("http"));
    AWSXRay.captureAWS(require("aws-sdk"));
    version = fs.readFileSync("./version").toString("utf8");
    bundledJsForBrowserPath = `${DeployConfig.CDN_BASE_PATH}/${
      DeployConfig.AWS_S3_PRODUCTION_FOLDER_PREFIX
    }/${version}/bundleBrowser.js`;
  }

  console.log(`The user requested at: ${path} with ${JSON.stringify(queryParamsObj)}`);

  // Handling '/robots.txt' path
  if (path === "/robots.txt") {
    return getResponseObjectForRobot(event.headers.host === "scinapse.io");
  }

  // handling '/sitemap' path
  if (path.search(SITEMAP_REGEX) !== -1) {
    return handleSiteMapRequest(path);
github aws-samples / aws-workshop-for-kubernetes / 03-path-application-development / 306-app-tracing-with-jaeger-and-x-ray / x-ray / nodejs-microservices / webapp / server.js View on Github external
'use strict';

// Include the AWS X-Ray Node.js SDK and set configuration
//ref:  https://docs.aws.amazon.com/xray-sdk-for-nodejs/latest/reference/
const XRay = require('aws-xray-sdk');
const AWS  = XRay.captureAWS(require('aws-sdk'));
const http = XRay.captureHTTPs(require('http'));
const express = require('express');
// const request = require('sync-request');

// Constants
const PORT = 8080;
const HOST = '0.0.0.0';
AWS.config.region = process.env.REGION

XRay.config([XRay.plugins.EC2Plugin, XRay.plugins.ECSPlugin]);
//XRay.middleware.setSamplingRules('sampling-rules.json');
XRay.middleware.enableDynamicNaming('*.elb.amazonaws.com');

// App
const app = express();
app.use(XRay.express.openSegment('webapp'));

app.get('/', (req, res) => {
	let seg = XRay.getSegment();
	seg.addAnnotation('param_greet', req.query['greet']);
	seg.addAnnotation('param_id', req.query['id']);

	getContent({hostname:`${process.env.GREETER_SERVICE_HOST}` ,port:process.env.GREETER_SERVICE_PORT, path: `/${process.env.GREETER_SERVICE_PATH}?greet=${req.query['greet']}`})
	.then( function (html){ 
		console.log (html); 
		var output1 = html;
github aws-samples / aws-workshop-for-kubernetes / 03-path-application-development / 306-app-tracing-with-jaeger-and-x-ray / x-ray / nodejs-microservices / webapp / server.js View on Github external
// Include the AWS X-Ray Node.js SDK and set configuration
//ref:  https://docs.aws.amazon.com/xray-sdk-for-nodejs/latest/reference/
const XRay = require('aws-xray-sdk');
const AWS  = XRay.captureAWS(require('aws-sdk'));
const http = XRay.captureHTTPs(require('http'));
const express = require('express');
// const request = require('sync-request');

// Constants
const PORT = 8080;
const HOST = '0.0.0.0';
AWS.config.region = process.env.REGION

XRay.config([XRay.plugins.EC2Plugin, XRay.plugins.ECSPlugin]);
//XRay.middleware.setSamplingRules('sampling-rules.json');
XRay.middleware.enableDynamicNaming('*.elb.amazonaws.com');

// App
const app = express();
app.use(XRay.express.openSegment('webapp'));

app.get('/', (req, res) => {
	let seg = XRay.getSegment();
	seg.addAnnotation('param_greet', req.query['greet']);
	seg.addAnnotation('param_id', req.query['id']);

	getContent({hostname:`${process.env.GREETER_SERVICE_HOST}` ,port:process.env.GREETER_SERVICE_PORT, path: `/${process.env.GREETER_SERVICE_PATH}?greet=${req.query['greet']}`})
	.then( function (html){ 
		console.log (html); 
		var output1 = html;
		// console.log(`output = ${output1}`);
		getContent({hostname:`${process.env.NAME_SERVICE_HOST}` ,port:process.env.NAME_SERVICE_PORT, path: `/${process.env.NAME_SERVICE_PATH}?id=${req.query['id']}`})
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
'use strict';

// Include the AWS X-Ray Node.js SDK and set configuration
var XRay = require('aws-xray-sdk');
var AWS  = require('aws-sdk');
const express = require('express');

// Constants
const PORT = 8080;
const HOST = '0.0.0.0';

AWS.config.region = process.env.REGION
XRay.config([XRay.plugins.EC2Plugin, XRay.plugins.ECSPlugin]);


// App
const app = express();
app.use(XRay.express.openSegment('greeter-svc'));

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';
github aws-samples / aws-workshop-for-kubernetes / 03-path-application-development / 306-app-tracing-with-jaeger-and-x-ray / x-ray / nodejs-microservices / name / server.js View on Github external
'use strict';

// Include the AWS X-Ray Node.js SDK and set configuration
var XRay = require('aws-xray-sdk');
var AWS = XRay.captureAWS(require('aws-sdk'));
const express = require('express');

// Constants
const PORT = 8080;
const HOST = '0.0.0.0';

AWS.config.region = process.env.REGION
XRay.config([XRay.plugins.EC2Plugin, XRay.plugins.ECSPlugin]);

// App
const app = express();
app.use(XRay.express.openSegment('name-svc'));


app.get('/*', (req, res) => {
  	var name = 'Arun';

	var seg = XRay.getSegment();
	seg.addAnnotation('name_req', req.query['id']);
	
  	console.log('name[id]: ' + req.query['id']);
  	
	if (req.query['id'] == '1') {
		name = 'Sheldon';
github pluto-net / scinapse-web-client / app / server / index.tsx View on Github external
let succeededToServerRendering = false;
  let version: string;

  let bundledJsForBrowserPath: string;
  if (queryParamsObj && queryParamsObj.branch && queryParamsObj.branch === "master") {
    bundledJsForBrowserPath = `${DeployConfig.CDN_BASE_PATH}/${DeployConfig.AWS_S3_PRODUCTION_FOLDER_PREFIX}/${
      queryParamsObj.version
    }/bundleBrowser.js`;
    version = decodeURIComponent(queryParamsObj.branch);
  } else if (isDevDemoRequest) {
    bundledJsForBrowserPath = `${DeployConfig.CDN_BASE_PATH}/${
      DeployConfig.AWS_S3_DEV_FOLDER_PREFIX
    }/${decodeURIComponent(queryParamsObj.branch)}/bundleBrowser.js`;
    version = decodeURIComponent(queryParamsObj.branch);
  } else {
    AWSXRay.captureHTTPsGlobal(require("http"));
    AWSXRay.captureAWS(require("aws-sdk"));
    version = fs.readFileSync("./version").toString("utf8");
    bundledJsForBrowserPath = `${DeployConfig.CDN_BASE_PATH}/${
      DeployConfig.AWS_S3_PRODUCTION_FOLDER_PREFIX
    }/${version}/bundleBrowser.js`;
  }

  console.log(`The user requested at: ${path} with ${JSON.stringify(queryParamsObj)}`);

  // Handling '/robots.txt' path
  if (path === "/robots.txt") {
    return getResponseObjectForRobot(event.headers.host === "scinapse.io");
  }

  // handling '/sitemap' path
  if (path.search(SITEMAP_REGEX) !== -1) {
github pluto-net / scinapse-web-client / app / server / index.tsx View on Github external
const rawCookie = event.headers.cookie;
  const userType = getExpUserType(rawCookie || "");

  let bundledJsForBrowserPath: string;
  if (queryParamsObj && queryParamsObj.branch && queryParamsObj.branch === "master") {
    bundledJsForBrowserPath = `${DeployConfig.CDN_BASE_PATH}/${DeployConfig.AWS_S3_PRODUCTION_FOLDER_PREFIX}/${
      queryParamsObj.version
    }/bundleBrowser.js`;
    version = decodeURIComponent(queryParamsObj.branch);
  } else if (isDevDemoRequest) {
    bundledJsForBrowserPath = `${DeployConfig.CDN_BASE_PATH}/${
      DeployConfig.AWS_S3_DEV_FOLDER_PREFIX
    }/${decodeURIComponent(queryParamsObj.branch)}/bundleBrowser.js`;
    version = decodeURIComponent(queryParamsObj.branch);
  } else {
    AWSXRay.captureHTTPsGlobal(require("http"));
    AWSXRay.captureAWS(require("aws-sdk"));
    version = fs.readFileSync("./version").toString("utf8");
    bundledJsForBrowserPath = `${DeployConfig.CDN_BASE_PATH}/${
      DeployConfig.AWS_S3_PRODUCTION_FOLDER_PREFIX
    }/${version}/bundleBrowser.js`;
  }

  console.log(`The user requested at: ${path} with ${JSON.stringify(queryParamsObj)}`);

  // Handling '/robots.txt' path
  if (path === "/robots.txt") {
    return getResponseObjectForRobot(event.headers.host === "scinapse.io");
  }

  // handling '/sitemap' path
  if (path.search(SITEMAP_REGEX) !== -1) {
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) {