Class: OpenTelemetry::SDK::Metrics::Instrument::Counter
- Inherits:
-
SynchronousInstrument
- Object
- SynchronousInstrument
- OpenTelemetry::SDK::Metrics::Instrument::Counter
- Defined in:
- lib/opentelemetry/sdk/metrics/instrument/counter.rb
Overview
Counter is the SDK implementation of Metrics::Counter.
Instance Method Summary collapse
-
#add(increment, attributes: {}) ⇒ Object
Increment the Counter by a fixed amount.
-
#instrument_kind ⇒ Symbol
Returns the instrument kind as a Symbol.
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
#add(increment, attributes: {}) ⇒ Object
Increment the Counter by a fixed amount.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/opentelemetry/sdk/metrics/instrument/counter.rb', line 27 def add(increment, 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 if increment.negative? OpenTelemetry.logger.warn("#{@name} received a negative value") else update(increment, attributes) end nil rescue StandardError => e OpenTelemetry.handle_error(exception: e) nil end |
#instrument_kind ⇒ Symbol
Returns the instrument kind as a Symbol
16 17 18 |
# File 'lib/opentelemetry/sdk/metrics/instrument/counter.rb', line 16 def instrument_kind :counter end |