Module: RailsAiBridge::Instrumentation

Defined in:
lib/rails_ai_bridge/instrumentation.rb

Overview

Thin wrapper around ActiveSupport::Notifications for rails-ai-bridge events.

Events are namespaced under rails_ai_bridge. If ActiveSupport::Notifications is not available, the helper yields without instrumentation so the code can be used outside of Rails without a hard dependency.

Defined Under Namespace

Classes: InstrumentedTool

Constant Summary collapse

NAMESPACE =
'rails_ai_bridge'

Class Method Summary collapse

Class Method Details

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

Emits an instrumentation event.

Parameters:

  • event (String)

    event name suffix (e.g. tool.call)

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

    extra payload attached to the event

Yields:

  • optional block to wrap; the block result is returned

Returns:

  • (Object)

    the block result, or nil when no block is given



20
21
22
23
24
25
26
# File 'lib/rails_ai_bridge/instrumentation.rb', line 20

def self.instrument(event, payload = {})
  return yield unless defined?(ActiveSupport::Notifications) && ActiveSupport::Notifications

  ActiveSupport::Notifications.instrument("#{NAMESPACE}.#{event}", payload) do
    yield if block_given?
  end
end