AWS X-Ray Investigation

January 15, 2017 #aws #xray #javascript #monitoring

In Zipkin JS Investigation and Zipkin JS Investigation (Part 2), I took a simple Express (Node.js) based web application and added zipkin tracing. I updated that application with support for AWS X-Ray (Preview).   The code snippet below was based on instructions found at

var express = require('express');
var http = require('http');
var AWSXRay = require('aws-xray-sdk');

var AWS = AWSXRay.captureAWS(require('aws-sdk'));
var app = express();
app.set('port', process.env.PORT || 3000);
app.set('servicename', 'helloservice');

// below not working, need to start with: XRAY_TRACING_NAME=helloservice node index.js

app.get('/', function (req, res) {
 // handler code here uses http.request()

Looking on the X-Ray Console, here is a screenshot of the result of calling: I have also included the raw JSON data for this trace.

X-Ray Trace Timeline

Amazon uses the X-Amzn-Trace-Id HTTP header with Root and Parent segments for carrying trace ids (see Request Tracing for Your Application Load Balancer for syntax).  For example:

X-Amzn-Trace-Id: Root=1-587c35e2-c21cf7e73003b660d10e33ea; Parent=06b7ad9dfdae682a; Sampled=1

To learn more about AWS X-Ray, you can watch AWS re:Invent 2016: NEW LAUNCH! Introduction to AWS X-Ray (DEV316) - YouTube.

Kevin Hakanson

Multi-Cloud Certified Architect | DevSecOps | AppSec | Web Platform | Speaker | Learner | Builder
Twitter | LinkedIn | GitHub | Stack Overflow | Credly

© 2024 Kevin Hakanson (built with Gatsby)