Module: Riffer::Metrics
Overview
Internal metrics port — records OTEL metric instruments when the host bundles the OpenTelemetry metrics API and no-ops otherwise, so riffer never declares an OTEL dependency.
Defined Under Namespace
Modules: Instruments, Null Classes: Histogram, Otel
Constant Summary collapse
- MUTEX =
Mutex.new
- SCHEMA_URL =
The Ruby API cannot attach a schema URL to a meter, so the semconv pin lives here as the documented contract version.
"https://opentelemetry.io/schemas/1.37.0"
Instance Method Summary collapse
-
#create_histogram(name, unit: nil, description: nil) ⇒ Object
Returns a handle to the named histogram.
-
#monotonic_now ⇒ Object
Reads the monotonic clock in seconds — the time source for duration metrics, immune to wall-clock adjustments.
-
#record_histogram(name, value, unit: nil, description: nil, attributes: nil) ⇒ Object
Records a value onto the named histogram.
-
#recording? ⇒ Boolean
Mirrors a span’s
recording?so a caller can skip work that exists only to feed a metric. -
#reset! ⇒ Object
Discards the resolved backend so the next record re-resolves it; cached instruments live on that backend, so this clears them too.
Instance Method Details
#create_histogram(name, unit: nil, description: nil) ⇒ Object
Returns a handle to the named histogram. – : (String, ?unit: String?, ?description: String?) -> Riffer::Metrics::Histogram
44 45 46 |
# File 'lib/riffer/metrics.rb', line 44 def create_histogram(name, unit: nil, description: nil) Histogram.new(name, unit: unit, description: description) end |
#monotonic_now ⇒ Object
Reads the monotonic clock in seconds — the time source for duration metrics, immune to wall-clock adjustments. – : () -> Float
68 69 70 |
# File 'lib/riffer/metrics.rb', line 68 def monotonic_now Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
#record_histogram(name, value, unit: nil, description: nil, attributes: nil) ⇒ Object
Records a value onto the named histogram. – : (String, Numeric, ?unit: String?, ?description: String?, ?attributes: Hash[String, untyped]?) -> void
51 52 53 54 |
# File 'lib/riffer/metrics.rb', line 51 def record_histogram(name, value, unit: nil, description: nil, attributes: nil) return unless Riffer.config.metrics.enabled backend.record_histogram(name, value, unit: unit, description: description, attributes: attributes) end |
#recording? ⇒ Boolean
Mirrors a span’s recording? so a caller can skip work that exists only to feed a metric. – : () -> bool
60 61 62 |
# File 'lib/riffer/metrics.rb', line 60 def recording? Riffer.config.metrics.enabled && backend.is_a?(Otel) end |
#reset! ⇒ Object
Discards the resolved backend so the next record re-resolves it; cached instruments live on that backend, so this clears them too. – : () -> void
76 77 78 |
# File 'lib/riffer/metrics.rb', line 76 def reset! MUTEX.synchronize { @backend = nil } end |