devtools_wire_format/
spans.rs

1use crate::common;
2
3mod generated {
4    #![allow(warnings)]
5    #![allow(clippy::all, clippy::pedantic)]
6    include!("./generated/rs.devtools.spans.rs");
7}
8
9pub use generated::*;
10
11impl SpanEvent {
12    #[must_use]
13    pub fn new_span(
14        at: prost_types::Timestamp,
15        id: &tracing_core::span::Id,
16        metadata: &'static tracing_core::Metadata<'static>,
17        fields: Vec<common::Field>,
18        parent: Option<tracing_core::span::Id>,
19    ) -> Self {
20        Self {
21            event: Some(span_event::Event::NewSpan(span_event::Span {
22                id: id.into_u64(),
23                metadata_id: std::ptr::from_ref(metadata) as u64,
24                fields,
25                at: Some(at),
26                parent: parent.map(|id| id.into_u64()),
27            })),
28        }
29    }
30
31    #[must_use]
32    pub fn enter_span(
33        at: prost_types::Timestamp,
34        id: &tracing_core::span::Id,
35        thread_id: u64,
36    ) -> Self {
37        Self {
38            event: Some(span_event::Event::EnterSpan(span_event::Enter {
39                span_id: id.into_u64(),
40                thread_id,
41                at: Some(at),
42            })),
43        }
44    }
45
46    #[must_use]
47    pub fn exit_span(
48        at: prost_types::Timestamp,
49        id: &tracing_core::span::Id,
50        thread_id: u64,
51    ) -> Self {
52        Self {
53            event: Some(span_event::Event::ExitSpan(span_event::Exit {
54                span_id: id.into_u64(),
55                thread_id,
56                at: Some(at),
57            })),
58        }
59    }
60
61    #[must_use]
62    pub fn close_span(at: prost_types::Timestamp, id: &tracing_core::span::Id) -> Self {
63        Self {
64            event: Some(span_event::Event::CloseSpan(span_event::Close {
65                span_id: id.into_u64(),
66                at: Some(at),
67            })),
68        }
69    }
70
71    #[must_use]
72    pub fn span_recorded(id: &tracing_core::span::Id, fields: Vec<common::Field>) -> Self {
73        Self {
74            event: Some(span_event::Event::Recorded(span_event::Recorded {
75                span_id: id.into_u64(),
76                fields,
77            })),
78        }
79    }
80}