How to use the aws-xray-sdk-core.captureAsyncFunc 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 UnaBiz / sigfox-gcloud / lib / aws.js View on Github external
return new Promise((resolve) => {
          //  Publish the message body as an AWS X-Ray annotation.
          //  This allows us to trace the message processing through AWS X-Ray.
          AWSXRay.captureAsyncFunc(topicName, (subsegment0) => {
            subsegment = subsegment0;
            try {
              const msg = JSON.parse(buffer.toString());
              const body = msg.body || msg;
              if (!body) {
                console.log('awsGetTopic', 'no_body');
                return resolve('no_body');
              }
              for (const key of Object.keys(body)) {
                //  Log only scalar values.
                const val = body[key];
                if (val === null || val === undefined) continue;
                if (typeof val === 'object') continue;
                subsegment.addAnnotation(key, val);
              }
            } catch (error) {
github luisfarzati / chromda / src / captureScreenshot.js View on Github external
exports.handler = async (event, callback) => {
  callback.callbackWaitsForEmptyEventLoop = false;

  /** @type {ChromdaOptions} */
  const options = normalizeEvent(event);

  // validate URL before wasting time waiting for Chrome to start
  new URL(options?.url);

  const browser = await puppetshot;

  await AWSXRay.captureAsyncFunc("navigate", async segment => {
    segment.addAnnotation("url", options.url);
    options.puppeteer?.navigation &&
      segment.addAnnotation(
        "options",
        JSON.stringify(options.puppeteer?.navigation)
      );
    await browser.navigate(options.url, options.puppeteer?.navigation);
    segment.close();
  });

  options.puppeteer?.viewport &&
    (await browser.resizeViewport(options.puppeteer.viewport));

  options.styles &&
    (await Promise.all([
      options.styles.map(style => browser.overrideStyles(style))
github aws-samples / aws-xray-kubernetes-serverless / lambda / index.js View on Github external
if (username !== "" && message !== "")
  {
    var id = Math.floor(new Date() / 1000);

    var params = {
      TableName: table,
      Item: {
        "id": id,
        "message": message,
        "username": username
      }
    };

    console.log("Adding a new message to DynamoDB: " + message);

    AWSXRay.captureAsyncFunc("## Writing to DynamoDB", function(subsegment) {
      docClient.put(params, function(err, data) {
        if (err) {
          console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
          responseBody.message = "Unable to add item. Error JSON:", JSON.stringify(err, null, 2);
          response.statusCode = 503;
        } else {
          console.log("Added item:", JSON.stringify(data, null, 2));
          responseBody.message = "Added item:", JSON.stringify(data, null, 2);
        }

        response.body = JSON.stringify(responseBody);
        console.log("response: " + JSON.stringify(response))

        callback(null, response);

        subsegment.close();
github simalexan / api-lambda-stripe-charge / src / tracing-repository.js View on Github external
return new Promise(function (resolve, reject) {
        AWSXRay.captureAsyncFunc(name, (segment) => {
            func(segment).then((result) => {
                segment.close();
                resolve(result);
            }, (error) => {
                segment.close(error);
                reject(error);
            });
        });
    });
}
github terodox / aws-xray-lambda-promise-subsegment / index.js View on Github external
return new Promise((resolve, reject) => {
        try {
            XRay.captureAsyncFunc(segmentName, (subSegment) => {
                try {
                    if (!subSegment) {
                        return promiseFactory()
                            .then(val => resolve(val))
                            .catch(err => reject(err));
                    } else {
                        addMetadata(subSegment, metadata);
                        addAnnotations(subSegment, annotations);

                        promiseFactory(subSegment)
                            .then(val => {
                                resolve(val);
                                subSegment.close();
                            })
                            .catch(err => {
                                reject(err);
github luisfarzati / chromda / src / captureScreenshot.js View on Github external
});

  options.puppeteer?.viewport &&
    (await browser.resizeViewport(options.puppeteer.viewport));

  options.styles &&
    (await Promise.all([
      options.styles.map(style => browser.overrideStyles(style))
    ]));

  options.exclude?.length && (await browser.excludeElements(options.exclude));

  const imageType = options.puppeteer?.screenshot?.type || "png";
  const capture = options.capture || "viewport";

  const buffer = await AWSXRay.captureAsyncFunc("screenshot", async segment => {
    segment.addAnnotation("capture", capture);

    /** @type {Buffer} */
    let buffer;

    switch (capture) {
      case "element":
        buffer = await browser.elementScreenshot(
          options.selector,
          options.puppeteer?.screenshot
        );
        break;
      case "page":
        buffer = await browser.pageScreenshot(options.puppeteer?.screenshot);
        break;
      case "viewport":