# Class LittleGhost::Tracing::PayloadLimiter

Documentation version: Edge

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

Keeps span attributes within a byte budget before a tracing backend rejects or
silently drops them. Captured model histories, Tool arguments, and Tool
results can grow far beyond what an exporter accepts; a PayloadLimiter
shortens them while keeping the parts a reader needs.

    LittleGhost.configure do |config|
      config.instrument LittleGhost::Tracing::OpenTelemetry.new(
        payload_limiter: LittleGhost::Tracing::PayloadLimiter.new(max_bytes: 64_000)
      )
    end

Only String attributes larger than `max_bytes` change. Message lists in
`gen_ai.input.messages` and the OpenInference
`input.value` keep the most recent messages that fit, plus a
leading system or developer message when there is room. Output messages keep
the leading choices. A Tool call and its result are kept or dropped together,
so a preview never shows a result without its call. JSON values stay valid
JSON, long strings keep their beginning and end around a
`...[truncated]...` marker, and multibyte characters are never
split.

Each shortened attribute is recorded under `telemetry_truncation` in the
OpenInference `metadata` attribute, with its original and captured sizes and,
for message lists, how many messages were omitted. Existing metadata is
preserved.

The limiter only shortens content that was already captured. It does not scrub
or redact; configure Support::ContentCapture for that. A limiter holds no
mutable state and can be shared across threads.

## Inheritance

`LittleGhost::Tracing::PayloadLimiter < Object`

## Attributes

<a id="attribute-i-max_bytes"></a>
### `max_bytes` (R)

The largest String attribute, in bytes, that passes through unchanged.

## Class methods

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

```ruby
.new(max_bytes:)
```

Creates a limiter for String attributes larger than `max_bytes`, which must be
at least 1,024.

## Instance methods

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

```ruby
#call(attributes)
```

Returns `attributes` itself when every String fits, or a new Hash with
oversized values shortened and the `metadata` attribute updated. If an
attribute cannot be shortened, only that attribute is omitted and recorded as
omitted, and a `little_ghost.tracing.payload_limit_failed` warning
is emitted through Events.
