Skip to content

fix: Move the logs-sdk and metrics-sdk requires#1956

Open
BrianHawley wants to merge 1 commit intoopen-telemetry:mainfrom
BrianHawley:fixes_1955
Open

fix: Move the logs-sdk and metrics-sdk requires#1956
BrianHawley wants to merge 1 commit intoopen-telemetry:mainfrom
BrianHawley:fixes_1955

Conversation

@BrianHawley
Copy link
Contributor

@BrianHawley BrianHawley commented Nov 8, 2025

This makes it so the logs and metrics will work when you require like

require 'opentelemetry/sdk/logs'
require 'opentelemetry/sdk/metrics'

Without requiring 'opentelemetry-logs-api' or 'opentelemetry-logs-metrics' earlier.

The opentelemetry-exporter-otlp-logs gem works around this, but I'm leaving that workaround there for now, so it will work with old versions of the opentelemetry-logs-sdk gem that are still locked.

Also added a missing require 'opentelemetry/sdk/metrics/version'.

To verify the fixes, I added require: false to the Gemfile files for the internal gem overrides. If you don't include require: false in the gem override declarations in the Gemfile, it will require those dependency files, which will hide bad requires in the code itself. If you specify require: false, the actual gem code requires will apply.

[Fixes #1955]

@BrianHawley BrianHawley changed the title Move the logs-sdk and metrics-sdk requires fix: Move the logs-sdk and metrics-sdk requires Nov 8, 2025
@BrianHawley
Copy link
Contributor Author

Looks like truffleruby is failing for unrelated reasons. I may look into that later.

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Nov 15, 2025

The test failures are unrelated, an incompatibility between Truffleruby and the latest json gem. So, until that gets fixed, the test suite isn't going to pass. What do we do next?

The test failures were fixed by #1959 so the tests pass now.

@BrianHawley BrianHawley force-pushed the fixes_1955 branch 3 times, most recently from 49d6a29 to 5924d40 Compare November 27, 2025 18:41
@kaylareopelle
Copy link
Contributor

kaylareopelle commented Dec 12, 2025

Hi @BrianHawley, thanks for your patience on this PR. I'm able to reproduce the bug you describe in #1955, but when I run the reproduction you have with this branch, the error still appears.

These are the contents of the Ruby file I'm using:

require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'

  gem 'opentelemetry-exporter-otlp-metrics', github: 'BrianHawley/opentelemetry-ruby', branch: 'fixes_1955', glob: 'exporter/otlp-metrics/*.gemspec'
end

require 'opentelemetry-exporter-otlp-metrics'

OpenTelemetry::SDK.configure do |c|
  c.use_all
end

This is the output:

Fetching https://github.com/BrianHawley/opentelemetry-ruby.git
Resolving dependencies...
Fetching gem metadata from https://rubygems.org/.../opentelemetry-api-1.7.0/lib/opentelemetry.rb:7: warning: logger was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add logger to your Gemfile or gemspec to silence this warning.
W, [2025-12-11T16:05:24.499438 #52700]  WARN -- : The otlp exporter cannot be configured - please add opentelemetry-exporter-otlp to your Gemfile, spans will not be exported
E, [2025-12-11T16:05:24.499588 #52700] ERROR -- : OpenTelemetry error: unexpected configuration error due to undefined method 'meter_provider=' for module OpenTelemetry - OpenTelemetry::SDK::ConfigurationError - .../opentelemetry-sdk-1.10.0/lib/opentelemetry/sdk.rb:74:in 'OpenTelemetry::SDK#configure'

Can you take a look? Am I misunderstanding what this PR addresses?

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Dec 13, 2025

@kaylareopelle I didn't reference the actual fixed gems in my reproduction example. Instead, I referenced the gem that you would normally reference to turn on metrics export. The actual gems with the bugs are opentelemetry-metrics-sdk and opentelemetry-logs-sdk.

So the fix proof script would be:

require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'

  gem 'opentelemetry-exporter-otlp-metrics' # the gem you would normally reference directly

  # The dependency with the bug, referenced here so you can use the fixed version. You need to
  # have require: false because otherwise bundler will require 'opentelemetry-metrics-sdk', which
  # works around the bug. If the gem is referenced indirectly, 'opentelemetry/sdk/metrics' is
  # required instead, as is the custom for these gems.
  gem 'opentelemetry-metrics-sdk',
    require: false,
    github: 'BrianHawley/opentelemetry-ruby',
    branch: 'fixes_1955',
    glob: 'metrics_sdk/*.gemspec'
end

require 'opentelemetry-exporter-otlp-metrics'

OpenTelemetry::SDK.configure do |c|
  c.use_all
end

Another option for the fix would be to move the logger_provider stuff from logs_api/lib/opentelemetry-logs-api.rb to logs_api/lib/opentelemetry/logs.rb, and move the meter_provider stuff from metrics_api/lib/opentelemetry-metrics-api.rb to metrics_api/lib/opentelemetry/metrics.rb. This would make the organization of the code more consistent with the opentelemetry-api and opentelemetry-sdk gems. I didn't make those changes because they are more extensive, but I can do them as well if you prefer.

@BrianHawley BrianHawley force-pushed the fixes_1955 branch 2 times, most recently from 5058334 to 8e68031 Compare December 13, 2025 21:54
@BrianHawley
Copy link
Contributor Author

BrianHawley commented Dec 13, 2025

I also added require: false to the Gemfile gem overrides so the tests should catch problems like this going forward.

@BrianHawley BrianHawley force-pushed the fixes_1955 branch 4 times, most recently from 9658c37 to 9c940a4 Compare January 10, 2026 02:09
This makes it so the logs and metrics will work when you require like
```ruby
require 'opentelemetry/sdk/logs'
require 'opentelemetry/sdk/metrics'
```
Without getting 'opentelemetry-logs-api' or 'opentelemetry-logs-metrics'
earlier.

The opentelemetry-exporter-otlp-logs gem works around this, but I'm
leaving that workaround there for now, so it will work with old versions
of the opentelemetry-logs-sdk gem that are still locked.

Also added a missing `require 'opentelemetry/sdk/metrics/version'`.

To verify the fixes, I added `require: false` to the Gemfile files for
the internal gem overrides. If you don't include `require: false`
in the gem override declarations in the Gemfile, it will require those
dependency files, which will hide bad requires in the code itself. If
you specify `require: false`, the actual gem code requires will apply.

[Fixes open-telemetry#1955]
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

Successfully merging this pull request may close these issues.

Requires in the wrong place in opentelemetry-logs-sdk and opentelemetry-metrics-sdk

2 participants