简体   繁体   English

AWS Xray:无法在 Lambda 函数内创建分段并且找不到分段

[英]AWS Xray: Cannot create segments inside Lambda function and segment not found

A really strange behaviour I was experiencing, I am following online documentation and while creating a segment to work with my subsegment, the lambda executes in following order:我遇到了一个非常奇怪的行为,我正在关注在线文档并在创建一个段以使用我的子段时,lambda 按以下顺序执行:

xray_recorder.begin_segment('segment-name')
xray_recorder.begin_subsegment('subsegment-name')
# put annotations and meta data etc
xray_recorder.end_segment('segment-name')
xray_recorder.end_subsegment('subsegment-name')

but I get following error on CloudWatch Manager :但我在CloudWatch Manager上收到以下错误:

Cannot create segments inside Lambda function. Discarded.

When I remove segment creation and try running things locally like this:当我删除段创建并尝试像这样在本地运行时:

xray_recorder.begin_subsegment('subsegment-name')
# put annotations and meta data etc
xray_recorder.end_segment('segment-name')

I get the error: SegmentNotFoundException: cannot find the current segment/subsegment, please make sure you have a segment open我收到错误:SegmentNotFoundException:找不到当前段/子段,请确保您打开了一个段

Confusing.令人困惑。

While running locally xray segments are created locally and you have to initiate segments for creating sub-segments but while running on lambda on AWS, the segments are created by default and you can proceed with sub-segments.在本地运行时,xray 分段是在本地创建的,您必须启动分段以创建子分段,但在 AWS 上的 lambda 上运行时,分段是默认创建的,您可以继续创建子分段。

Locally I was running into errors while omitting the creation of segments while it worked fine remotely.在本地我遇到了错误,同时在远程工作正常时省略了段的创建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM