class LittleGhost::Tracing::PayloadLimiter
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.
Attributes
The largest String attribute, in bytes, that passes through unchanged.
Public Class Methods
Source
# File lib/little_ghost/tracing/payload_limiter.rb, line 62 def initialize(max_bytes:) @max_bytes = Integer(max_bytes) raise ArgumentError, "max_bytes must be at least #{MINIMUM_BYTES}" if @max_bytes < MINIMUM_BYTES end
Creates a limiter for String attributes larger than max_bytes, which must be at least 1,024.
Public Instance Methods
Source
# File lib/little_ghost/tracing/payload_limiter.rb, line 72 def call(attributes) return attributes unless attributes.is_a?(Hash) transformed = attributes.dup truncations = {} attributes.each do |name, value| next if name == "metadata" next unless value.is_a?(String) && value.bytesize > @max_bytes result = limit_attribute(name, value) transformed[name] = result.value truncations[name] = result.details rescue => error Events.warn("little_ghost.tracing.payload_limit_failed", error_type: error.class.name) transformed.delete(name) truncations[name] = {"omitted" => true, "error" => error.class.name} end if transformed["metadata"].is_a?(String) && transformed["metadata"].bytesize > @max_bytes result = limit_json(transformed.fetch("metadata")) transformed["metadata"] = result.value truncations["metadata"] = result.details end return attributes if truncations.empty? transformed["metadata"] = metadata_with_truncations(transformed["metadata"], truncations) transformed rescue => error Events.warn("little_ghost.tracing.payload_limit_failed", error_type: error.class.name) omit_oversized_content(attributes, error) end
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.