How to use aws-xray-sdk-express - 8 common examples

To help you get started, we’ve selected a few aws-xray-sdk-express 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 / app.js View on Github external
console.log('GET /results');
    console.log(`web -> GET ${reportsURI}/results`);
    let result = await reportsAPI.get('/results');
    console.log('resp: %j', result.data);
    // result.data contains an object
    // { success: , result: { voter_id: , vote: } }
    // Just passing response through
    // Expect an object with vote count: { success: true, result: { a: X, b: X } }
    res.send(result.data);
  } catch (err) {
    console.log('ERROR: GET /results: %s', err.message || err.response || err);
    res.status(500).send({ success: false, reason: 'internal error' });
  }
});

app.use(xrayExpress.closeSegment());

// initialize and start running
(async () => {
  try {
    await new Promise(resolve => {
      server.listen(port, () => {
        console.log(`listening on port ${port}`);
        resolve();
      });
    });

  } catch (err) {
    console.log(err);
    process.exit(1);
  }
})();
github aws-samples / voteapp / src / database-proxy / app.js View on Github external
});

// results route handler
app.get('/results', async (req, res) => {
  try {
    console.log('GET /results');
    let result = await db.tallyVotes();
    console.log('results: %j', result);
    res.send({ success: true, result: result });
  } catch (err) {
    console.log('ERROR GET /results: %j', err);
    res.send(500, { success: false, reason: err.message });
  }
});

app.use(xrayExpress.closeSegment());

// initialize and start running
(async () => {
  try {
    // initialize database client for querying vote results
    db = new Database(databaseConfig);
    console.log(`connecting to database at (${db.connectionURL})`);
    await db.connect();
    console.log(`connected to database (${db.connectionURL})`);
    server.listen(port, () => console.log(`listening on port ${port}`));
  } catch (err) {
    console.log(err);
    process.exit(1);
  }
})();
github aws-samples / voteapp / src / reports / app.js View on Github external
let r = data.result; 
      console.log(`data: ${r}`)
      r.totalVotes = r.a + r.b;
      r.version = "2.0"
    // ex: { success: true, result: { a: X, b: X, totalVotes: X } }
      console.log(`v2 data: ${r}`)
    }

    res.send(data);
  } catch (err) {
    console.log('ERROR: GET /results: %s', err.message || err.response || err);
    res.status(500).send({ success: false, reason: 'internal error' });
  }
});

app.use(xrayExpress.closeSegment());

// initialize and start running
(async () => {
  try {
    await new Promise(resolve => {
      server.listen(port, () => {
        console.log(`listening on port ${port}`);
        resolve();
      });
    });
  
  } catch (err) {
    console.log(err);
    process.exit(1);
  }
})();
github aws-samples / voteapp / src / votes / app.js View on Github external
try {
    console.log('POST /vote: %j', req.body);
    let v = req.body;
    let result = await ax.post('/vote', v);
    let data = result.data;
    // result.data contains an object
    // { success: , result: { voter_id: , vote: } }
    console.log('data: ', data);
    res.send(data);
  } catch (err) {
    console.log('ERROR: POST /vote:', err);
    res.status(500).send({ success: false, reason: err.message })
  }
});

app.use(xrayExpress.closeSegment());

// initialize and start running
(async () => {
  try {
    await new Promise(resolve => {
      server.listen(port, () => {
        console.log(`listening on port ${port}`);
        resolve();
      });
    });
  
  } catch (err) {
    console.log(err);
    process.exit(1);
  }
})();
github aws-samples / voteapp / src / reports / app.js View on Github external
const captureAxios = require('./xray-axios');

let ax = axios.create({
    baseURL: process.env.DATABASE_PROXY_URI || 'http://database-proxy:3000/'
});

captureAxios(ax);

// install route logging middleware
app.use(morgan('dev'));

// install json body parsing middleware
app.use(express.json());

// install x-ray tracing
app.use(xrayExpress.openSegment('reports.app'));

// root route handler
app.get('/', (_, res) => {
  return res.send({ success: true, result: 'hello'});
});

// results route handler
app.get('/results', async (_, res) => {
  try {
    console.log('GET /results');
    let result = await ax.get('/results');
    let data = result.data;
    // ex: { success: true, result: { a: X, b: X } }
    console.log('data: ', data);

    // append version 2 extra field
github aws-samples / voteapp / src / database-proxy / app.js View on Github external
const port = process.env.PORT || 3000;
const app = express();
const server = http.createServer(app);

let databaseConfig = Database.createStdConfig();
let db;

// install route logging middleware
app.use(morgan('dev'));

// install json body parsing middleware
app.use(express.json());

// install x-ray tracing
app.use(xrayExpress.openSegment('database-proxy.app'));

// root route handler
app.get('/', (_, res) => {
  return res.send({ success: true, result: 'hello'});
});

// vote route handler
app.post('/vote', async (req, res) => {
  try {
    console.log('POST /vote: %j', req.body);
    let v = req.body;
    let result = await db.updateVote(v);
    console.log('stored :', result);
    res.send({ success: true, result: {
      voter_id: result.voter_id,
      vote: result.vote
github aws-samples / voteapp / src / web / app.js View on Github external
let reportsURI = process.env.REPORTS_URI || 'http://reports:3000/';
let reportsAPI = axios.create({
    baseURL: reportsURI
});

captureAxios(votesAPI);
captureAxios(reportsAPI);

// install route logging middleware
app.use(morgan('dev'));

// install json body parsing middleware
app.use(express.json());

// install x-ray tracing
app.use(xrayExpress.openSegment('web.app'));

// root route handler
app.get('/', (req, res) => {
  return res.send({ success: true, result: 'hello'});
});

// vote route handler
app.post('/vote', async (req, res) => {
  try {
    console.log('POST /vote: %j', req.body);
    let v = { vote: req.body.vote };
    let result = await votesAPI.post('/vote', v);
    // result.data contains an object
    // { success: , result: { voter_id: , vote: } }
    let data = result.data;
    console.log('posted vote: %j', data);
github aws-samples / voteapp / src / votes / app.js View on Github external
const captureAxios = require('./xray-axios');

let ax = axios.create({
    baseURL: process.env.DATABASE_PROXY_URI || 'http://database-proxy:3000/'
});

captureAxios(ax);

// route logging middleware
app.use(morgan('dev'));

// json body parsing middleware
app.use(express.json());

// install x-ray tracing
app.use(xrayExpress.openSegment('votes.app'));

// root route handler
app.get('/', (req, res) => {
  return res.send({ success: true, result: 'hello'});
});

// vote route handler
app.post('/vote', async (req, res) => {
  try {
    console.log('POST /vote: %j', req.body);
    let v = req.body;
    let result = await ax.post('/vote', v);
    let data = result.data;
    // result.data contains an object
    // { success: , result: { voter_id: , vote: } }
    console.log('data: ', data);

aws-xray-sdk-express

AWS X-Ray Middleware for Express (Javascript)

Apache-2.0
Latest version published 9 days ago

Package Health Score

77 / 100
Full package analysis