1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::common;

mod generated {
    #![allow(warnings)]
    #![allow(clippy::all, clippy::pedantic)]
    include!("./generated/rs.devtools.spans.rs");
}

pub use generated::*;

impl SpanEvent {
    #[must_use]
    pub fn new_span(
        at: prost_types::Timestamp,
        id: &tracing_core::span::Id,
        metadata: &'static tracing_core::Metadata<'static>,
        fields: Vec<common::Field>,
        parent: Option<tracing_core::span::Id>,
    ) -> Self {
        Self {
            event: Some(span_event::Event::NewSpan(span_event::Span {
                id: id.into_u64(),
                metadata_id: metadata as *const _ as u64,
                fields,
                at: Some(at),
                parent: parent.map(|id| id.into_u64()),
            })),
        }
    }

    #[must_use]
    pub fn enter_span(
        at: prost_types::Timestamp,
        id: &tracing_core::span::Id,
        thread_id: u64,
    ) -> Self {
        Self {
            event: Some(span_event::Event::EnterSpan(span_event::Enter {
                span_id: id.into_u64(),
                thread_id,
                at: Some(at),
            })),
        }
    }

    #[must_use]
    pub fn exit_span(
        at: prost_types::Timestamp,
        id: &tracing_core::span::Id,
        thread_id: u64,
    ) -> Self {
        Self {
            event: Some(span_event::Event::ExitSpan(span_event::Exit {
                span_id: id.into_u64(),
                thread_id,
                at: Some(at),
            })),
        }
    }

    #[must_use]
    pub fn close_span(at: prost_types::Timestamp, id: &tracing_core::span::Id) -> Self {
        Self {
            event: Some(span_event::Event::CloseSpan(span_event::Close {
                span_id: id.into_u64(),
                at: Some(at),
            })),
        }
    }

    #[must_use]
    pub fn span_recorded(id: &tracing_core::span::Id, fields: Vec<common::Field>) -> Self {
        Self {
            event: Some(span_event::Event::Recorded(span_event::Recorded {
                span_id: id.into_u64(),
                fields,
            })),
        }
    }
}