Module: Clicksign::Instrumentation
- Defined in:
- lib/clicksign/instrumentation.rb
Constant Summary collapse
- EVENTS =
%i[request retry error].freeze
Class Method Summary collapse
-
.clear ⇒ Object
Removes all registered callbacks — intended for test teardown.
- .on(event, &block) ⇒ Object
- .publish(event, payload) ⇒ Object
Class Method Details
.clear ⇒ Object
Removes all registered callbacks — intended for test teardown.
32 33 34 |
# File 'lib/clicksign/instrumentation.rb', line 32 def clear @mutex.synchronize { @callbacks = Hash.new { |h, k| h[k] = [] } } end |
.on(event, &block) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/clicksign/instrumentation.rb', line 11 def on(event, &block) unless EVENTS.include?(event) raise ArgumentError, "Unknown event: #{event}. Valid: #{EVENTS.join(', ')}" end @mutex.synchronize { @callbacks[event] << block } end |
.publish(event, payload) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/clicksign/instrumentation.rb', line 19 def publish(event, payload) callbacks = @mutex.synchronize { @callbacks[event].dup } callbacks.each do |cb| cb.call(payload) rescue StandardError => e Clicksign.configuration.logger&.warn( "[Clicksign] instrumentation callback error (#{event}): " \ "#{e.class}: #{e.}", ) end end |