1

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?

1 Answer 1

1

Please try to change

xray_recorder.end_subsegment("my_function")

to

xray_recorder.end_subsegment()
Sign up to request clarification or add additional context in comments.

1 Comment

Also note per the AWS docs: "The xray_recorder keeps one segment per thread. Therefore, in manual mode, call xray_recorder.end_segment() before creating a new segment, otherwise the new segment overwrites the existing one"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.