Module: Clicksign::Instrumentation

Defined in:
lib/clicksign/instrumentation.rb

Constant Summary collapse

EVENTS =
%i[request retry error].freeze

Class Method Summary collapse

Class Method Details

.clearObject

Removes all registered callbacks — intended for test teardown.



30
31
32
# File 'lib/clicksign/instrumentation.rb', line 30

def clear
  @callbacks = Hash.new { |h, k| h[k] = [] }
end

.on(event, &block) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/clicksign/instrumentation.rb', line 10

def on(event, &block)
  unless EVENTS.include?(event)
    raise ArgumentError, "Unknown event: #{event}. Valid: #{EVENTS.join(', ')}"
  end

  @callbacks[event] << block
end

.publish(event, payload) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/clicksign/instrumentation.rb', line 18

def publish(event, payload)
  @callbacks[event].each do |cb|
    cb.call(payload)
  rescue StandardError => e
    Clicksign.configuration.logger&.warn(
      "[Clicksign] instrumentation callback error (#{event}): " \
      "#{e.class}: #{e.message}",
    )
  end
end