use serde_json::Value;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DataCategory {
Error,
Transaction,
Session,
Log,
HttpRequest,
Db,
Heartbeat,
Release,
}
impl DataCategory {
pub fn as_str(&self) -> &'static str {
match self {
DataCategory::Error => "error",
DataCategory::Transaction => "transaction",
DataCategory::Session => "session",
DataCategory::Log => "log",
DataCategory::HttpRequest => "http_request",
DataCategory::Db => "db",
DataCategory::Heartbeat => "heartbeat",
DataCategory::Release => "release",
}
}
}
#[derive(Debug, Clone)]
pub struct Envelope {
pub path: &'static str,
pub category: DataCategory,
pub body: Value,
}
impl Envelope {
pub fn new<T: serde::Serialize>(
path: &'static str,
category: DataCategory,
payload: &T,
) -> Self {
let body = serde_json::to_value(payload).unwrap_or(Value::Null);
Envelope {
path,
category,
body,
}
}
}