How can I send xray trace id to API gateway on AWS?

1.6k views Asked by At

I have a lambda which has xray enabled and it sends http request to API gateway which links to another lambda. I also enabled xray in the API gateway. But it doesn't trace the whole flow because the trace id in the first lambda is not used by API Gateway.

My question is how I can send the trace id over http rest request? I'd like to link from end to end flow.

I am using axios in nodejs and I don't know how awsXRay.captureHTTPsGlobal works with this library.

2

There are 2 answers

3
Jason Dauxerre On BEST ANSWER

You can retrace the whole flow but you need manually capture the all HTTP/S external requests :

const awsXRay = require("aws-xray-sdk")
awsXRay.captureAWS(require("aws-sdk"))
awsXRay.captureHTTPsGlobal(require("http"))
awsXRay.captureHTTPsGlobal(require("https"))

And in your handler ( before making the HTTP request ) to allow the tracing of promise based requests ( Axios for example ) :

awsXRay.capturePromise()
2
Arun Kamalanathan On

The AWS Lambda has automatic instrumentation enabled, It means the calls to aws services are tracked. But when it comes to http(s) client, explicit instrumentation is necessary.

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

Tracing calls to downstream HTTP web services using the X-Ray SDK for Node.js