How to use the aws-xray-sdk-core.getSegment 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 humanmade / tachyon / index.js View on Github external
image.toBuffer(async (err, data, info) => {
				if (err) {
					reject(err);
				}

				// Pass PNG images through PNGQuant as Sharp is not good at compressing them.
				// See https://github.com/lovell/sharp/issues/478
				if ( info.format === 'png' ) {

					if ( enableTracing ) {
						var mainSegment = AWSXRay.getSegment();
						var segment = mainSegment.addNewSubsegment( 'imagemin-pngquant' );
					}

					data = await imageminPngquant()( data );

					if ( enableTracing ) {
						segment.close();
					}

					// Make sure we update the size in the info, to reflect the new
					// size after lossless-compression.
					info.size = data.length;
				}

				callback && callback(null, data, info);
				resolve({ data, info });
github aws-samples / voteapp / src / worker / main.js View on Github external
(async () => {
  try {
    await init();
    console.log('worker processing queue');
    while (true) {
      try {
        let msg = await consumer.receive();
        if (!msg) continue;
        console.log('message received: ', msg);
        let json = JSON.parse(msg);
        let res = await db.updateVote(json);
        console.log('message saved: %j', res);

        let segment = xray.getSegment();

        if (segment)
          xray.getSegment().close();

      } catch (err) {
        console.log(err);
      }
    }
  } catch (err) {
    console.log(err);
  } finally {
    try {
      await quit();
      console.log('worker stopped processing queue');
    } catch (err) {
      console.log(err);
github reimagined / resolve / packages / core / resolve-runtime / src / cloud / init-performance-tracer.js View on Github external
getSegment: () => {
        if (traceId !== process.env._X_AMZN_TRACE_ID) {
          traceId = process.env._X_AMZN_TRACE_ID
          segment = process.env.TRACE ? AWSXray.getSegment() : null
        }

        return {
          addNewSubsegment: subsegmentName => {
            const subsegment = process.env.TRACE
              ? segment.addNewSubsegment(subsegmentName)
              : null
            const prevSegment = segment
            segment = subsegment

            return {
              addAnnotation: (annotationName, data) => {
                if (process.env.TRACE) {
                  subsegment.addAnnotation(annotationName, data)
                }
              },
github vandium-io / vandium-node / lib / recorder / xray_recorder.js View on Github external
constructor() {

        super();

        this.segment = AWSXRay.getSegment().addNewSubsegment( 'vandium' );
    }
github aws-samples / voteapp / src / web / xray-axios.js View on Github external
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);

    return config;
  }, function (error) {
    var subsegment = xray.getSegment().addNewSubsegment("Intercept request error");
github DataDog / datadog-lambda-layer-js / src / trace / trace-context-service.ts View on Github external
get currentTraceContext(): TraceContext | undefined {
    if (this.rootTraceContext === undefined) {
      return;
    }
    const traceContext = { ...this.rootTraceContext };
    const datadogContext = this.tracerWrapper.traceContext();
    if (datadogContext) {
      logDebug(`set trace context from dd-trace with parent ${datadogContext.parentID}`);
      return datadogContext;
    }
    try {
      const xraySegment = getSegment();
      const value = convertToAPMParentID(xraySegment.id);
      if (value !== undefined) {
        logDebug(`set trace context from xray with parent ${value} from segment`);
        traceContext.parentID = value;
      }
    } catch (error) {
      logError("couldn't retrieve segment from xray", { innerError: error });
    }

    return traceContext;
  }
github DataDog / datadog-lambda-layer-js / src / trace / context.ts View on Github external
export function readTraceContextFromXray() {
  try {
    const segment = getSegment();
    const traceHeader = {
      parentID: segment.id,
      sampled: segment.notTraced ? 0 : 1,
      traceID: segment.trace_id,
    };
    return convertTraceContext(traceHeader);
  } catch (error) {
    logError("couldn't read xray trace header", { innerError: error });
  }
  return undefined;
}
github reimagined / resolve / packages / core / resolve-runtime / src / cloud / init-performance-tracer.js View on Github external
const initPerformanceTracer = resolve => {
  let segment = process.env.TRACE ? AWSXray.getSegment() : null
  let traceId = process.env._X_AMZN_TRACE_ID

  Object.defineProperty(resolve, 'performanceTracer', {
    value: {
      getSegment: () => {
        if (traceId !== process.env._X_AMZN_TRACE_ID) {
          traceId = process.env._X_AMZN_TRACE_ID
          segment = process.env.TRACE ? AWSXray.getSegment() : null
        }

        return {
          addNewSubsegment: subsegmentName => {
            const subsegment = process.env.TRACE
              ? segment.addNewSubsegment(subsegmentName)
              : null
            const prevSegment = segment
github aws-samples / voteapp / src / web / xray-axios.js View on Github external
}, function (error) {
    var subsegment = xray.getSegment().addNewSubsegment("Intercept request error");
    subsegment.close(error);

    return Promise.reject(error);
  });
github aws-samples / voteapp / src / web / xray-axios.js View on Github external
}, function (error) {
    var subsegment = xray.getSegment();
    subsegment.close(error);

    return Promise.reject(error);
  });
};