amazon-web-services - AWS X-Ray GoLang Lambda 到 lambda 跟踪并显示在服务 map 中

标签 amazon-web-services go aws-lambda aws-api-gateway aws-xray

我有调用 Lamdba 函数 1 并在 Go 中调用 lambda 函数 2 的 API 网关。我想在服务 map 中看到这两个功能。

到目前为止,我能够做到这一点的唯一方法是创建一个自定义段,例如称为“父”,并从该上下文创建一个子段,例如称为“子”。然后使用 client.InvokeWithContext 调用传递“子”段上下文的函数 2。

sess := session.Must(session.NewSession())
client := lambda.New(sess, &aws.Config{Region: aws.String(region)})

xray.Configure(xray.Config{LogLevel: "trace"})
xray.AWS(client.Client)

ctx, seg := xray.BeginSegment(context.Background(), "Parent")
ctx, subseg := xray.BeginSubsegment(ctx, "Child")
result, _ := client.InvokeWithContext(ctx, 
    lambda.InvokeInput{FunctionName: aws.String(functionName), Payload: nil})
subseg.Close(nil)   
seg.Close(nil)

问题是这会在服务映射中创建跟踪父级 -> 子级,但也具有功能 1。

请问在服务 map 上加入这两个功能的最佳方式是什么? 笔记。我想在服务 map 上看到超过 2 个链接,以向我展示我通过 lambdas 的整个流程。

请帮忙。

谢谢 瑞克

最佳答案

除非您想添加注释/元数据,否则您不需要为“子”调用添加子段。

API 网关将名为 X-Amzn-Trace-Id 的跟踪 ID 添加到传入请求的 header 中,X-ray 会拾取该 ID。如果您在调用中将该跟踪 ID 从 lambda 1 转发到 lambda 2,则 X 射线将在概览中使用从 lambda 1 到 lambda 2 的箭头直观地表示调用,并在查看跟踪详细信息时包括 lambda 2 的跟踪详细信息λ 1.

只要你通过调用链转发顶部的trace ID,X-ray就会正确地用节点和箭头将调用链从一个服务可视化到另一个服务。

来自 https://aws.amazon.com/xray/faqs/ :

Q: What is a trace?

An X-Ray trace is a set of data points that share the same trace ID. For example, when a client makes a request to your application, it is assigned a unique trace ID. As the request makes its way through services in your application, the services relay information regarding the request back to X-Ray using this unique trace ID. The piece of information relayed by each service in your application to X-Ray is a segment, and a trace is a collection of segments.

https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader

https://docs.aws.amazon.com/xray/latest/devguide/xray-services-apigateway.html

关于amazon-web-services - AWS X-Ray GoLang Lambda 到 lambda 跟踪并显示在服务 map 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49396352/

相关文章:

amazon-web-services - AWS Lambda@Edge Nodejs "Environment variables are not supported."

amazon-web-services - 在同一台机器或每台机器上运行多个图像/容器?

go - 如何在 Gorm 中模仿联合类型?

c - 如何使用 C.dll

amazon-web-services - 客户端错误: An error occurred (403) when calling the HeadObject operation: Forbidden

amazon-web-services - 如何在 CloudWatch Insights 查询中获取额外的上下文行?

amazon-web-services - aws s3 在一个命令中cp多个文件

data-structures - 在 golang 中实现嵌套矩阵的惯用方式

amazon-web-services - 如何在 aws lambda 机器上安装 ffmpeg?

aws-lambda - 当我尝试使用方法 OPTIONS 进行 CORS 预检 (Lambda) 时,AWS cloudformation template.yaml 失败