# Class LittleGhost::Tracing::OpenTelemetry

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Tracing/OpenTelemetry.html

OpenTelemetry turns LittleGhost lifecycle notifications into GenAI spans and
events. It brings agents, model calls, tools, workflows, and token usage into
the same traces as the rest of an application.

    LittleGhost.configure do |config|
      config.instrument LittleGhost::Tracing::OpenTelemetry.new
    end

LittleGhost depends only on `opentelemetry-api`. Install and
configure the desired SDK, processors, and exporters before registering this
subscriber.

### Content and trust

Prompts, responses, messages, tool arguments, and exception content are
omitted by default. They appear only when Instrumentation has an explicit,
scrubbed Support::ContentCapture policy.

## Inheritance

`LittleGhost::Tracing::OpenTelemetry < LittleGhost::Instrumentation::Subscriber`

## Class methods

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

```ruby
.new(tracer: nil)
```

Uses `tracer` or the global tracer provider.

## Instance methods

<a id="method-i-emit"></a>
### `#emit`

```ruby
#emit(name, attributes)
```

Adds a structured event to the correlated active span.

<a id="method-i-finish"></a>
### `#finish`

```ruby
#finish(name, attributes)
```

Finishes the span correlated by operation ID.

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

```ruby
#flush(timeout: nil)
```

Flushes through the configured tracer provider when supported.

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

```ruby
#shutdown(timeout: nil)
```

Finishes spans still owned by this subscriber.

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

```ruby
#start(name, attributes)
```

Starts a span for a lifecycle operation.

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

```ruby
#trace_context(operation_id: nil, **)
```

Supplies W3C propagation fields for an active operation when known.

<a id="method-i-with_span"></a>
### `#with_span`

```ruby
#with_span(name, attributes:, parent_operation_id: nil)
```

Wraps a block in a standalone internal span. Prefer lifecycle Instrumentation
methods for normal framework operations.
