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

Metrics SDK initialization error with 'add_metric_reader' #1758

Open
GBoucher42 opened this issue Nov 6, 2024 · 1 comment
Open

Metrics SDK initialization error with 'add_metric_reader' #1758

GBoucher42 opened this issue Nov 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@GBoucher42
Copy link

Following along the Readme for the Metris SDK. There's an error when running OpenTelemetry.meter_provider.add_metric_reader

# Create an exporter. This example exports metrics to the console.
console_metric_exporter = OpenTelemetry::SDK::Metrics::Export::ConsoleMetricPullExporter.new

# Add the exporter to the meter provider as a new metric reader.
OpenTelemetry.meter_provider.add_metric_reader(console_metric_exporter)

# Create a meter to generate instruments.
meter = OpenTelemetry.meter_provider.meter("SAMPLE_METER_NAME")

The error is

 NoMethodError:
       undefined method `add_metric_reader' for an instance of OpenTelemetry::Internal::ProxyMeterProvider

When going through the code, in metrics_api/lib/opentelemetry/internal/proxy_meter_provider.rb we can see that there is indeed no method called add_metric_reader unlike what we see in metrics_sdk/lib/opentelemetry/sdk/metrics/meter_provider.rb.

The documentation should probably refer to OpenTelemetry::SDK::Metrics::MeterProvider instead of OpenTelemetry.meter_provider.

Share details about your runtime

RUBY_ENGINE: "ruby"
RUBY_VERSION: "3.3.5"

Share a simplified reproduction if possible
Exactly like the Metrics' SDK Readme

console_metric_exporter = OpenTelemetry::SDK::Metrics::Export::ConsoleMetricPullExporter.new

# Add the exporter to the meter provider as a new metric reader.
OpenTelemetry.meter_provider.add_metric_reader(console_metric_exporter)

# Create a meter to generate instruments.
meter = OpenTelemetry.meter_provider.meter("SAMPLE_METER_NAME")
@GBoucher42 GBoucher42 added the bug Something isn't working label Nov 6, 2024
@kaylareopelle
Copy link
Contributor

Hi @GBoucher42, thanks for bringing this to our attention!

This is puzzling. The OpenTelemetry::Internal::ProxyMeterProvider inherits from OpenTelemetry::SDK::Metrics::MeterProvider, so add_metric_reader should be brought in by the parent class.

I'm not able to reproduce the error locally on the latest version of the opentelemetry-metrics-sdk and and opentelemetry-metrics-api gems when I run those lines as part of the examples/metrics_sdk/metrics_collect.rb script.

I have a few questions to help us troubleshoot:

  • What versions of opentelemetry-related gems are you using?
  • Are you running the code in a script or within a web framework?
  • If you clone the repo on Ruby 3.3.5 and run the examples/metrics_sdk/metrics_collect.rb script, does the same error appear in your environment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants