- Create a new lambda function and call it "otel-js-perf"
- Choose the Node.js 14.x runtime
- In this repo, run
npm install
followed bysh upload.sh
- Add a layer to the lambda function, use the appropriate region: https://aws-otel.github.io/docs/getting-started/lambda/lambda-js
- Set the environment variable
NODE_OPTIONS
to--require src/tracing
- Enable "Active tracing" under Configuration > Monitoring
- Ensure the lambda execution role has permission to create XRay traces, the Console should automatically do this for you at Step (7)
- Increase the timeout to 30 seconds under Configuration > General
- Run a test
- Open X-Ray to find the trace your function created. It will resemble this:
- The function takes around 3 seconds to execute with instrumentation
- and roughly 1 second without
- You can experiment by:
- Removing the lambda layer
- Removing the NODE_OPTIONS env var
- Both of the above
- Generally I have found the following performance impacts:
- The lambda layer adds ~300ms
- The tracing.js file adds 500-700ms
- Sometimes, there is ~1000ms of unexplained time after the handler has exited
- Be aware of when your test is running cold or warm
- if warm, the "Initialization" span will be missing, and the function completes much quicker