How to use the aws-xray-sdk-core.SegmentUtils function in aws-xray-sdk-core

To help you get started, we’ve selected a few aws-xray-sdk-core 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 / voteapp / src / web / xray-axios.js View on Github external
const xray = require('aws-xray-sdk-core');
const segmentUtils = xray.SegmentUtils;

let captureAxios = function(axios) {

  //add a request interceptor on POST
  axios.interceptors.request.use(function (config) {
    var parent = xray.getSegment();
    var subsegment = parent.addNewSubsegment(config.baseURL + config.url.substr(1));
    subsegment.namespace = 'remote';

    let root = parent.segment ? parent.segment : parent;
    let header = 'Root=' + root.trace_id + ';Parent=' + subsegment.id + ';Sampled=' + (!root.notTraced ? '1' : '0');
    config.headers.get={ 'x-amzn-trace-id': header };
    config.headers.post={ 'x-amzn-trace-id': header };

    xray.setSegment(subsegment);