# Module LittleGhost::Instrumentation

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Instrumentation.html

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.

## Class methods

<a id="method-c-capture_content"></a>
### `.capture_content`

```ruby
.capture_content(...)
```

Installs the process-wide diagnostic content policy.

<a id="method-c-context"></a>
### `.context`

```ruby
.context()
```

Copies the current instrumentation context.

<a id="method-c-current"></a>
### `.current`

```ruby
.current()
```

Returns the current fiber's active Handle.

<a id="method-c-flush"></a>
### `.flush`

```ruby
.flush(...)
```

Flushes process-wide subscribers.

<a id="method-c-instrument"></a>
### `.instrument`

```ruby
.instrument(...)
```

Wraps a block in a lifecycle operation.

<a id="method-c-notifier"></a>
### `.notifier`

```ruby
.notifier()
```

Accesses the process-wide Bus.

<a id="method-c-notifier-3D"></a>
### `.notifier=`

```ruby
.notifier=(value)
```

Replaces the process-wide bus when it has no active operations.

<a id="method-c-publish"></a>
### `.publish`

```ruby
.publish(...)
```

Publishes a point event on the process-wide bus.

<a id="method-c-shutdown"></a>
### `.shutdown`

```ruby
.shutdown(...)
```

Shuts down the process-wide bus.

<a id="method-c-start"></a>
### `.start`

```ruby
.start(...)
```

Starts a lifecycle operation on the process-wide bus.

<a id="method-c-subscribe"></a>
### `.subscribe`

```ruby
.subscribe(...)
```

Subscribes a process-wide backend.

<a id="method-c-subscribed"></a>
### `.subscribed`

```ruby
.subscribed(subscriber, prepend: false)
```

Temporarily subscribes a backend for the block's execution state.

<a id="method-c-trace_context"></a>
### `.trace_context`

```ruby
.trace_context(...)
```

Gets downstream trace fields from process-wide subscribers.

<a id="method-c-unsubscribe"></a>
### `.unsubscribe`

```ruby
.unsubscribe(...)
```

Unsubscribes a process-wide backend.

<a id="method-c-with_context"></a>
### `.with_context`

```ruby
.with_context(attributes, &block)
```

Adds attributes while the block runs.
