class LittleGhost::Support::ContentCapture
ContentCapture lets an application opt selected diagnostic content into telemetry after redaction and scrubbing. Capture stays off until an application installs an enabled policy.
policy = LittleGhost::Support::ContentCapture.new( enabled: true, max_bytes: 16_384, redactions: [ENV.fetch("API_TOKEN")] ) LittleGhost::Instrumentation.capture_content(policy)
Security and trust
Enabling capture may place model input, output, tool definitions, and exception details into telemetry. Redaction and a custom scrubber reduce accidental disclosure but are not a security boundary. Configure one policy per trusted process and apply exporter-side controls as well.
Public Class Methods
Source
# File lib/little_ghost/support/content_capture.rb, line 28 def self.disabled = new(enabled: false)
Creates a policy that never captures diagnostics.
# File lib/little_ghost/support/content_capture.rb, line 32 def initialize(enabled: false, max_bytes: nil, scrubber: nil, redactions: []) @enabled = enabled == true @max_bytes = Integer(max_bytes) if max_bytes @scrubber = scrubber @redactor = Redactor.new(redactions:, stringify_keys: true) raise ArgumentError, "max_bytes must be at least 64" if @max_bytes && @max_bytes < 64 raise ArgumentError, "scrubber must be callable" if @scrubber && !@scrubber.respond_to?(:call) end
Configures a policy. max_bytes is applied per captured attribute and scrubber receives already redacted values.
Public Instance Methods
Source
# File lib/little_ghost/support/content_capture.rb, line 43 def capture(values) return {} unless @enabled && values.is_a?(Hash) values.each_with_object({}) do |(key, value), captured| next unless %i[input output exception tool_definitions].include?(key.to_sym) captured[:"diagnostic_#{key}"] = if key.to_sym == :tool_definitions capture_tool_definitions(value) else value = structured_output(value) if key.to_sym == :output scrubbed = scrub(value) scrubbed = scrub(@scrubber.call(scrubbed)) if @scrubber truncate(JSON.generate(scrubbed)) end rescue JSON::GeneratorError, Encoding::UndefinedConversionError captured[:"diagnostic_#{key}"] = JSON.generate("[UNSERIALIZABLE]") end end
Produces scrubbed, JSON-encoded diagnostic attributes selected from values, or an empty hash when disabled.