use std::collections::BTreeMap;
use std::future::Future;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use super::span_digest::{SpanStub, capture, normalize_attribute};
#[derive(Debug, Clone, Default, PartialEq)]
pub struct LogRecord {
pub event_name: String,
pub span_id: Option<u64>,
pub body: Value,
pub attributes: Vec<(String, Value)>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct LogDigest {
pub event_name: String,
pub body: Value,
pub attributes: BTreeMap<String, Value>,
}
pub fn build_log_digest(r: &LogRecord) -> LogDigest {
LogDigest {
event_name: r.event_name.clone(),
body: r.body.clone(),
attributes: r
.attributes
.iter()
.map(|(k, v)| (k.clone(), normalize_attribute(k, v.clone())))
.collect(),
}
}
pub async fn capture_logs<F: Future>(fut: F) -> (F::Output, Vec<SpanStub>, Vec<LogRecord>) {
capture(fut).await
}