How to use the aws-xray-sdk.config 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 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 / 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 aws-samples / aws-xray-fargate / src / service-a / server.js View on Github external
var AWS = XRay.captureAWS(require('aws-sdk'));
var http = XRay.captureHTTPs(require('http'));

const express = require('express');
var bodyParser = require('body-parser');
var queryString = require('querystring');


// Constants
const PORT = 8080;
const apiCNAME = process.env.API_CNAME || 'localhost';

// App
const app = express();

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

app.use(bodyParser.urlencoded({extended: false}));
app.use(XRay.express.openSegment('service-a'));

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

app.get('/', function(req, res) {
  var seg = XRay.getSegment();
  seg.addAnnotation('service', 'service-b-request');

  var reqData = queryString.stringify(req.body);

  var options = {
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 linuxacademy / eks-deep-dive-2019 / 4-3-XRay / 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");
github linuxacademy / eks-deep-dive-2019 / 4-3-XRay / demo-app / service-a / server.js View on Github external
var AWS = XRay.captureAWS(require('aws-sdk')); // Capture all AWS SDK calls
var http = XRay.captureHTTPs(require('http')); // Capture all HTTP/HTTPS calls

const express = require('express');
var bodyParser = require('body-parser');
var queryString = require('querystring');


// Constants
const PORT = 8080;
const apiCNAME = process.env.API_CNAME || 'localhost';

// App
const app = express();

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

app.use(bodyParser.urlencoded({extended: false}));

// Start capturing the calls in the application
app.use(XRay.express.openSegment('service-a'));

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

app.get('/', function(req, res) {
  var seg = XRay.getSegment();
  seg.addAnnotation('service', 'service-b-request');

  var reqData = queryString.stringify(req.body);
github aws-samples / aws-xray-kubernetes / demo-app / service-b / server.js View on Github external
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

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");
github aws-samples / aws-xray-fargate / src / service-b / server.js View on Github external
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

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");
github alphagov / pay-frontend / app / routes.js View on Github external
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_frontend'))

  createNamespace(clsXrayConfig.nameSpaceName)

  app.use((req, res, next) => {
    const namespace = getNamespace(clsXrayConfig.nameSpaceName)
    namespace.bindEmitter(req)
    namespace.bindEmitter(res)
    namespace.run(() => {
      next()
    })
  })

  app.get('/healthcheck', healthcheck)

  // charges