How to use the aws-xray-sdk.getSegment 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 theburningmonk / manning-aws-lambda-in-motion / functions / get-index.js View on Github external
try {
        let body = (yield httpReq).body;
        if (subsegment) {
          subsegment.close();
        }
        resolve(body);
      } catch (err) {
        if (subsegment) {
          subsegment.close(err);
        }
        reject(err);
      }
    });

    // the current sub/segment
    let segment = AWSXRay.getSegment();

    AWSXRay.captureAsyncFunc("getting restaurants", f, segment);
  });
}
github aws-samples / aws-xray-kubernetes / demo-app / service-a / server.js View on Github external
app.get('/', function(req, res) {
  var seg = XRay.getSegment();
  seg.addAnnotation('service', 'service-b-request');

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

  var options = {
    host: apiCNAME,
    port: '80',
    path: '/create',
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Content-Length': Buffer.byteLength(reqData)
    }
  };

  // Set up the request
github aws-samples / aws-xray-fargate / src / service-a / server.js View on Github external
app.get('/', function(req, res) {
  var seg = XRay.getSegment();
  seg.addAnnotation('service', 'service-b-request');

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

  var options = {
    host: apiCNAME,
    port: '80',
    path: '/create',
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Content-Length': Buffer.byteLength(reqData)
    }
  };

  // Set up the request
github linuxacademy / eks-deep-dive-2019 / 4-3-XRay / demo-app / service-a / server.js View on Github external
app.get('/', function(req, res) {
  var seg = XRay.getSegment();
  seg.addAnnotation('service', 'service-b-request');

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

  var options = {
    host: apiCNAME,
    port: '80',
    path: '/create',
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Content-Length': Buffer.byteLength(reqData)
    }
  };

  // Set up the request
github cloudacademy / aws-xray-microservices-calc / node-calc / server.js View on Github external
var calcid = req.body.calcid;

    console.log("=====================================");
    console.log("Calculator entry point...");

    if (typeof calcid == "undefined") {    
        calcid = shortid.generate();
        console.log(`generating new calcid: ${calcid}`);
    }
    else {
        console.log(`calcid supplied: ${calcid}`);
    }

    console.log(`calcid: ${calcid}, infix: ${infix}`);
    
    var seg = xray.getSegment();
    seg.addAnnotation('calcid', calcid);
    
    const postData = querystring.stringify({
        'calcid': calcid,
        'expression': infix
    });

    const options = {
        hostname: '172.19.0.200',
        port: 9090,
        path: '/api/postfix/',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Content-Length': Buffer.byteLength(postData)
        }
github cloudacademy / aws-xray-microservices-calc / node-postfix / server.js View on Github external
router.post("/postfix", function(req, res) {
    var calcid = req.body.calcid;
    var infix = req.body.expression;

    var seg = xray.getSegment();
    seg.addAnnotation('calcid', calcid);

    console.log(`${serviceName}->calcid: ${calcid}, infix: ${infix}`);
    var postfix = mathsolver.infixToPostfix(infix).trim();
    console.log(`${serviceName}->calcid: ${calcid}, postfix: ${postfix}`);
    res.write(postfix);
    
    var responseCode = 200;
    var random = Math.random();

    //randomize response code
    if (random < 0.8) {
        //GREEN
        responseCode = 200;
    } else if (random < 0.9) {
        //ORANGE
github cloudacademy / aws-xray-microservices-calc / node-divide / server.js View on Github external
router.get("/divide", function(req, res) {
    console.log("dividing...")
    var calcid = req.query.calcId;
    var left = req.query.leftOp;
    var right = req.query.rightOp;

    var seg = xray.getSegment();
    seg.addAnnotation('calcid', calcid);

    var result = Number(left) / Number(right);
    console.log(`${left}/${right}=${result}`);
    res.write(result.toString());

    seg.addMetadata("left", left);
    seg.addMetadata("right", right);
    seg.addMetadata("operator", "/");
    seg.addMetadata("result", result);

    var responseCode = 200;
    var random = Math.random();

    //randomize response code
    if (random < 0.8) {
github cloudacademy / aws-xray-microservices-calc / node-subtract / server.js View on Github external
router.get("/subtract", function(req, res) {
    console.log("subtracting...");
    var calcid = req.query.calcId;    
    var left = req.query.leftOp;
    var right = req.query.rightOp;

    var seg = xray.getSegment();
    seg.addAnnotation('calcid', calcid);
    
    var result = Number(left) - Number(right);
    console.log(`${left}-${right}=${result}`);
    res.write(result.toString());

    seg.addMetadata("left", left);
    seg.addMetadata("right", right);
    seg.addMetadata("operator", "-");
    seg.addMetadata("result", result);

    var responseCode = 200;
    var random = Math.random();

    //randomize response code
    if (random < 0.8) {
github cloudacademy / aws-xray-microservices-calc / node-multiply / server.js View on Github external
router.get("/multiply", function(req, res) {
    console.log("multiplying...");
    var calcid = req.query.calcId;
    var left = req.query.leftOp;
    var right = req.query.rightOp;

    var seg = xray.getSegment();
    seg.addAnnotation('calcid', calcid);

    var result = Number(left) * Number(right);
    console.log(`${left}*${right}=${result}`);
    res.write(result.toString());

    seg.addMetadata("left", left);
    seg.addMetadata("right", right);
    seg.addMetadata("operator", "*");
    seg.addMetadata("result", result);

    var responseCode = 200;
    var random = Math.random();

    //randomize response code
    if (random < 0.8) {
github cloudacademy / aws-xray-microservices-calc / node-add / server.js View on Github external
router.get("/add", function(req, res) {
    console.log("adding...");
    var calcid  = req.query.calcId;
    var left    = req.query.leftOp;
    var right   = req.query.rightOp;

    var seg = xray.getSegment();
    seg.addAnnotation('calcid', calcid);

    var result = Number(left) + Number(right);
    console.log(`${left}+${right}=${result}`);
    res.write(result.toString());

    seg.addMetadata("left", left);
    seg.addMetadata("right", right);
    seg.addMetadata("operator", "+");
    seg.addMetadata("result", result);

    var responseCode = 200;
    var random = Math.random();

    //randomize response code
    if (random < 0.8) {