Module: Woods::Observability::Instrumentation

Defined in:
lib/woods/observability/instrumentation.rb

Overview

Lightweight instrumentation wrapper that delegates to ActiveSupport::Notifications when available, and falls back to a simple yield otherwise.

Examples:

Instrumentation.instrument('woods.extraction', unit: 'User') do
  extract_unit(user_model)
end

Class Method Summary collapse

Class Method Details

.instrument(event, payload = {}) {|payload| ... } ⇒ Object

Instrument a block of code with an event name and payload.

Delegates to ActiveSupport::Notifications.instrument when available. Otherwise, yields the block directly.

Parameters:

  • event (String)

    Event name (e.g., ‘woods.extraction’)

  • payload (Hash) (defaults to: {})

    Additional data to include with the event

Yields:

  • (payload)

    The block to instrument

Returns:

  • (Object)

    The return value of the block



25
26
27
28
29
30
31
# File 'lib/woods/observability/instrumentation.rb', line 25

def instrument(event, payload = {}, &block)
  if defined?(ActiveSupport::Notifications)
    ActiveSupport::Notifications.instrument(event, payload, &block)
  elsif block
    yield payload
  end
end