Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LWA + OpenTelemetry collector + zip Lambda deployment - is it possible? #568

Open
tmokmss opened this issue Jan 16, 2025 · 7 comments
Open

Comments

@tmokmss
Copy link
Contributor

tmokmss commented Jan 16, 2025

Hi, can we use LWA and OpenTelemetry collector together with zip Lambda deployment? I am afraid that we cannot because LWA and Otel collector both requires AWS_LAMBDA_EXEC_WRAPPER environment variable set to their binary path, but we can only set one single path for the variable.

Do you know if there is any workaround for this? Thanks.

P.S.) I confirmed that with Container Lambda deployment, we can use LWA + Otel without a problem. We can just copy multiple Lambda extension binaries to the /opt/extensions directory.

@tmokmss
Copy link
Contributor Author

tmokmss commented Jan 16, 2025

Nevermind. I misunderstood that AWS_LAMBDA_EXEC_WRAPPER is a path to binary but it turns out that it is just a shell script (lwa, otel, nodejs). I merged the two scripts and it is now apparently working.

@tmokmss tmokmss closed this as completed Jan 16, 2025
@tmokmss
Copy link
Contributor Author

tmokmss commented Jan 22, 2025

Hi @bnusunny
I'm currently trying this configuration on Lambda Node.js runtime, but now realized that things are not such simple.

So Lambda + otel seems to rely on AwsLambdaInstrumentation module to properly instrument a Lambda function, e.g. creating a span, by "patching" the Lambda handler function. But LWA apps do not have Lambda handler, (we have run.sh instead), the module fails to apply the patch, resulting in failed instrumentation (in X-Ray I can only see Lambda lifecycle events such as Init, Overhead, etc.)

I'm still trying to find a way to make it work properly, but do you have any information on this? e.g. a successful example of LWA + Otel configuration. Thanks.

@tmokmss tmokmss reopened this Jan 22, 2025
@bnusunny
Copy link
Contributor

bnusunny commented Jan 22, 2025

Since you are running a actual web app inside Lambda using LWA, you should instrument the web app in the normal way (such as this one), not following the Lambda function approach. I can create an example this weekend.

@tmokmss
Copy link
Contributor Author

tmokmss commented Jan 23, 2025

@bnusunny That's awesome, thanks! I think I tried the approach but it somehow didn't work; it appeared the span context was not propagated? still investigating though. I might have mesed up something so I'll wait for your test result 🙏

@bnusunny
Copy link
Contributor

bnusunny commented Jan 28, 2025

I got it working. Here are the configuration steps:

  1. install ADOT auto instrumentation lib:
npm install @aws/aws-distro-opentelemetry-node-autoinstrumentation
  1. attach ADOT layer to the function:
      Layers:
        - !Sub arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerX86:24
        - !Sub arn:aws:lambda:${AWS::Region}:901920570463:layer:aws-otel-nodejs-amd64-ver-1-30-1:1
  1. add configuration environment variables to the run.sh script
#!/bin/bash
export NODE_OPTIONS="--require @aws/aws-distro-opentelemetry-node-autoinstrumentation/register"
export OTEL_SERVICE_NAME=expressjs
exec node app.js

The ADOT collector batches the trace data by default. You need to invoke the functions multple times before the otel trace data show up in the x-ray.

Here is a sample trace.

Image

@tmokmss
Copy link
Contributor Author

tmokmss commented Jan 29, 2025

Thanks! I'll give it a try 👍

@tmokmss
Copy link
Contributor Author

tmokmss commented Feb 7, 2025

Hi @bnusunny could you share the full example code when you get a chance? Currently I cannot somehow get it work but not sure about the detailed difference with your configuration e.g. bundler option etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants