use std::borrow::Cow;
pub trait TraceIdLike: PartialEq + Eq {
fn to_u128(&self) -> u128;
}
pub trait AttributeLike {
type Value: ValueLike;
fn key(&self) -> &str;
fn value(&self) -> &Self::Value;
}
pub trait ValueLike {
fn extract_float(&self) -> Option<f64>;
fn extract_string(&self) -> Option<Cow<'_, str>>;
}
impl AttributeLike for opentelemetry::KeyValue {
type Value = opentelemetry::Value;
fn key(&self) -> &str {
self.key.as_str()
}
fn value(&self) -> &Self::Value {
&self.value
}
}
impl ValueLike for opentelemetry::Value {
fn extract_float(&self) -> Option<f64> {
crate::sampling::utils::extract_float_value(self)
}
fn extract_string(&self) -> Option<Cow<'_, str>> {
crate::sampling::utils::extract_string_value(self)
}
}
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: AttributeLike;
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<'a>(&'a self) -> impl Iterator<Item = &'a Self::Attribute>
where
Self: 'a;
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;
}