use bytes::BytesMut;
use obs_proto::obs::v1::{Cardinality, Classification, FieldKind, ObsEnvelope, Severity, Tier};
#[derive(Debug, Clone, Copy)]
pub struct FieldMeta {
pub name: &'static str,
pub number: u32,
pub role: FieldRole,
pub cardinality: Cardinality,
pub classification: Classification,
}
impl FieldMeta {
#[must_use]
pub const fn new(
name: &'static str,
number: u32,
role: FieldRole,
cardinality: Cardinality,
classification: Classification,
) -> Self {
Self {
name,
number,
role,
cardinality,
classification,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum FieldRole {
Label,
Attribute,
Measurement,
TraceId,
SpanId,
ParentSpanId,
TimestampNs,
DurationNs,
Forensic,
}
impl From<FieldKind> for FieldRole {
fn from(k: FieldKind) -> Self {
match k {
FieldKind::Label => Self::Label,
FieldKind::Attribute => Self::Attribute,
FieldKind::Measurement => Self::Measurement,
FieldKind::TraceId => Self::TraceId,
FieldKind::SpanId => Self::SpanId,
FieldKind::ParentSpanId => Self::ParentSpanId,
FieldKind::TimestampNs => Self::TimestampNs,
FieldKind::DurationNs => Self::DurationNs,
FieldKind::Forensic => Self::Forensic,
_ => Self::Attribute,
}
}
}
pub trait EventSchema: Send + Sync + Sized + 'static {
const FULL_NAME: &'static str;
const TIER: Tier;
const DEFAULT_SEV: Severity;
const FIELDS: &'static [FieldMeta];
const SCHEMA_HASH: u64;
fn encode_payload(&self, buf: &mut BytesMut);
fn project(&self, env: &mut ObsEnvelope);
fn project_metrics(&self, sink: &mut dyn crate::metric::MetricEmitter) {
let _ = sink;
}
const SPANS_PAIRED_WITH: Option<&'static str> = None;
}