module LittleGhost::Instrumentation
Instrumentation turns agent work into structured lifecycle notifications. Applications can measure agents, models, tools, workflows, and sessions with the telemetry backend they already use.
class TimingSubscriber < LittleGhost::Instrumentation::Subscriber def finish(name, attributes) puts "#{name}: #{attributes.fetch(:duration_ms)}ms" end end LittleGhost.configure do |config| config.instrument TimingSubscriber.new end
A subscriber receives structured attributes when an operation starts, finishes, or emits a point-in-time event. Subscriber failures are reported once and kept separate from agent execution.
Content and trust
Diagnostic content is excluded unless the application installs an explicit Support::ContentCapture policy. One process is one telemetry and content policy boundary; applications that need different exporters or data policies should use separate processes.
Public Class Methods
Source
# File lib/little_ghost/instrumentation.rb, line 433 def capture_content(...) = bus.capture_content(...)
Installs the process-wide diagnostic content policy.
Source
# File lib/little_ghost/instrumentation.rb, line 445 def context = bus.context
Copies the current instrumentation context.
Source
# File lib/little_ghost/instrumentation.rb, line 441 def current = bus.current
Returns the current fiber’s active Handle.
Source
# File lib/little_ghost/instrumentation.rb, line 447 def flush(...) = bus.flush(...)
Flushes process-wide subscribers.
Source
# File lib/little_ghost/instrumentation.rb, line 439 def instrument(...) = bus.instrument(...)
Wraps a block in a lifecycle operation.
Source
# File lib/little_ghost/instrumentation.rb, line 413 def notifier = bus
Accesses the process-wide Bus.
Source
# File lib/little_ghost/instrumentation.rb, line 416 def notifier=(value) raise ArgumentError, "notifier must be an instrumentation bus" unless value.is_a?(Bus) notifier_mutex.synchronize do if @bus && !@bus.equal?(value) && @bus.active? raise Error, "cannot replace instrumentation notifier with active operations" end @bus = value end end
Replaces the process-wide bus when it has no active operations.
Source
# File lib/little_ghost/instrumentation.rb, line 435 def publish(...) = bus.publish(...)
Publishes a point event on the process-wide bus.
Source
# File lib/little_ghost/instrumentation.rb, line 449 def shutdown(...) = bus.shutdown(...)
Shuts down the process-wide bus.
Source
# File lib/little_ghost/instrumentation.rb, line 437 def start(...) = bus.start(...)
Starts a lifecycle operation on the process-wide bus.
Source
# File lib/little_ghost/instrumentation.rb, line 429 def subscribe(...) = bus.subscribe(...)
Subscribes a process-wide backend.
# File lib/little_ghost/instrumentation.rb, line 454 def subscribed(subscriber, prepend: false) unless subscriber.is_a?(Subscriber) raise ArgumentError, "instrumentation subscriber must be a LittleGhost::Instrumentation::Subscriber" end subscribers = ExecutionState[:instrumentation_subscribers] || [] entry = {subscriber:, prepend:} ExecutionState.with(instrumentation_subscribers: subscribers + [entry]) { yield } end
Temporarily subscribes a backend for the block’s execution state.
Source
# File lib/little_ghost/instrumentation.rb, line 451 def trace_context(...) = bus.trace_context(...)
Gets downstream trace fields from process-wide subscribers.
Source
# File lib/little_ghost/instrumentation.rb, line 431 def unsubscribe(...) = bus.unsubscribe(...)
Unsubscribes a process-wide backend.
# File lib/little_ghost/instrumentation.rb, line 443 def with_context(attributes, &block) = bus.with_context(attributes, &block)
Adds attributes while the block runs.