Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS X-Ray: Is it possible to add the API Gateway call to the service map?

I've added X-ray instrumentation to my lambda(Node.js) and can see all services around it in the trace, but still cannot add the API Gateway calling it to the trace and the service map. Is there anyway to do it?

like image 311
Bachman Avatar asked Oct 30 '17 06:10

Bachman


2 Answers

A few days ago AWS announced the availability of X-Ray integration into API Gateway, so yes, getting the whole picture including API Gateway in X-Ray is possible now.

To enable the X-Ray integration in API Gateway, you can use the Management Console, the AWS CLI or do direct API calls.

With the management console open the Stage of an API you want to enable the X-Ray integration for, select the "Logs/Tracing" tab and select "Enable X-Ray Tracing" there as shown in the screenshot below:

How to enable X-Ray integration into API Gateway using the Management console

To enable the X-Ray integration using the AWS CLI instead, the official documentation sums it up pretty nicely:

To use the AWS CLI to enable active X-Ray tracing for an API that's already been deployed, call the update-stage command as follows:

aws apigateway update-stage          \
    --rest-api-id {rest-api-id}      \
    --stage-name {stage-name}      \
    --patch-operations op=replace,path=/tracingEnabled,value=true

After you enabled the X-Ray integration into your API Gateway API Stage, you'll see the API Gateway API Stage show up in the X-Ray service map.

like image 61
Dunedan Avatar answered Nov 13 '22 22:11

Dunedan


According to the X-Ray FAQ, X-Ray only supports the following services: EC2, ECS, Lambda, and Elastic Beanstalk. Until X-Ray adds API Gateway support, you won't be able to trace API Gateway calls w/X-Ray.

X-Ray docs say that metadata is added to AWS SDK calls made to AWS services, so you're seeing X-Ray trace data for other AWS services invoked by your Lambda function.

This X-Ray documentation says that API Gateway doesn't send trace data to X-Ray, so you can't use a similar method to what X-Ray provides for AWS SDKs. For instance, if you used X-Ray's PutTraceSegments operation right before invoking your API Gateway API, you'd end up with two separate traces for each invocation. It looks like you'll have to wait for X-Ray and API Gateway to integrate. Hopefully that happens soon.

like image 20
Mark Mucha Avatar answered Nov 14 '22 00:11

Mark Mucha