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
use core::fmt::Debug;
use core::marker::{Send, Sync};
use crate::span::SpanContext;
use crate::trace::{TraceContext, TraceContextBuilder, TraceRecord};
const TRACE_RESERVE: usize = 10;
const EXT_RESERVE: usize = 5;
/// A handler for error events.
///
/// A `Subscriber` implements a behavior for recording or collecting traces of
/// created, propagated or converted errors.
#[allow(unused_mut)]
#[allow(unused_variables)]
pub trait Subscriber: Sync + Send {
/// Notifies this subscriber that the propagation of the error has been started.
///
/// This handler is called before any other handler
/// and is ideal for initializing data for a context.
fn on_start(&self, builder: &mut TraceContextBuilder, rec: &TraceRecord) {
builder
.reserve_trace(TRACE_RESERVE)
.reserve_extensions(EXT_RESERVE);
}
/// Notifies this subscriber that the propagation of the error has been completed
/// and that no more trace records will be appended.
fn on_end(&self, ctx: &mut TraceContext) {}
/// Visits the construction of a new error [`Span`](crate::span::Span) instance.
///
/// A new span is constructed if:
/// - the error context is explicitly created
/// - one span type is converted to another
fn on_new_span(&self, ctx: &mut SpanContext) {}
/// Visits the construction of an [`TraceRecord`] instance.
///
/// This handler will be called before a record is inserted into the trace context.
///
/// A new record is inserted if:
/// - an error is created
/// - a conversion from one error to another happens
/// - the error is propagated to the caller
///
/// It can also happen that multiple events call this handler for the same location,
/// but perform different operations.
fn on_try_record(&self, ctx: &mut SpanContext) {}
/// Notifies this subscriber that a trace record has been verified and successfully recorded.
fn on_record(&self, ctx: &mut TraceContext) {}
}
/// Default error subscriber.
#[derive(Clone, Debug, Default)]
pub struct ErrorSubscriber;
impl Subscriber for ErrorSubscriber {}