How to use the aws-xray-sdk-core.captureFunc 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 motdotla / node-lambda / test / handler / index.js View on Github external
exports.handler = (event, context, callback) => {
  // It changes to a boolean value with `!!`
  context.callbackWaitsForEmptyEventLoop =
    !!event.callbackWaitsForEmptyEventLoop

  if (event.asyncTest) {
    setTimeout(() => console.log('sleep 3500 msec'), 3500)
  }

  // https://docs.aws.amazon.com/xray/latest/devguide/scorekeep-lambda.html
  // For testing AWSXRay support
  AWSXRay.captureFunc('annotations', (subsegment) => {
    subsegment.addAnnotation('Name', 'name')
    subsegment.addAnnotation('UserID', 'piyo')
  })

  /* eslint-disable no-eval */
  eval(event.callbackCode)
}
github aws-samples / eb-java-scorekeep / _lambda / random-name / index.js View on Github external
var myFunction = function(event, context, callback) {
  var sns = new AWS.SNS();
  var chance = new Chance();
  var userid = event.userid;
  var name = chance.first();

  AWSXRay.captureFunc('annotations', function(subsegment){
    subsegment.addAnnotation('Name', name);
    subsegment.addAnnotation('UserID', event.userid);
  });

  // Notify
  var params = {
    Message: 'Created randon name "' + name + '"" for user "' + userid + '".',
    Subject: 'New user: ' + name,
    TopicArn: process.env.TOPIC_ARN
  };
  sns.publish(params, function(err, data) {
    if (err) {
      console.log(err, err.stack);
      callback(err);
    }
    else {
github DataDog / datadog-lambda-layer-js / src / trace / context.ts View on Github external
export function addTraceContextToXray(eventType: string, traceContext?: TraceContext) {
  let val: Record = {
    "event-source": eventType,
  };
  if (traceContext !== undefined) {
    val = {
      ...val,
      "parent-id": traceContext.parentID,
      "sampling-priority": traceContext.sampleMode.toString(10),
      "trace-id": traceContext.traceID,
    };
  }
  captureFunc(xraySubsegmentName, (segment) => {
    segment.addMetadata(xraySubsegmentKey, val, xraySubsegmentNamespace);
  });
}