opentelemetry/testing/
trace.rs1use crate::{
2 trace::{Span, SpanContext, Status},
3 KeyValue, SpanId, TraceId,
4};
5use std::borrow::Cow;
6
7#[derive(Debug)]
8pub struct TestSpan(pub SpanContext);
9
10impl Span for TestSpan {
11 fn add_event_with_timestamp<T>(
12 &mut self,
13 _name: T,
14 _timestamp: std::time::SystemTime,
15 _attributes: Vec<KeyValue>,
16 ) where
17 T: Into<Cow<'static, str>>,
18 {
19 }
20 fn span_context(&self) -> &SpanContext {
21 &self.0
22 }
23 fn is_recording(&self) -> bool {
24 false
25 }
26 fn set_attribute(&mut self, _attribute: KeyValue) {}
27 fn set_status(&mut self, _status: Status) {}
28 fn update_name<T>(&mut self, _new_name: T)
29 where
30 T: Into<Cow<'static, str>>,
31 {
32 }
33
34 fn add_link(&mut self, _span_context: SpanContext, _attributes: Vec<KeyValue>) {}
35 fn end_with_timestamp(&mut self, _timestamp: std::time::SystemTime) {}
36}
37
38impl TraceId {
40 pub fn from_u128(num: u128) -> Self {
41 TraceId::from_bytes(num.to_be_bytes())
42 }
43}
44
45impl SpanId {
47 pub fn from_u64(num: u64) -> Self {
48 SpanId::from_bytes(num.to_be_bytes())
49 }
50}