Skip to content

Commit

Permalink
Revert "Revert "feat: Use an empty frozen hash as default advice""
Browse files Browse the repository at this point in the history
This reverts commit ed4ceca.
  • Loading branch information
kaylareopelle committed Sep 19, 2024
1 parent ed4ceca commit bcb1caf
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion metrics_api/lib/opentelemetry/internal/proxy_instrument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module OpenTelemetry
module Internal
# @api private
class ProxyInstrument
def initialize(kind, name, unit, desc, callable, advice = nil)
def initialize(kind, name, unit, desc, callable, advice = Metrics::Meter::EMPTY_ADVICE)
@kind = kind
@name = name
@unit = unit
Expand Down
6 changes: 4 additions & 2 deletions metrics_api/lib/opentelemetry/metrics/meter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Meter
UP_DOWN_COUNTER = Instrument::UpDownCounter.new
OBSERVABLE_UP_DOWN_COUNTER = Instrument::ObservableUpDownCounter.new

EMPTY_ADVICE = {}.freeze

NAME_REGEX = /\A[a-zA-Z][-.\w]{0,62}\z/

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

def create_histogram(name, unit: nil, description: nil, advice: nil)
def create_histogram(name, unit: nil, description: nil, advice: EMPTY_ADVICE)
create_instrument(:histogram, name, unit, description, nil, advice) { HISTOGRAM }
end

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

private

def create_instrument(kind, name, unit, description, callback, advice = nil)
def create_instrument(kind, name, unit, description, callback, advice = EMPTY_ADVICE)
raise InstrumentNameError if name.nil?
raise InstrumentNameError if name.empty?
raise InstrumentNameError unless NAME_REGEX.match?(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Metrics
module Instrument
# {Histogram} is the SDK implementation of {OpenTelemetry::Metrics::Histogram}.
class Histogram < OpenTelemetry::SDK::Metrics::Instrument::SynchronousInstrument
def initialize(name, unit, description, instrumentation_scope, meter_provider, advice = nil)
def initialize(name, unit, description, instrumentation_scope, meter_provider, advice = OpenTelemetry::Metrics::Meter::EMPTY_ADVICE)
@advice = advice

super
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Instrument
# {SynchronousInstrument} contains the common functionality shared across
# the synchronous instruments SDK instruments.
class SynchronousInstrument
def initialize(name, unit, description, instrumentation_scope, meter_provider, advice = nil)
def initialize(name, unit, description, instrumentation_scope, meter_provider, advice = OpenTelemetry::Metrics::Meter::EMPTY_ADVICE)
@name = name
@unit = unit
@description = description
Expand Down
2 changes: 1 addition & 1 deletion metrics_sdk/lib/opentelemetry/sdk/metrics/meter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def add_metric_reader(metric_reader)
end
end

def create_instrument(kind, name, unit, description, callback, advice = nil)
def create_instrument(kind, name, unit, description, callback, advice = OpenTelemetry::Metrics::Meter::EMPTY_ADVICE)
super do
case kind
when :counter then OpenTelemetry::SDK::Metrics::Instrument::Counter.new(name, unit, description, @instrumentation_scope, @meter_provider)
Expand Down
2 changes: 1 addition & 1 deletion metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
it 'does not require advice' do
instrument = meter.create_histogram('histogram', description: 'stuff', unit: 'things')

assert_nil instrument.instance_variable_get(:@advice)
assert_equal({}, instrument.instance_variable_get(:@advice))
end
end

Expand Down

0 comments on commit bcb1caf

Please sign in to comment.