open-telemetry / opentelemetry-lambda

Create your own Lambda Layer in each OTel language using this starter code. Add the Lambda Layer to your Lamdba Function to get tracing with OpenTelemetry.
https://opentelemetry.io
Apache License 2.0
277 stars 167 forks source link

GlobalOpenTelemetry.get() returns Noop implementation when using java lambda layer #1061

Closed Thul95 closed 2 months ago

Thul95 commented 9 months ago

Describe the bug When in AWS lambda using the java agent layer, both for layer v1 and v2. You can't access the Opentelemetry instance defined by the layer. GlobalOpenTelemetry.get() returns a DefaultOpenTelemetry{propagators=DefaultContextPropagators{textMapPropagator=NoopTextMapPropagator}}.

However my code is correctly instrumented and traces are being forwarded to my collector also context is correctly propagated/injected on to produced records on my Kafka topic.

Steps to reproduce Deploy AWS java lambda with layer arn:aws:lambda:${aws:region}:184161586896:layer:opentelemetry-javaagent-0_2_0:1. Add implementation("io.opentelemetry:opentelemetry-api:1.32.0") to the classpath and try to get the global opentelemetry instance using GlobalOpenTelemetry.get()

What did you expect to see? GlobalOpenTelemetry.get() returns the OpenTelemetry instance used by layer.

What did you see instead? GlobalOpenTelemetry.get() returns OpenTelemetry.noop()

What version of collector/language SDK version did you use?

What language layer did you use? Java 17

tylerbenson commented 8 months ago

You still need to add the javaagent or use the wrapper.

Try adding the following environment variable.

AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler
serkan-ozal commented 7 months ago

@Thul95 Yes, @tylerbenson is correct. You are missing setting AWS_LAMBDA_EXEC_WRAPPER environment variable. Otherwise, Java agent is not activated and in this case it is expected that there is no trace context started.

serkan-ozal commented 2 months ago

@tylerbenson I think this is not a bug, but misuse. Should we close this one?