Class: OpenTelemetry::Metrics::Meter

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/metrics/meter.rb

Overview

No-op implementation of Meter.

Direct Known Subclasses

Internal::ProxyMeter

Constant Summary collapse

NAME_REGEX =
/\A[a-zA-Z][-.\w]{0,62}\z/
DuplicateInstrumentError =
Class.new(OpenTelemetry::Error)
InstrumentNameError =
Class.new(OpenTelemetry::Error)
InstrumentUnitError =
Class.new(OpenTelemetry::Error)
InstrumentDescriptionError =
Class.new(OpenTelemetry::Error)

Instance Method Summary collapse

Constructor Details

#initializeMeter

Returns a new instance of Meter.



28
29
30
31
# File 'lib/opentelemetry/metrics/meter.rb', line 28

def initialize
  @mutex = Mutex.new
  @instrument_registry = {}
end

Instance Method Details

#create_counter(name, unit: nil, description: nil) ⇒ nil

Counter is a synchronous Instrument which supports non-negative increments.

With this api call:

exception_counter = meter.create_counter(“exceptions”, description: “number of exceptions caught”, unit: 's')

Parameters:

  • name (String)

    the name of the counter

  • unit (optional String) (defaults to: nil)

    an optional string provided by user.

  • description (optional String) (defaults to: nil)

    an optional free-form text provided by user.

Returns:

  • (nil)

    after creation of counter, it will be stored in instrument_registry



46
47
48
# File 'lib/opentelemetry/metrics/meter.rb', line 46

def create_counter(name, unit: nil, description: nil)
  create_instrument(:counter, name, unit, description, nil) { COUNTER }
end

#create_gauge(name, unit: nil, description: nil) ⇒ nil

Gauge is an synchronous Instrument which reports non-additive value(s)

With this api call:

meter.create_gauge(“cpu.frequency”, description: “the real-time CPU clock speed”, unit: “ms”)

Parameters:

  • name (String)

    the name of the gauge.

  • unit (optional String) (defaults to: nil)

    an optional string provided by user.

  • description (optional String) (defaults to: nil)

    an optional free-form text provided by user.

Returns:

  • (nil)

    after creation of gauge, it will be stored in instrument_registry



83
84
85
# File 'lib/opentelemetry/metrics/meter.rb', line 83

def create_gauge(name, unit: nil, description: nil)
  create_instrument(:gauge, name, unit, description, nil) { GAUGE }
end

#create_histogram(name, unit: nil, description: nil) ⇒ nil

Histogram is a synchronous Instrument which can be used to report arbitrary values that are likely to be statistically meaningful. It is intended for statistics such as histograms, summaries, and percentiles.

With this api call:

http_server_duration = meter.create_histogram(“http.server.duration”, description: “measures the duration of the inbound HTTP request”, unit: “s”)

Parameters:

  • name (String)

    the name of the histogram

  • unit (optional String) (defaults to: nil)

    an optional string provided by user.

  • description (optional String) (defaults to: nil)

    an optional free-form text provided by user.

Returns:

  • (nil)

    after creation of histogram, it will be stored in instrument_registry



65
66
67
# File 'lib/opentelemetry/metrics/meter.rb', line 65

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

#create_observable_counter(name, callback:, unit: nil, description: nil) ⇒ nil

ObservableCounter is an asynchronous Instrument which reports monotonically increasing value(s) when the instrument is being observed.

With this api call:

pf_callback = -> { # collect metrics here } meter.create_observable_counter(“PF”, pf_callback, description: “process page faults”, unit: 'ms')

Parameters:

  • name (String)

    the name of the observable_counter

  • callback (Proc)

    the callback function that used to collect metrics

  • unit (optional String) (defaults to: nil)

    an optional string provided by user.

  • description (optional String) (defaults to: nil)

    an optional free-form text provided by user.

Returns:

  • (nil)

    after creation of observable_counter, it will be stored in instrument_registry



122
123
124
# File 'lib/opentelemetry/metrics/meter.rb', line 122

def create_observable_counter(name, callback:, unit: nil, description: nil)
  create_instrument(:observable_counter, name, unit, description, callback) { OBSERVABLE_COUNTER }
end

#create_observable_gauge(name, callback:, unit: nil, description: nil) ⇒ nil

ObservableGauge is an asynchronous Instrument which reports non-additive value(s) (e.g. the room temperature - it makes no sense to report the temperature value from multiple rooms and sum them up) when the instrument is being observed.

With this api call:

pf_callback = -> { # collect metrics here } meter.create_observable_counter(“cpu.frequency”, pf_callback, description: “the real-time CPU clock speed”, unit: 'ms')

Parameters:

  • name (String)

    the name of the observable_gauge

  • callback (Proc)

    the callback function that used to collect metrics

  • unit (optional String) (defaults to: nil)

    an optional string provided by user.

  • description (optional String) (defaults to: nil)

    an optional free-form text provided by user.

Returns:

  • (nil)

    after creation of observable_gauge, it will be stored in instrument_registry



145
146
147
# File 'lib/opentelemetry/metrics/meter.rb', line 145

def create_observable_gauge(name, callback:, unit: nil, description: nil)
  create_instrument(:observable_gauge, name, unit, description, callback) { OBSERVABLE_GAUGE }
end

#create_observable_up_down_counter(name, callback:, unit: nil, description: nil) ⇒ nil

ObservableUpDownCounter is an asynchronous Instrument which reports additive value(s) (e.g. the process heap size - it makes sense to report the heap size from multiple processes and sum them up, so we get the total heap usage) when the instrument is being observed.

With this api call:

pf_callback = -> { # collect metrics here } meter.create_observable_up_down_counter(“process.workingset”, pf_callback, description: “process working set”, unit: 'KB')

Parameters:

  • name (String)

    the name of the observable_up_down_counter

  • callback (Proc)

    the callback function that used to collect metrics

  • unit (optional String) (defaults to: nil)

    an optional string provided by user.

  • description (optional String) (defaults to: nil)

    an optional free-form text provided by user.

Returns:

  • (nil)

    after creation of observable_up_down_counter, it will be stored in instrument_registry



168
169
170
# File 'lib/opentelemetry/metrics/meter.rb', line 168

def create_observable_up_down_counter(name, callback:, unit: nil, description: nil)
  create_instrument(:observable_up_down_counter, name, unit, description, callback) { OBSERVABLE_UP_DOWN_COUNTER }
end

#create_up_down_counter(name, unit: nil, description: nil) ⇒ nil

UpDownCounter is a synchronous Instrument which supports increments and decrements.

With this api call:

items_counter = meter.create_up_down_counter(“store.inventory”, description: “the number of the items available”, unit: “s”)

Parameters:

  • name (String)

    the name of the up_down_counter

  • unit (optional String) (defaults to: nil)

    an optional string provided by user.

  • description (optional String) (defaults to: nil)

    an optional free-form text provided by user.

Returns:

  • (nil)

    after creation of up_down_counter, it will be stored in instrument_registry



100
101
102
# File 'lib/opentelemetry/metrics/meter.rb', line 100

def create_up_down_counter(name, unit: nil, description: nil)
  create_instrument(:up_down_counter, name, unit, description, nil) { UP_DOWN_COUNTER }
end