module LittleGhost::Events

Events lets an application react to noteworthy agent activity without coupling LittleGhost to a logger or event backend. Listeners can feed local diagnostics, alerts, or an application’s own event pipeline.

class WarningCollector
  attr_reader :events

  def initialize
    @events = []
  end

  def emit(event)
    events << event
  end
end

warnings = WarningCollector.new
LittleGhost::Events.subscribe(warnings) do |event|
  %i[warn error].include?(event[:level])
end
LittleGhost::Events.warn("support.case.stalled", case_id: "case-42")
warnings.events.last[:name] # => "support.case.stalled"

Events describe point-in-time facts. Instrumentation measures work that has a start and finish. Payloads are copied, limited to JSON-safe values, and delivered with context local to the current execution. A broken listener never breaks the operation that emitted the event.