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
272 stars 166 forks source link

Does not work with custom metrics #1135

Open stevemao opened 7 months ago

stevemao commented 7 months ago

Describe the bug A clear and concise description of what the bug is.

Metrics is not exported.

Steps to reproduce If possible, provide a recipe for reproducing the error.

Step 1. follow https://opentelemetry.io/docs/faas/lambda-auto-instrument/ All default config. everything should be exported to log which should be visible on cloudwatch

Step 2. Add

import { metrics } from '@opentelemetry/api';

// Create a meter
export const meter = metrics.getMeter('your-metric-name');

// Define a counter metric
export const requestCounter = meter.createCounter('my-requests', {
  description: 'Counts number of requests processed',
});

requestCounter.add(1, { functionName: context.functionName });

In my lambda

What did you expect to see? A clear and concise description of what you expected to see.

metrics in log which should be in cloudwatch

What did you see instead? A clear and concise description of what you saw instead.

Only traces in the log, no metrics

What version of collector/language SDK version did you use? Version: (e.g., v0.58.0, v1.11.0, etc)

latest

What language layer did you use? Config: (e.g., Java, Python, etc)

Nodejs

Additional context Add any other context about the problem here.

stevemao commented 7 months ago

I notice it says Flush MeterProvider for nodejs is supported. so metrics should be flushed at the end of execution

stevemao commented 7 months ago

after https://github.com/open-telemetry/opentelemetry-lambda/pull/1136/files, it seems that logging works. But changing it to awsemf won't work. enable debugging by OTEL_LOG_LEVEL: 'DEBUG' won't log anything.

serkan-ozal commented 1 week ago

I think this might be fixed by https://github.com/open-telemetry/opentelemetry-lambda/pull/1504.

@pragmaticivan WDYT?

pragmaticivan commented 1 week ago

👋🏽 I noticed that the metrics instrumented by the auto-instrumentation packages are working because they register the current meger provider. So My last PR #1504 sets a global provider with the same reference which will allow us to create custom metrics in the code and use the same flush/view setup of the lambda layer.