Skip to content

Commit bcb1caf

Browse files
committed
Revert "Revert "feat: Use an empty frozen hash as default advice""
This reverts commit ed4ceca.
1 parent ed4ceca commit bcb1caf

File tree

6 files changed

+9
-7
lines changed

6 files changed

+9
-7
lines changed

metrics_api/lib/opentelemetry/internal/proxy_instrument.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module OpenTelemetry
88
module Internal
99
# @api private
1010
class ProxyInstrument
11-
def initialize(kind, name, unit, desc, callable, advice = nil)
11+
def initialize(kind, name, unit, desc, callable, advice = Metrics::Meter::EMPTY_ADVICE)
1212
@kind = kind
1313
@name = name
1414
@unit = unit

metrics_api/lib/opentelemetry/metrics/meter.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class Meter
1515
UP_DOWN_COUNTER = Instrument::UpDownCounter.new
1616
OBSERVABLE_UP_DOWN_COUNTER = Instrument::ObservableUpDownCounter.new
1717

18+
EMPTY_ADVICE = {}.freeze
19+
1820
NAME_REGEX = /\A[a-zA-Z][-.\w]{0,62}\z/
1921

2022
private_constant(:COUNTER, :OBSERVABLE_COUNTER, :HISTOGRAM, :OBSERVABLE_GAUGE, :UP_DOWN_COUNTER, :OBSERVABLE_UP_DOWN_COUNTER)
@@ -33,7 +35,7 @@ def create_counter(name, unit: nil, description: nil)
3335
create_instrument(:counter, name, unit, description, nil) { COUNTER }
3436
end
3537

36-
def create_histogram(name, unit: nil, description: nil, advice: nil)
38+
def create_histogram(name, unit: nil, description: nil, advice: EMPTY_ADVICE)
3739
create_instrument(:histogram, name, unit, description, nil, advice) { HISTOGRAM }
3840
end
3941

@@ -55,7 +57,7 @@ def create_observable_up_down_counter(name, callback:, unit: nil, description: n
5557

5658
private
5759

58-
def create_instrument(kind, name, unit, description, callback, advice = nil)
60+
def create_instrument(kind, name, unit, description, callback, advice = EMPTY_ADVICE)
5961
raise InstrumentNameError if name.nil?
6062
raise InstrumentNameError if name.empty?
6163
raise InstrumentNameError unless NAME_REGEX.match?(name)

metrics_sdk/lib/opentelemetry/sdk/metrics/instrument/histogram.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Metrics
1010
module Instrument
1111
# {Histogram} is the SDK implementation of {OpenTelemetry::Metrics::Histogram}.
1212
class Histogram < OpenTelemetry::SDK::Metrics::Instrument::SynchronousInstrument
13-
def initialize(name, unit, description, instrumentation_scope, meter_provider, advice = nil)
13+
def initialize(name, unit, description, instrumentation_scope, meter_provider, advice = OpenTelemetry::Metrics::Meter::EMPTY_ADVICE)
1414
@advice = advice
1515

1616
super

metrics_sdk/lib/opentelemetry/sdk/metrics/instrument/synchronous_instrument.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Instrument
1111
# {SynchronousInstrument} contains the common functionality shared across
1212
# the synchronous instruments SDK instruments.
1313
class SynchronousInstrument
14-
def initialize(name, unit, description, instrumentation_scope, meter_provider, advice = nil)
14+
def initialize(name, unit, description, instrumentation_scope, meter_provider, advice = OpenTelemetry::Metrics::Meter::EMPTY_ADVICE)
1515
@name = name
1616
@unit = unit
1717
@description = description

metrics_sdk/lib/opentelemetry/sdk/metrics/meter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def add_metric_reader(metric_reader)
3333
end
3434
end
3535

36-
def create_instrument(kind, name, unit, description, callback, advice = nil)
36+
def create_instrument(kind, name, unit, description, callback, advice = OpenTelemetry::Metrics::Meter::EMPTY_ADVICE)
3737
super do
3838
case kind
3939
when :counter then OpenTelemetry::SDK::Metrics::Instrument::Counter.new(name, unit, description, @instrumentation_scope, @meter_provider)

metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
it 'does not require advice' do
3535
instrument = meter.create_histogram('histogram', description: 'stuff', unit: 'things')
3636

37-
assert_nil instrument.instance_variable_get(:@advice)
37+
assert_equal({}, instrument.instance_variable_get(:@advice))
3838
end
3939
end
4040

0 commit comments

Comments
 (0)