Class: OpenTelemetry::Internal::ProxyInstrument Private
- Inherits:
-
Object
- Object
- OpenTelemetry::Internal::ProxyInstrument
- Defined in:
- lib/opentelemetry/internal/proxy_instrument.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
-
#add(amount, attributes: nil) ⇒ Object
private
Delegates to the upgraded instrument's #add, if any.
-
#bind(attributes: {}) ⇒ Object
private
Delegates to the upgraded instrument's #bind, if any; returns self (no-op) until upgraded.
-
#enabled? ⇒ Boolean
private
Delegates to the upgraded instrument's #enabled?, false (disabled) until upgraded.
-
#initialize(kind, name, unit, desc, callback, exemplar_filter, exemplar_reservoir, advisory = nil) ⇒ ProxyInstrument
constructor
private
A new instance of ProxyInstrument.
-
#record(amount, attributes: nil) ⇒ Object
private
Delegates to the upgraded instrument's #record, if any.
-
#register_callback(callback) ⇒ Object
private
Delegates to the underlying instrument, or queues the callback until the delegate is set.
-
#unregister(callback) ⇒ Object
private
Delegates to the underlying instrument, or removes the callback from the queue.
-
#upgrade_with(meter) ⇒ Object
private
Replaces the no-op delegate with a real instrument from the given meter.
Constructor Details
#initialize(kind, name, unit, desc, callback, exemplar_filter, exemplar_reservoir, advisory = nil) ⇒ ProxyInstrument
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ProxyInstrument.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/opentelemetry/internal/proxy_instrument.rb', line 11 def initialize(kind, name, unit, desc, callback, exemplar_filter, exemplar_reservoir, advisory = nil) @kind = kind @name = name @unit = unit @desc = desc @callback = callback @exemplar_filter = exemplar_filter @exemplar_reservoir = exemplar_reservoir @advisory = advisory @registered_callbacks = [] @delegate = nil end |
Instance Method Details
#add(amount, attributes: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delegates to the upgraded instrument's #add, if any.
38 39 40 |
# File 'lib/opentelemetry/internal/proxy_instrument.rb', line 38 def add(amount, attributes: nil) @delegate&.add(amount, attributes: attributes) end |
#bind(attributes: {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delegates to the upgraded instrument's #bind, if any; returns self (no-op) until upgraded.
53 54 55 |
# File 'lib/opentelemetry/internal/proxy_instrument.rb', line 53 def bind(attributes: {}) @delegate ? @delegate.bind(attributes: attributes) : self end |
#enabled? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delegates to the upgraded instrument's #enabled?, false (disabled) until upgraded.
48 49 50 |
# File 'lib/opentelemetry/internal/proxy_instrument.rb', line 48 def enabled? @delegate ? @delegate.enabled? : false end |
#record(amount, attributes: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delegates to the upgraded instrument's #record, if any.
43 44 45 |
# File 'lib/opentelemetry/internal/proxy_instrument.rb', line 43 def record(amount, attributes: nil) @delegate&.record(amount, attributes: attributes) end |
#register_callback(callback) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delegates to the underlying instrument, or queues the callback until the delegate is set.
58 59 60 61 62 63 64 |
# File 'lib/opentelemetry/internal/proxy_instrument.rb', line 58 def register_callback(callback) if @delegate @delegate.register_callback(callback) else @registered_callbacks << callback end end |
#unregister(callback) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delegates to the underlying instrument, or removes the callback from the queue.
67 68 69 70 71 72 73 |
# File 'lib/opentelemetry/internal/proxy_instrument.rb', line 67 def unregister(callback) if @delegate @delegate.unregister(callback) else @registered_callbacks.delete(callback) end end |
#upgrade_with(meter) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Replaces the no-op delegate with a real instrument from the given meter.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/opentelemetry/internal/proxy_instrument.rb', line 25 def upgrade_with(meter) @delegate = case @kind when :counter, :histogram, :up_down_counter, :gauge meter.send("create_#{@kind}", @name, unit: @unit, description: @desc, exemplar_filter: @exemplar_filter, exemplar_reservoir: @exemplar_reservoir, advisory: @advisory) when :observable_counter, :observable_gauge, :observable_up_down_counter meter.send("create_#{@kind}", @name, unit: @unit, description: @desc, exemplar_filter: @exemplar_filter, exemplar_reservoir: @exemplar_reservoir, callback: @callback, advisory: @advisory) end @registered_callbacks.each do |callback| @delegate.register_callback(callback) if @delegate.respond_to?(:register_callback) end end |