【问题标题】:How do I instrument additional functions in X-Ray with AWS Lambda function in Python?如何使用 Python 中的 AWS Lambda 函数检测 X-Ray 中的其他函数?
【发布时间】:2020-10-20 20:35:54
【问题描述】:

我正在尝试使用 X Ray 检测 AWS Lambda 函数。根据aws_xray_sdkofficial documentation,我无法检测处理函数之外的任何内容。如果我有以下示例代码:

from aws_xray_sdk.core import xray_recorder


@xray_recorder.capture("handler")
def my_handler(event, context):
  # some code here
  xray_recorder.begin_subsegment("my_function")
  my_function(params)
  xray_recorder.end_subsegment("my_function")
  return {"message": "done"}

@xray_recorder.capture("my_function")
def my_function(params):
  # do work

除了handler 之外,X 射线跟踪中没有检测到任何内容。我尝试了begin_subsegment 的不同组合,而my_function 上没有@xray_recorder.capture()my_function 似乎没有任何痕迹。我该如何解决这个问题?

【问题讨论】:

    标签: python amazon-web-services aws-lambda aws-xray


    【解决方案1】:

    请尝试更改

    xray_recorder.end_subsegment("my_function")
    

    xray_recorder.end_subsegment()
    

    【讨论】:

    • 另外注意AWS docs:“xray_recorder为每个线程保留一个段。因此,在手动模式下,在创建新段之前调用xray_recorder.end_segment(),否则新段会覆盖现有的段一个”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    • 1970-01-01
    • 2021-12-20
    • 2021-10-17
    相关资源
    最近更新 更多