use tracing::Span;
use crate::config::SemconvConfig;
pub struct ContentEventEmitter;
impl ContentEventEmitter {
pub fn emit_prompt(config: &SemconvConfig, prompt: &str) {
if !config.capture_content {
return;
}
let span = Span::current();
if span.is_none() {
tracing::debug!("content event emitter: no active span for prompt event");
return;
}
span.in_scope(|| {
tracing::info!(event_name = "gen_ai.content.prompt", content = prompt);
});
}
pub fn emit_completion(config: &SemconvConfig, completion: &str) {
if !config.capture_content {
return;
}
let span = Span::current();
if span.is_none() {
tracing::debug!("content event emitter: no active span for completion event");
return;
}
span.in_scope(|| {
tracing::info!(event_name = "gen_ai.content.completion", content = completion);
});
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_emit_prompt_disabled_is_noop() {
let config = SemconvConfig::default();
ContentEventEmitter::emit_prompt(&config, "test prompt");
}
#[test]
fn test_emit_completion_disabled_is_noop() {
let config = SemconvConfig::default();
ContentEventEmitter::emit_completion(&config, "test completion");
}
}