opentelemetry_api/testing/
trace.rs1use crate::{
2 trace::{Span, SpanContext, SpanId, Status, TraceId},
3 KeyValue,
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 fn end_with_timestamp(&mut self, _timestamp: std::time::SystemTime) {}
34}
35
36impl TraceId {
38 pub fn from_u128(num: u128) -> Self {
39 TraceId::from_bytes(num.to_be_bytes())
40 }
41}
42
43impl SpanId {
45 pub fn from_u64(num: u64) -> Self {
46 SpanId::from_bytes(num.to_be_bytes())
47 }
48}