I'm attempting to build a serverless application using AWS APIGateway/Lambda function integration.
I have the following setup:
* Two APIGateway resources. Calling them service A and service B for now.
* Two Lambda functions which act the the backend, responsible for processing the requests from APIGateway. Calling them LambdaFunction A and LambdaFunction B for now.
ServiceA -> LambdaFunctionA
ServiceB -> LambdaFunctionB
ServiceA->ServiceB
Now, as per the setup serviceA can call ServiceB. I would like to trace a request originating from serviceA to serviceB. One of the ways I was thinking to do this is through requestIds. I was attempting to see if there's some specific way to persist/explicitly provide requestIds when serviceA calls serviceB? I looked up AWS docs and couldn't find any specific mechanism on this.
The other alternative I had was to integration my Lambda functions with Xray and then maybe pass the requestId in the Xray context map/trace. I doubt I'm the first person attempting to trace requests across multiple Lambda functions and thought there would be a mechanism to do this already in place. Any help would be greatly appreciated!
AWS X-Ray already uses trace ids that are used for context propagation across two resources in your case servicea and serviceb. For API Gateway and Lambda the context propagation for trace id is automatic if you have X-Ray enabled on your entry point api gateway or lambda. A trace id generated for you by the X-Ray SDK in API Gateway or lambda is used to uniquely identify a request. If you have a custom request id you can additionally add it to the X-Ray segments as annotations.