1
+ //! # OpenTelemetry Span Processor Interface
2
+ //!
3
+ //! Span processor is an interface which allows hooks for span start and end method
4
+ //! invocations. The span processors are invoked only when
5
+ //! [`is_recording`] is true.
6
+ //!
7
+ //! Built-in span processors are responsible for batching and conversion of spans to
8
+ //! exportable representation and passing batches to exporters.
9
+ //!
10
+ //! Span processors can be registered directly on SDK [`TracerProvider`] and they are
11
+ //! invoked in the same order as they were registered.
12
+ //!
13
+ //! All `Tracer` instances created by a `TracerProvider` share the same span processors.
14
+ //! Changes to this collection reflect in all `Tracer` instances.
15
+ //!
16
+ //! The following diagram shows `SpanProcessor`'s relationship to other components
17
+ //! in the SDK:
18
+ //!
19
+ //! ```ascii
20
+ //! +-----+--------------+ +-----------------------+ +-------------------+
21
+ //! | | | | | | |
22
+ //! | | | | (Batch)SpanProcessor | | SpanExporter |
23
+ //! | | +---> (Simple)SpanProcessor +---> (JaegerExporter) |
24
+ //! | | | | | | |
25
+ //! | SDK | Tracer.span()| +-----------------------+ +-------------------+
26
+ //! | | Span.end() |
27
+ //! | | | +---------------------+
28
+ //! | | | | |
29
+ //! | | +---> ZPagesProcessor |
30
+ //! | | | | |
31
+ //! +-----+--------------+ +---------------------+
32
+ //! ```
33
+ //!
34
+ //! [`is_recording`]: ../span/trait.Span.html#method.is_recording
35
+ //! [`TracerProvider`]: ../provider/trait.TracerProvider.html
36
+ use crate :: sdk:: trace:: Span ;
1
37
use crate :: {
2
38
exporter:: trace:: { SpanData , SpanExporter } ,
3
- trace:: { Span , SpanProcessor } ,
4
39
Context ,
5
40
} ;
6
41
use futures:: { channel:: mpsc, executor, future:: BoxFuture , Future , FutureExt , Stream , StreamExt } ;
@@ -23,6 +58,18 @@ const OTEL_BSP_MAX_EXPORT_BATCH_SIZE: &str = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE";
23
58
/// Default maximum batch size
24
59
const OTEL_BSP_MAX_EXPORT_BATCH_SIZE_DEFAULT : usize = 512 ;
25
60
61
+ /// `SpanProcessor`s allow hooks for span start and end method invocations.
62
+ pub trait SpanProcessor : Send + Sync + std:: fmt:: Debug {
63
+ /// `on_start` method is invoked when a `Span` is started.
64
+ fn on_start ( & self , span : & Span , cx : & Context ) ;
65
+ /// `on_end` method is invoked when a `Span` is ended.
66
+ fn on_end ( & self , span : SpanData ) ;
67
+ /// Shutdown is invoked when SDK shuts down. Use this call to cleanup any
68
+ /// processor data. No calls to `on_start` and `on_end` method is invoked
69
+ /// after `shutdown` call is made.
70
+ fn shutdown ( & mut self ) ;
71
+ }
72
+
26
73
/// A [`SpanProcessor`] that exports synchronously when spans are finished.
27
74
///
28
75
/// # Examples
@@ -58,7 +105,7 @@ impl SimpleSpanProcessor {
58
105
}
59
106
60
107
impl SpanProcessor for SimpleSpanProcessor {
61
- fn on_start ( & self , _span : & dyn Span , _cx : & Context ) {
108
+ fn on_start ( & self , _span : & Span , _cx : & Context ) {
62
109
// Ignored
63
110
}
64
111
@@ -127,7 +174,7 @@ impl fmt::Debug for BatchSpanProcessor {
127
174
}
128
175
129
176
impl SpanProcessor for BatchSpanProcessor {
130
- fn on_start ( & self , _span : & dyn Span , _cx : & Context ) {
177
+ fn on_start ( & self , _span : & Span , _cx : & Context ) {
131
178
// Ignored
132
179
}
133
180
0 commit comments