How to use the aws-xray-sdk.captureAWS 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 pluto-net / scinapse-web-client / app / server / index.tsx View on Github external
const userType = getExpUserType(rawCookie || "");

  let bundledJsForBrowserPath: string;
  if (queryParamsObj && queryParamsObj.branch && queryParamsObj.branch === "master") {
    bundledJsForBrowserPath = `${DeployConfig.CDN_BASE_PATH}/${DeployConfig.AWS_S3_PRODUCTION_FOLDER_PREFIX}/${
      queryParamsObj.version
    }/bundleBrowser.js`;
    version = decodeURIComponent(queryParamsObj.branch);
  } else if (isDevDemoRequest) {
    bundledJsForBrowserPath = `${DeployConfig.CDN_BASE_PATH}/${
      DeployConfig.AWS_S3_DEV_FOLDER_PREFIX
    }/${decodeURIComponent(queryParamsObj.branch)}/bundleBrowser.js`;
    version = decodeURIComponent(queryParamsObj.branch);
  } else {
    AWSXRay.captureHTTPsGlobal(require("http"));
    AWSXRay.captureAWS(require("aws-sdk"));
    version = fs.readFileSync("./version").toString("utf8");
    bundledJsForBrowserPath = `${DeployConfig.CDN_BASE_PATH}/${
      DeployConfig.AWS_S3_PRODUCTION_FOLDER_PREFIX
    }/${version}/bundleBrowser.js`;
  }

  console.log(`The user requested at: ${path} with ${JSON.stringify(queryParamsObj)}`);

  // Handling '/robots.txt' path
  if (path === "/robots.txt") {
    return getResponseObjectForRobot(event.headers.host === "scinapse.io");
  }

  // handling '/sitemap' path
  if (path.search(SITEMAP_REGEX) !== -1) {
    return handleSiteMapRequest(path);
github nzoschke / gofaas / web / handlers / auth / index.js View on Github external
"use strict";
var AWSXRay = require("aws-xray-sdk");
var AWS = AWSXRay.captureAWS(require("aws-sdk"));
var GoogleStrategy = require("passport-google-oauth20").Strategy;
var jwt = require("jwt-simple");
var querystring = require("querystring");

AWSXRay.captureHTTPsGlobal(require("http"));

// global var reused across invocations
var Params = {
    AuthDomainName: undefined,
    AuthHashKey: undefined,
    OAuthClientId: undefined,
    OAuthClientSecret: undefined,
    Scope: [
        "https://www.googleapis.com/auth/plus.login",
        "https://www.googleapis.com/auth/userinfo.email",
    ],
github aws-samples / aws-serverless-workshops / DevOps / 3_XRay / uni-api / app / list.js View on Github external
'use strict';

const AWSXRay = require('aws-xray-sdk');
const AWS = AWSXRay.captureAWS(require('aws-sdk'));

const docClient = new AWS.DynamoDB.DocumentClient();
const tableName = process.env.TABLE_NAME;

function list_unicorns(callback) {
  var params = {
    TableName: tableName
  };

  AWSXRay.captureAsyncFunc('List Unicorns', (subsegment) => {
    docClient.scan(params, function(err, data) {
      // Comment or Delete the following line of code to remove simulated error
      err = Error("something is wrong");

      if (err) {
        callback(err, null, subsegment);
github Brikl / serverless-apollo-datasource-redis / handler.js View on Github external
import 'babel-polyfill';
const { ApolloServer, gql } = require('apollo-server-lambda');
const { RedisCache } = require('apollo-server-redis');
const { RESTDataSource } = require('apollo-datasource-rest');

const AWSXRay = require('aws-xray-sdk');
const AWS = AWSXRay.captureAWS(require('aws-sdk'));

class NYTIMESAPI extends RESTDataSource {
  baseURL = ' https://api.nytimes.com/svc/search/v2/articlesearch.json';  
  async searchNYArticle(q) {
    // https://api.nytimes.com/svc/search/v2/articlesearch.json
    const result = await this.get(`?q=${q}&api-key=${process.env.NY_TIMES_APIKEY}`);
    return result.response && result.response.docs ? result.response.docs : []    
  }
}

const typeDefs = gql`
  type Query {
    searchNYTimes(q: String): [Doc]
  }
  type Doc @cacheControl(maxAge: 6000) {
    web_url: String
github aws-samples / aws-workshop-for-kubernetes / 03-path-application-development / 306-app-tracing-with-jaeger-and-x-ray / x-ray / nodejs-microservices / name / server.js View on Github external
'use strict';

// Include the AWS X-Ray Node.js SDK and set configuration
var XRay = require('aws-xray-sdk');
var AWS = XRay.captureAWS(require('aws-sdk'));
const express = require('express');

// Constants
const PORT = 8080;
const HOST = '0.0.0.0';

AWS.config.region = process.env.REGION
XRay.config([XRay.plugins.EC2Plugin, XRay.plugins.ECSPlugin]);

// App
const app = express();
app.use(XRay.express.openSegment('name-svc'));


app.get('/*', (req, res) => {
  	var name = 'Arun';
github aws-samples / aws-xray-fargate / src / service-a / server.js View on Github external
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// A copy of the License is located at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

var XRay = require('aws-xray-sdk');
var AWS = XRay.captureAWS(require('aws-sdk'));
var http = XRay.captureHTTPs(require('http'));

const express = require('express');
var bodyParser = require('body-parser');
var queryString = require('querystring');


// Constants
const PORT = 8080;
const apiCNAME = process.env.API_CNAME || 'localhost';

// App
const app = express();

XRay.config([XRay.plugins.ECSPlugin]);
XRay.middleware.enableDynamicNaming();
github aws-samples / aws-serverless-workshops / DevOps / 3_XRay / uni-api / app / update.js View on Github external
'use strict';

const AWSXRay = require('aws-xray-sdk');
const AWS = AWSXRay.captureAWS(require('aws-sdk'));
const docClient = new AWS.DynamoDB.DocumentClient();

exports.lambda_handler = (event, context, callback) => {
  console.log('Received event:', JSON.stringify(event, null, 2));

  const tableName = process.env.TABLE_NAME;
  const unicorn = build_unicorn(event);

  var params = {
    TableName: tableName,
    Item: {
      name: unicorn.name,
      breed: unicorn.breed,
      description: unicorn.description
    }
  };
github ioxe / graphql-aws-iot-example / backend / todo-api / src / index.js View on Github external
import 'source-map-support/register';

import AWSXray from 'aws-xray-sdk';
const AWS = AWSXray.captureAWS(require('aws-sdk'));

import { SubscriptionManager, PubSub } from 'graphql-aws-iot-server';

import schema from './root.schema';

let db;
let manager;
let pubsub;

export const handler = (event, context, callback) => {
    console.log('Todo api handler running');
    console.log(JSON.stringify(event));

    if (!db) {
        db = new AWS.DynamoDB.DocumentClient();
    }
github aws-samples / aws-serverless-workshops / DevOps / 3_XRay / uni-api / app / delete.js View on Github external
'use strict';

const AWSXRay = require('aws-xray-sdk');
const AWS = AWSXRay.captureAWS(require('aws-sdk'));
const docClient = new AWS.DynamoDB.DocumentClient();
const tableName = process.env.TABLE_NAME;

exports.lambda_handler = (event, context, callback) => {
  console.log('Received event:', JSON.stringify(event, null, 2));
  const unicorn = build_unicorn(event);

  var params = {
    TableName: tableName,
    Key: {
      name: unicorn.name
    }
  };

  docClient.delete(params, function(err, data) {
    if (err) callback(err)
github theburningmonk / manning-aws-lambda-in-motion / functions / search-restaurants.js View on Github external
'use strict';

const co         = require('co');
const AWSXRay    = require('aws-xray-sdk');
const AWS        = AWSXRay.captureAWS(require('aws-sdk'));
const dynamodb   = new AWS.DynamoDB.DocumentClient();
const log        = require('../lib/log');
const cloudwatch = require('../lib/cloudwatch');
const wrapper    = require('../middleware/wrapper');

const defaultResults = process.env.defaultResults || 8;
const tableName      = process.env.restaurants_table;

function* findRestaurantsByTheme(theme, count) {
  let req = {
    TableName: tableName,
    Limit: count,
    FilterExpression: "contains(themes, :theme)",
    ExpressionAttributeValues: { ":theme": theme }
  };