Skip to content

Commit 9eee7e1

Browse files
authored
[trace] Move SpanProcessor into sdk. Use ReadableSpan as parameter in on_start (open-telemetry#334)
1 parent fab6940 commit 9eee7e1

File tree

5 files changed

+52
-57
lines changed

5 files changed

+52
-57
lines changed

opentelemetry/src/api/trace/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ mod noop;
119119
mod provider;
120120
mod span;
121121
mod span_context;
122-
mod span_processor;
123122
mod tracer;
124123

125124
pub use self::{
@@ -135,6 +134,5 @@ pub use self::{
135134
SpanContext, SpanId, TraceId, TraceState, TRACE_FLAG_DEBUG, TRACE_FLAG_DEFERRED,
136135
TRACE_FLAG_NOT_SAMPLED, TRACE_FLAG_SAMPLED,
137136
},
138-
span_processor::SpanProcessor,
139137
tracer::{SpanBuilder, Tracer},
140138
};

opentelemetry/src/api/trace/span_processor.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

opentelemetry/src/sdk/trace/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ pub use provider::{Builder, TracerProvider};
2424
pub use sampler::{Sampler, SamplingDecision, SamplingResult, ShouldSample};
2525
pub use span::Span;
2626
pub use span_processor::{
27-
BatchConfig, BatchSpanProcessor, BatchSpanProcessorBuilder, SimpleSpanProcessor,
27+
BatchConfig, BatchSpanProcessor, BatchSpanProcessorBuilder, SimpleSpanProcessor, SpanProcessor,
2828
};
2929
pub use tracer::Tracer;

opentelemetry/src/sdk/trace/provider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! not duplicate this data to avoid that different `Tracer` instances
1010
//! of the `TracerProvider` have different versions of these data.
1111
use crate::exporter::trace::SpanExporter;
12-
use crate::{sdk, trace::SpanProcessor};
12+
use crate::{sdk, sdk::trace::SpanProcessor};
1313
use std::sync::Arc;
1414

1515
/// Default tracer name if empty string is provided.

opentelemetry/src/sdk/trace/span_processor.rs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
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;
137
use crate::{
238
exporter::trace::{SpanData, SpanExporter},
3-
trace::{Span, SpanProcessor},
439
Context,
540
};
641
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";
2358
/// Default maximum batch size
2459
const OTEL_BSP_MAX_EXPORT_BATCH_SIZE_DEFAULT: usize = 512;
2560

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+
2673
/// A [`SpanProcessor`] that exports synchronously when spans are finished.
2774
///
2875
/// # Examples
@@ -58,7 +105,7 @@ impl SimpleSpanProcessor {
58105
}
59106

60107
impl SpanProcessor for SimpleSpanProcessor {
61-
fn on_start(&self, _span: &dyn Span, _cx: &Context) {
108+
fn on_start(&self, _span: &Span, _cx: &Context) {
62109
// Ignored
63110
}
64111

@@ -127,7 +174,7 @@ impl fmt::Debug for BatchSpanProcessor {
127174
}
128175

129176
impl SpanProcessor for BatchSpanProcessor {
130-
fn on_start(&self, _span: &dyn Span, _cx: &Context) {
177+
fn on_start(&self, _span: &Span, _cx: &Context) {
131178
// Ignored
132179
}
133180

0 commit comments

Comments
 (0)