use std::borrow::Cow;
pub trait TraceIdLike: Eq {
fn to_u128(&self) -> u128;
}
pub trait AttributeLike {
type Value: ValueLike;
fn key(&self) -> &str;
fn value(&self) -> &Self::Value;
}
impl<T: AttributeLike> AttributeLike for &T {
type Value = T::Value;
fn key(&self) -> &str {
(**self).key()
}
fn value(&self) -> &Self::Value {
(**self).value()
}
}
pub trait ValueLike {
fn as_float(&self) -> Option<f64>;
fn as_str(&self) -> Option<Cow<'_, str>>;
}
pub trait AttributeFactory {
type Attribute: Sized;
fn create_i64(&self, key: &'static str, value: i64) -> Self::Attribute;
fn create_f64(&self, key: &'static str, value: f64) -> Self::Attribute;
fn create_string(&self, key: &'static str, value: Cow<'static, str>) -> Self::Attribute;
}
pub trait SpanProperties {
type Attribute<'a>: AttributeLike
where
Self: 'a;
fn operation_name(&self) -> Cow<'_, str>;
fn service(&self) -> Cow<'_, str>;
fn env(&self) -> Cow<'_, str>;
fn resource(&self) -> Cow<'_, str>;
fn status_code(&self) -> Option<u32>;
fn attributes(&self) -> impl Iterator<Item = Self::Attribute<'_>> + '_;
fn get_alternate_key<'b>(&self, key: &'b str) -> Option<Cow<'b, str>>;
}
pub trait SamplingData {
type TraceId: TraceIdLike;
type Properties<'a>: SpanProperties
where
Self: 'a;
fn is_parent_sampled(&self) -> Option<bool>;
fn trace_id(&self) -> &Self::TraceId;
fn with_span_properties<S, T, F>(&self, s: &S, f: F) -> T
where
F: Fn(&S, &Self::Properties<'_>) -> T;
}