1

I am building lambdas and using xray to check performance. My lambda will write to other dynamodb tables where trigger another lambda via streaming. The other lambda will carry that event and publish the data in RDS as well as external application.

I'd like to put trace data in this flow to trace the whole process. I know that AWS has build-in support to enable xray in lambda. But it doesn't cover the whole event flow in my application. Is there a way for me to manually set up a trace ID in the event and make xray to use this ID to trace the event flow?

If can I manually push trace to xray, how can I make the dynamodb streaming use the trace id to trigger a lambda?

Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
  • this question returns for my search, so FWIW -- you can't use your own custom trace ids unless they conform to [xrays spec](https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html#xray-api-traceids). so if you're already generating a trace id, you'll need to create a mapping somewhere. – Cory Mawhorter May 30 '22 at 18:14

3 Answers3

0

You can do it using a trace ID! The trace ID tracks the request as it travels between services.

Here you have more information about how to use that: https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html

Keep rocking!

Jonathan Brizio
  • 1,087
  • 1
  • 14
  • 28
  • 2
    That sounds a good solution. But in my case, how can I let dynamodb stream to carry the trace ID to trigger my lambda? I'd like to use the same trace id from the lambda saving data to dynamodb and receiving streaming update event in another lambda. – Joey Yi Zhao Aug 29 '20 at 05:20
  • @JoeyYiZhao Did you ever figure this out? I think it's a valid question. Trace ID's don't seem to be generated for non-API Gateway Events. I know locally you can set an env var for this, but not sure if it works - I'll put it as an answer and we can go from there. – Matt Rowles Dec 17 '20 at 22:53
0

Tracing of DynamoDB streams is not yet supported with X-Ray. For your application structure, if you have active tracing enabled on both the lambdas and have instrumented the downstream AWS service calls (DDB in your case), you'd see a trace map like this (disconnected at DDB stream event):

client -> Lambda -> LambdaFunction_A -> DDB

client -> Lambda -> LambdaFunction_B -> RDS

This is because DDB streams currently do not propagate the trace header which is required for end-to-end tracing.

Another limitation is that Lambda function invocation generates its own trace id if one is not passed in from upstream. You cannot overwrite this trace id from within the lambda function.

0

Locally for Serverless, it is recommended you use environment variables:

# Required for XRAY tracing to work locally
export AWS_XRAY_CONTEXT_MISSING=LOG_ERROR
export _X_AMZN_TRACE_ID=some_uuid
export DISABLE_XRAY_TRACING=1

Does this work remotely for lambdas that are triggered off of non-API Gateway events? e.g., in your code:

process.env._X_AMZN_TRACE_ID=abc-123; // some UUID

I have a related question

Matt Rowles
  • 7,721
  • 18
  • 55
  • 88