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() -> ContentRecorder
pub fn disabled() -> ContentRecorder
Records nothing. The default, and what an application gets unless it deliberately asks for something else.
Sourcepub fn enabled(redactor: Arc<dyn ContentRedactor>) -> ContentRecorder
pub fn enabled(redactor: Arc<dyn ContentRedactor>) -> ContentRecorder
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.
Trait Implementations§
Source§impl Clone for ContentRecorder
impl Clone for ContentRecorder
Source§fn clone(&self) -> ContentRecorder
fn clone(&self) -> ContentRecorder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContentRecorder
impl Debug for ContentRecorder
Source§impl Default for ContentRecorder
impl Default for ContentRecorder
Source§fn default() -> ContentRecorder
fn default() -> ContentRecorder
Auto Trait Implementations§
impl !RefUnwindSafe for ContentRecorder
impl !UnwindSafe for ContentRecorder
impl Freeze for ContentRecorder
impl Send for ContentRecorder
impl Sync for ContentRecorder
impl Unpin for ContentRecorder
impl UnsafeUnpin for ContentRecorder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more