Class: Hanami::Events::CloudPubsub::Middleware::Prometheus

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/events/cloud_pubsub/middleware/prometheus.rb

Overview

Middleware used for logging useful information about an event

Constant Summary collapse

LONG_RUNNING_JOB_RUNTIME_BUCKETS =
[
  0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, # standard (from Prometheus)
  30, 60, 120, 300, 1800, 3600, 21_600 # Tasks may be very long-running
].freeze

Instance Method Summary collapse

Instance Method Details

#call(msg, **opts) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hanami/events/cloud_pubsub/middleware/prometheus.rb', line 28

def call(msg, **opts)
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  status = :running

  begin
    ret = yield(**opts) if block_given?
    status = :succeeded
    ret
  rescue StandardError
    status = :failed
    raise
  end
ensure
  record_metrics(msg, status, start)
end