pub struct ContentRecorder { /* private fields */ }Expand description
Records prompt and completion text on a provider-call span.
Disabled by default, and for a reason. Prompts and completions are user
data: enabling this sends what the user typed, and what the model said back,
to whatever tracing backend is configured. That is a decision about data
residency, retention and consent, not a debugging convenience, so it takes
an explicit ContentRecorder::enabled call and a
ContentRedactor to switch on (spec §25.5).
use std::sync::Arc;
use turnframe_telemetry::tracing::{ContentRecorder, ContentRole, DropAllContent};
// The default records nothing at all.
let off = ContentRecorder::disabled();
assert!(!off.is_enabled());
assert_eq!(off.rendered(ContentRole::Input, "withdraw trip 17"), None);
// Even switched on, everything goes through the redaction hook.
let on = ContentRecorder::enabled(Arc::new(DropAllContent));
assert!(on.is_enabled());
assert_eq!(on.rendered(ContentRole::Input, "withdraw trip 17"), None);Implementations§
Source§impl ContentRecorder
impl ContentRecorder
Sourcepub fn disabled() -> Self
pub fn disabled() -> Self
Records nothing. The default, and what an application gets unless it deliberately asks for something else.
Sourcepub fn enabled(redactor: Arc<dyn ContentRedactor>) -> Self
pub fn enabled(redactor: Arc<dyn ContentRedactor>) -> Self
Records content, every piece of it through redactor first.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether content recording is switched on.
Sourcepub fn rendered(&self, role: ContentRole, text: &str) -> Option<String>
pub fn rendered(&self, role: ContentRole, text: &str) -> Option<String>
What would be recorded for this text: None when recording is off or
the redactor dropped it. Exposed so an application can test its own
redaction hook without a subscriber.
Sourcepub fn record(&self, span: &Span, role: ContentRole, text: &str)
pub fn record(&self, span: &Span, role: ContentRole, text: &str)
Records content on span, if recording is on and the redactor allows
it. The span must be one this crate opened, which declares the two
content fields empty.