🛈 Note: This is pre-release documentation for the upcoming tracing 0.2.0 ecosystem.

For the release documentation, please see docs.rs, instead.

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#![doc = include_str!("../README.md")]
pub mod collector;
pub mod event;
pub mod expect;
pub mod field;
mod metadata;
pub mod span;

#[cfg(feature = "tracing-subscriber")]
pub mod subscriber;

#[derive(Debug, Eq, PartialEq)]
pub enum Parent {
    ContextualRoot,
    Contextual(String),
    ExplicitRoot,
    Explicit(String),
}

impl Parent {
    pub fn check_parent_name(
        &self,
        parent_name: Option<&str>,
        provided_parent: Option<tracing_core::span::Id>,
        ctx: impl std::fmt::Display,
        collector_name: &str,
    ) {
        match self {
            Parent::ExplicitRoot => {
                assert!(
                    provided_parent.is_none(),
                    "[{}] expected {} to be an explicit root, but its parent was actually {:?} (name: {:?})",
                    collector_name,
                    ctx,
                    provided_parent,
                    parent_name,
                );
            }
            Parent::Explicit(expected_parent) => {
                assert!(
                    provided_parent.is_some(),
                    "[{}] expected {} to have explicit parent {}, but it has no explicit parent",
                    collector_name,
                    ctx,
                    expected_parent,
                );
                assert_eq!(
                    Some(expected_parent.as_ref()),
                    parent_name,
                    "[{}] expected {} to have explicit parent {}, but its parent was actually {:?} (name: {:?})",
                    collector_name,
                    ctx,
                    expected_parent,
                    provided_parent,
                    parent_name,
                );
            }
            Parent::ContextualRoot => {
                assert!(
                    provided_parent.is_none(),
                    "[{}] expected {} to be a contextual root, but its parent was actually {:?} (name: {:?})",
                    collector_name,
                    ctx,
                    provided_parent,
                    parent_name,
                );
                assert!(
                    parent_name.is_none(),
                    "[{}] expected {} to be contextual a root, but we were inside span {:?}",
                    collector_name,
                    ctx,
                    parent_name,
                );
            }
            Parent::Contextual(expected_parent) => {
                assert!(provided_parent.is_none(),
                    "[{}] expected {} to have a contextual parent\nbut it has the explicit parent {:?} (name: {:?})",
                    collector_name,
                    ctx,
                    provided_parent,
                    parent_name,
                );
                assert_eq!(
                    Some(expected_parent.as_ref()),
                    parent_name,
                    "[{}] expected {} to have contextual parent {:?}, but got {:?}",
                    collector_name,
                    ctx,
                    expected_parent,
                    parent_name,
                );
            }
        }
    }
}