简体   繁体   中英

How do I instrument additional functions in X-Ray with AWS Lambda function in Python?

I am trying to instrument an AWS Lambda function using X Ray. According to the official documentation of the aws_xray_sdk , I can't instrument anything outside the handler function. If I have the following sample code:

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

nothing gets instrumented in X-Ray traces other than handler . I have tried with different combinations of begin_subsegment and not having @xray_recorder.capture() on my_function . Nothing seems to generate any traces for my_function . How do I work around this?

Please try to change

xray_recorder.end_subsegment("my_function")

to

xray_recorder.end_subsegment()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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