Expand description
tracing integration for emitting redacted events.
RedactLayer scans string/debug field values with a cloakrs_core::Scanner
and writes sanitized events. It is intentionally a sanitizing output layer;
the tracing subscriber API does not let one layer mutate fields before
unrelated sibling layers observe them.
§Examples
use cloakrs_core::{Confidence, EntityType, Locale, PiiEntity, Recognizer, Scanner, Span};
use tracing_subscriber::prelude::*;
struct Email;
impl Recognizer for Email {
fn id(&self) -> &str { "email_test" }
fn entity_type(&self) -> EntityType { EntityType::Email }
fn supported_locales(&self) -> &[Locale] { &[] }
fn scan(&self, text: &str) -> Vec<PiiEntity> {
text.find('@').map(|at| PiiEntity {
entity_type: EntityType::Email,
span: Span::new(0, text[at..].find(' ').map_or(text.len(), |offset| at + offset)),
text: text[..text[at..].find(' ').map_or(text.len(), |offset| at + offset)].to_string(),
confidence: Confidence::new(0.95).unwrap(),
recognizer_id: self.id().to_string(),
}).into_iter().collect()
}
}
let scanner = Scanner::builder().recognizer(Email).build().unwrap();
let _subscriber = tracing_subscriber::registry()
.with(cloakrs_tracing::RedactLayer::new(scanner));Structs§
- Redact
Layer - A tracing layer that writes sanitized events.