Amazon API Gateway API 的 Amazon X-Ray 跟踪 - Amazon API Gateway
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

Amazon API Gateway API 的 Amazon X-Ray 跟踪

本部分讨论 Amazon API Gateway API 的 Amazon X-Ray 跟踪分段、子段和其他跟踪字段。

阅读本节之前,请查看《X-Ray 开发人员指南》中的以下主题中:

针对 API Gateway API 的跟踪对象示例

本节讨论您可能在 API Gateway API 跟踪中看到的一些对象。

注释

注解可在分段和子分段中出现。它们在采样规则中用作过滤表达式,以过滤跟踪。有关更多信息,请参阅配置采样规则

下面是 annotations 对象的一个示例,其中,API 阶段由 API ID 和 API 阶段名称标识:

"annotations": { "aws:api_id": "a1b2c3d4e5", "aws:api_stage": "dev" }

有关注释的更多信息,请参阅 X-Ray 分段文档,然后依次选择 X-Ray 分段文档注释

Amazon 资源数据

aws 对象仅存在于分段中。以下是与默认的取样规则匹配的 aws 对象的一个示例。有关采样规则的深入说明,请参阅配置采样规则

"aws": { "xray": { "sampling_rule_name": "Default" }, "api_gateway": { "account_id": "123412341234", "rest_api_id": "a1b2c3d4e5", "stage": "dev", "request_id": "a1b2c3d4-a1b2-a1b2-a1b2-a1b2c3d4e5f6" } }

有关 aws 对象的更多信息,请参阅 X-Ray 分段文档,然后依次选择 X-Ray 分段文档Amazon 资源数据

了解跟踪

以下是 API Gateway 阶段的跟踪分段。有关组成跟踪分段的字段的详细说明,请参阅 X-Ray 分段文档

{ "Document": { "id": "a1b2c3d4a1b2c3d4", "name": "testxray/dev", "start_time": 1533928226.229, "end_time": 1533928226.614, "metadata": { "default": { "extended_request_id": "abcde12345abcde=", "request_id": "a1b2c3d4-a1b2-a1b2-a1b2-a1b2c3d4e5f6" } }, "http": { "request": { "url": "https://example.com/dev?username=demo&message=hellofromdemo/", "method": "GET", "client_ip": "192.0.2.0", "x_forwarded_for": true }, "response": { "status": 200, "content_length": 0 } }, "aws": { "xray": { "sampling_rule_name": "Default" }, "api_gateway": { "account_id": "123412341234", "rest_api_id": "a1b2c3d4e5", "stage": "dev", "request_id": "a1b2c3d4-a1b2-a1b2-a1b2-a1b2c3d4e5f6" } }, "annotations": { "aws:api_id": "a1b2c3d4e5", "aws:api_stage": "dev" }, "trace_id": "1-a1b2c3d4-a1b2c3d4a1b2c3d4a1b2c3d4", "origin": "AWS::ApiGateway::Stage", "resource_arn": "arn:aws:apigateway:us-east-1::/restapis/a1b2c3d4e5/stages/dev", "subsegments": [ { "id": "abcdefgh12345678", "name": "Lambda", "start_time": 1533928226.233, "end_time": 1533928226.6130002, "http": { "request": { "url": "https://example.com/2015-03-31/functions/arn:aws:lambda:us-east-1:123412341234:function:xray123/invocations", "method": "GET" }, "response": { "status": 200, "content_length": 62 } }, "aws": { "function_name": "xray123", "region": "us-east-1", "operation": "Invoke", "resource_names": [ "xray123" ] }, "namespace": "aws" } ] }, "Id": "a1b2c3d4a1b2c3d4" }