use std::{collections::HashMap, time::SystemTime};
use super::v7::{DebugMeta, TraceId};
use crate::utils::ts_rfc3339;
use serde::{Deserialize, Serialize, Serializer};
use uuid::Uuid;
fn serialize_id<S: Serializer>(uuid: &Uuid, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_some(&uuid.as_simple())
}
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub struct TransactionMetadata {
#[serde(serialize_with = "serialize_id")]
pub id: Uuid,
pub name: String,
pub trace_id: TraceId,
pub relative_start_ns: u64,
pub relative_end_ns: u64,
#[serde(default)]
pub active_thread_id: u64,
}
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
pub struct RustFrame {
pub instruction_addr: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub struct Sample {
pub stack_id: u32,
pub thread_id: u64,
pub elapsed_since_start_ns: u64,
}
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub struct ThreadMetadata {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub struct Profile {
pub samples: Vec<Sample>,
pub stacks: Vec<Vec<u32>>,
pub frames: Vec<RustFrame>,
pub thread_metadata: HashMap<String, ThreadMetadata>,
}
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub struct OSMetadata {
pub name: String,
pub version: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub build_number: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub struct RuntimeMetadata {
pub name: String,
pub version: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub struct DeviceMetadata {
pub architecture: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub enum Version {
#[serde(rename = "1")]
V1,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct SampleProfile {
pub version: Version,
#[serde(skip_serializing_if = "Option::is_none")]
pub debug_meta: Option<DebugMeta>,
pub device: DeviceMetadata,
pub os: OSMetadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub runtime: Option<RuntimeMetadata>,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub environment: String,
#[serde(serialize_with = "serialize_id")]
pub event_id: Uuid,
pub platform: String,
pub profile: Profile,
pub release: String,
#[serde(with = "ts_rfc3339")]
pub timestamp: SystemTime,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub transactions: Vec<TransactionMetadata>,
}