servlet 1.0.0

A small application runtime with an explicit operational contract
Documentation
//! Delegate identity, parenting, sampling, and timestamps to the native SDK.
use super::{bounds, config::TraceLimits};
use opentelemetry::{
    Context, KeyValue,
    trace::{Span, SpanBuilder, SpanContext, Status, Tracer},
};
use opentelemetry_sdk::trace::{SdkTracer, Span as SdkSpan};
use std::{borrow::Cow, sync::Arc, time::SystemTime};

#[derive(Clone, Debug)]
pub(crate) struct BoundedTracer {
    pub(crate) inner: SdkTracer,
    pub(crate) limits: Arc<TraceLimits>,
}
#[derive(Debug)]
pub(crate) struct BoundedSpan {
    inner: SdkSpan,
    limits: Arc<TraceLimits>,
}
impl Tracer for BoundedTracer {
    type Span = BoundedSpan;
    fn build_with_context(&self, mut builder: SpanBuilder, parent: &Context) -> Self::Span {
        let limits = &self.limits;
        builder.name = bounds::text(builder.name, limits.value_bytes);
        if let Some(attributes) = &mut builder.attributes {
            bounds::attributes(attributes, limits.attributes, limits);
        }
        if let Some(events) = &mut builder.events {
            bounds::collection(events, limits.events as usize);
            for event in events {
                event.name = bounds::text(std::mem::take(&mut event.name), limits.value_bytes);
                bounds::attributes(&mut event.attributes, limits.nested_attributes, limits);
            }
        }
        if let Some(links) = &mut builder.links {
            bounds::collection(links, limits.links as usize);
            for link in links {
                bounds::attributes(&mut link.attributes, limits.nested_attributes, limits);
            }
        }
        BoundedSpan {
            inner: self.inner.build_with_context(builder, parent),
            limits: limits.clone(),
        }
    }
}
impl Span for BoundedSpan {
    fn span_context(&self) -> &SpanContext {
        self.inner.span_context()
    }
    fn is_recording(&self) -> bool {
        self.inner.is_recording()
    }
    fn set_attribute(&mut self, mut kv: KeyValue) {
        bounds::attribute(&mut kv, &self.limits);
        self.inner.set_attribute(kv);
    }
    fn set_status(&mut self, status: Status) {
        self.inner.set_status(bounds::status(status, &self.limits));
    }
    fn update_name<T: Into<Cow<'static, str>>>(&mut self, name: T) {
        self.inner
            .update_name(bounds::text(name, self.limits.value_bytes));
    }
    fn add_event_with_timestamp<T: Into<Cow<'static, str>>>(
        &mut self,
        name: T,
        time: SystemTime,
        mut attrs: Vec<KeyValue>,
    ) {
        bounds::attributes(&mut attrs, self.limits.nested_attributes, &self.limits);
        self.inner.add_event_with_timestamp(
            bounds::text(name, self.limits.value_bytes),
            time,
            attrs,
        );
    }
    fn add_link(&mut self, context: SpanContext, mut attrs: Vec<KeyValue>) {
        bounds::attributes(&mut attrs, self.limits.nested_attributes, &self.limits);
        self.inner.add_link(context, attrs);
    }
    fn end_with_timestamp(&mut self, time: SystemTime) {
        self.inner.end_with_timestamp(time);
    }
}