0

I have a handful of Python Lambda functions with tracing enabled, they start like this:

import json
import boto3
from aws_xray_sdk.core import patch
from aws_xray_sdk.core import xray_recorder

patch(['boto3'])

def lambda_handler(event, context):
  ...

With this tracing works for every Lambda function itself and I can see the subservice calls to DynamoDB or Kinesis done through boto3.

But how can I connect various Lambda functions together in one trace? I'm thinking of generating a unique string in the first function and write it into the message stored in Kinesis. Another function would then pick up the string from the Kinesis' message and trace it again.

How would this be possible in a way to then see the whole connected trace in X-Ray?

Anton
  • 3,587
  • 2
  • 12
  • 27
Kim
  • 1,757
  • 1
  • 17
  • 32

1 Answers1

1

If your upstream service which invokes your Lambda functions has tracing enabled, your functions will automatically send traces. From your question, I'm not sure how your functions are invoked. If one function is directly invoking another function, you'll have a single trace for them.

For your approach of invoking lambdas with Kinesis messages, I'm not sure it would achieve what you want due to several reasons.Firstly, Kinesis is not integrated with X-Ray, which means it will not propagate the trace header to downstream lambda. Secondly, the segment and the trace header for a lambda function is not directly accessible from your function's code since it is generated by the lambda runtime upon invocation and is thus immutable. Explicitly overriding the trace id in a lambda function may result in undesired behavior of your service graph.

Thanks.

  • Thanks, yes the functions are invoked asynchronously via Kinesis stream events. I also encountered the issue where I wasn't able to change the Lambda X-Ray segments from inside my functions to add annotations for example. – Kim Apr 02 '20 at 08:01