use libdd_trace_protobuf::pb;
use libdd_trace_utils::span::{trace_utils, v04::Span, TraceData};
use libdd_trace_utils::trace_utils as pb_utils;
use std::borrow::Borrow;
pub trait StatSpan<'a> {
fn service(&'a self) -> &'a str;
fn resource(&'a self) -> &'a str;
fn name(&'a self) -> &'a str;
fn r#type(&'a self) -> &'a str;
fn start(&'a self) -> i64;
fn duration(&'a self) -> i64;
fn is_error(&'a self) -> bool;
fn is_trace_root(&'a self) -> bool;
fn is_measured(&'a self) -> bool;
fn is_partial_snapshot(&'a self) -> bool;
fn has_top_level(&'a self) -> bool;
fn get_meta(&'a self, key: &str) -> Option<&'a str>;
fn get_metrics(&'a self, key: &str) -> Option<f64>;
}
impl<'a, T: TraceData> StatSpan<'a> for Span<T> {
fn service(&'a self) -> &'a str {
self.service.borrow()
}
fn resource(&'a self) -> &'a str {
self.resource.borrow()
}
fn name(&'a self) -> &'a str {
self.name.borrow()
}
fn r#type(&'a self) -> &'a str {
self.r#type.borrow()
}
fn start(&'a self) -> i64 {
self.start
}
fn duration(&'a self) -> i64 {
self.duration
}
fn is_error(&'a self) -> bool {
self.error != 0
}
fn is_trace_root(&'a self) -> bool {
self.parent_id == 0
}
fn is_measured(&'a self) -> bool {
trace_utils::is_measured(self)
}
fn is_partial_snapshot(&'a self) -> bool {
trace_utils::is_partial_snapshot(self)
}
fn has_top_level(&'a self) -> bool {
trace_utils::has_top_level(self)
}
fn get_meta(&'a self, key: &str) -> Option<&'a str> {
self.meta.get(key).map(|v| v.borrow())
}
fn get_metrics(&'a self, key: &str) -> Option<f64> {
self.metrics.get(key).copied()
}
}
impl<'a> StatSpan<'a> for pb::Span {
fn service(&'a self) -> &'a str {
self.service.as_str()
}
fn resource(&'a self) -> &'a str {
self.resource.as_str()
}
fn name(&'a self) -> &'a str {
self.name.as_str()
}
fn r#type(&'a self) -> &'a str {
self.r#type.as_str()
}
fn start(&'a self) -> i64 {
self.start
}
fn duration(&'a self) -> i64 {
self.duration
}
fn is_error(&'a self) -> bool {
self.error != 0
}
fn is_trace_root(&'a self) -> bool {
self.parent_id == 0
}
fn is_measured(&'a self) -> bool {
pb_utils::is_measured(self)
}
fn is_partial_snapshot(&'a self) -> bool {
pb_utils::is_partial_snapshot(self)
}
fn has_top_level(&'a self) -> bool {
pb_utils::has_top_level(self)
}
fn get_meta(&'a self, key: &str) -> Option<&'a str> {
self.meta.get(key).map(|v| v.as_str())
}
fn get_metrics(&'a self, key: &str) -> Option<f64> {
self.metrics.get(key).copied()
}
}