AWS X-Ray:是否可以将 API 网关调用添加到服务地图?

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

我已将 X 射线检测添加到我的 lambda(Node.js) 并且可以在跟踪中看到它周围的所有服务,但仍然无法将调用它的 API 网关添加到跟踪中和服务地图。有办法吗?

根据 X-Ray FAQ,X-Ray 仅支持以下服务:EC2、ECS、Lambda 和 Elastic Beanstalk。在 X-Ray 添加 API 网关支持之前,您将无法跟踪 API 网关调用 w/X-Ray。

X-Ray 文档说元数据已添加到对 AWS 服务进行的 AWS SDK 调用中,因此您会看到由您的 Lambda 函数调用的其他 AWS 服务的 X-Ray 跟踪数据。

X-Ray documentation 表示 API 网关不会将跟踪数据发送到 X-Ray,因此您不能使用类似于 X-Ray 为 AWS SDK 提供的方法。例如,如果您在调用 API 网关 API 之前使用了 X-Ray 的 PutTraceSegments 操作,那么每次调用都会得到两个单独的跟踪。看来您必须等待 X-Ray 和 API Gateway 集成。希望这很快就会发生。

几天前 AWS announced X-Ray 集成到 API Gateway 中的可用性,所以是的,现在可以在 X-Ray 中获取包括 API Gateway 在内的全貌.

要在 API 网关中启用 X-Ray 集成,您可以使用管理控制台、AWS CLI 或直接 API 调用。

使用管理控制台打开您要为其启用 X-Ray 集成的 API 的舞台,select “Logs/Tracing”选项卡和 select“启用 X 射线跟踪”,如下面的屏幕截图所示:

要改为使用 AWS CLI 启用 X-Ray 集成,official documentation 总结得非常好:

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

在您启用 X-Ray 集成到您的 API 网关 API 舞台后,您将看到 API 网关 API 舞台出现在 X -雷服地图.