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

2

7

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?

Destefano answered 30/10, 2017 at 6:39 Comment(0)
F
5

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.

Floor answered 30/10, 2017 at 6:47 Comment(2)
While this it true, I can see all my SNS, SQS, DynamoDB calls from my Lambda by just wrapping it with the X-Ray SDK. Is there anything similar for the API GW? It's clear to me that the Lambda does not call the API-GW and that it's the other way around. Thanks!Destefano
See the forums post here addressing this: forums.aws.amazon.com/thread.jspa?messageID=781548&#781548Vyner
Q
8

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.

Questor answered 9/9, 2018 at 13:52 Comment(6)
This should be the new accepted answer. By the way, did you run into any trouble with this? I've been trying to get this to work, but the API Gateway still does not show up in the traces. Something is happening though, because a) the "Clients" start node is not shown anymore, and b) everything downstream shows up, even if only set to passive tracing. I haven't been able to figure this one out yet.Nutrition
Worked flawlessly for me when I tried it out. As expected I got additional nodes representing the API Gateway methods in AWS X-Ray.Questor
Is there a way we can use cloudformation to enable x-ray in API GW?Sapphera
@ShubhamMittal Unfortunately the API Gateway resources for CloudFormation don't support it yet, so the only option to have to enable it via CloudFormation would be a custom resource.Questor
@Questor The support has been finally added! Adding it here for future viewers. See the TracingEnabled property: docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/…Sapphera
Anyone know how to enable this setting using the Typescript CDK?Pushing
F
5

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.

Floor answered 30/10, 2017 at 6:47 Comment(2)
While this it true, I can see all my SNS, SQS, DynamoDB calls from my Lambda by just wrapping it with the X-Ray SDK. Is there anything similar for the API GW? It's clear to me that the Lambda does not call the API-GW and that it's the other way around. Thanks!Destefano
See the forums post here addressing this: forums.aws.amazon.com/thread.jspa?messageID=781548&#781548Vyner

© 2022 - 2024 — McMap. All rights reserved.