Skip to content

Exponential Histogram scale for data points can become erroneously low when using multiple sets of attributes #2000

@hibachrach

Description

@hibachrach

When recording values for a histogram to which an ExponentialBucketAggregation has been added as a aggregation, a normal sequence of measurements can lead to the histogram scale getting very low, often going below the minimum of -10. This seems to mostly occur when recording for more than one set of attributes.

Share details about your runtime

Operating system details: macOS Sequoia 15.7.2
RUBY_ENGINE: "ruby"
RUBY_VERSION: "3.2.7"
RUBY_DESCRIPTION: "ruby 3.2.7 (2025-02-04 revision 02ec315244) [arm64-darwin24]"

Share a simplified reproduction if possible

require 'bundler/inline'

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

  gem 'opentelemetry-api'
  gem 'opentelemetry-sdk'
  gem 'opentelemetry-metrics-sdk'
end

require 'opentelemetry-metrics-sdk'

OpenTelemetry::SDK.configure do |c|
  c.add_metric_reader(
    OpenTelemetry::SDK::Metrics::Export::PeriodicMetricReader.new(
      exporter: OpenTelemetry::SDK::Metrics::Export::ConsoleMetricPullExporter.new
    )
  )
end

OpenTelemetry.meter_provider.add_view(
  'example_hist',
  aggregation: OpenTelemetry::SDK::Metrics::Aggregation::ExponentialBucketHistogram.new
)
meter = OpenTelemetry.meter_provider.meter('exp-hist-bug')

hist = meter.create_histogram('example_hist')
attr1 = {foo: 1}
attr2 = {foo: 2}

hist.record(0.010359524076171637, attributes: attr1)
hist.record(0.006354922335082751, attributes: attr2)
hist.record(0.009615690848606532, attributes: attr1)
hist.record(0.00007659464778730196, attributes: attr1)
hist.record(0.0101281877195143937, attributes: attr2)

OpenTelemetry.tracer_provider.shutdown

This generated the log line

E, [2025-12-15T08:39:35.907901 #15628] ERROR -- : OpenTelemetry error: Scale -12 is smaller than minimum scale -10 - /Users/USERNAME/.rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/opentelemetry-metrics-sdk-0.11.2/lib/opentelemetry/sdk/metrics/aggregation/exponential_bucket_histogram.rb:344:in `validate_scale'

Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions