Class: OpenTelemetry::SDK::Metrics::Instrument::Gauge

Inherits:
SynchronousInstrument show all
Defined in:
lib/opentelemetry/sdk/metrics/instrument/gauge.rb

Overview

Gauge is the SDK implementation of Metrics::Gauge.

Instance Method Summary collapse

Methods inherited from SynchronousInstrument

#initialize, #register_with_new_metric_store

Constructor Details

This class inherits a constructor from OpenTelemetry::SDK::Metrics::Instrument::SynchronousInstrument

Instance Method Details

#instrument_kindSymbol

Returns the instrument kind as a Symbol

Returns:

  • (Symbol)


16
17
18
# File 'lib/opentelemetry/sdk/metrics/instrument/gauge.rb', line 16

def instrument_kind
  :gauge
end

#record(value, attributes: {}) ⇒ Object

Record the absolute value of the Gauge.

Parameters:

  • value (numeric)

    The current absolute value.

  • attributes (Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}) (defaults to: {})

    Values must be non-nil and (array of) string, boolean or numeric type. Array values must not contain nil elements and all elements must be of the same basic type (string, numeric, boolean).



27
28
29
30
31
32
33
34
35
36
# File 'lib/opentelemetry/sdk/metrics/instrument/gauge.rb', line 27

def record(value, attributes: {})
  # TODO: When the metrics SDK stabilizes and is merged into the main SDK,
  # we can leverage the SDK Internal validation classes to enforce this:
  # https://github.com/open-telemetry/opentelemetry-ruby/blob/6bec625ef49004f364457c26263df421526b60d6/sdk/lib/opentelemetry/sdk/internal.rb#L47
  update(value, attributes)
  nil
rescue StandardError => e
  OpenTelemetry.handle_error(exception: e)
  nil
end