minitrace/local/
raw_span.rs

1// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0.
2
3use std::borrow::Cow;
4
5use minstant::Instant;
6
7use crate::collector::SpanId;
8use crate::util::Properties;
9
10#[derive(Debug)]
11pub struct RawSpan {
12    pub id: SpanId,
13    pub parent_id: SpanId,
14    pub begin_instant: Instant,
15    pub name: Cow<'static, str>,
16    pub properties: Properties,
17    pub is_event: bool,
18
19    // Will write this field at post processing
20    pub end_instant: Instant,
21}
22
23impl RawSpan {
24    #[inline]
25    pub(crate) fn begin_with(
26        id: SpanId,
27        parent_id: SpanId,
28        begin_instant: Instant,
29        name: impl Into<Cow<'static, str>>,
30        is_event: bool,
31    ) -> Self {
32        RawSpan {
33            id,
34            parent_id,
35            begin_instant,
36            name: name.into(),
37            properties: Properties::default(),
38            is_event,
39            end_instant: Instant::ZERO,
40        }
41    }
42
43    #[inline]
44    pub(crate) fn end_with(&mut self, end_instant: Instant) {
45        self.end_instant = end_instant;
46    }
47}
48
49impl Clone for RawSpan {
50    fn clone(&self) -> Self {
51        let mut properties = Properties::default();
52        properties.extend(self.properties.iter().cloned());
53
54        RawSpan {
55            id: self.id,
56            parent_id: self.parent_id,
57            begin_instant: self.begin_instant,
58            name: self.name.clone(),
59            properties,
60            is_event: self.is_event,
61            end_instant: self.end_instant,
62        }
63    }
64}