opentelemetry_zpages/trace/
span_processor.rs

1//! ## zPages processor
2//!
3//! ZPages processor collect span information when span starts or ends and send it to [`SpanAggregator`]
4//! for further process.
5//!
6//! [`SpanAggregator`]:../struct.SpanAggregator.html
7use crate::trace::TracezMessage;
8use async_channel::Sender;
9use opentelemetry::Context;
10use opentelemetry_sdk::{
11    error::OTelSdkResult,
12    trace::SpanData,
13    trace::{Span, SpanProcessor},
14};
15use std::fmt::Formatter;
16
17/// ZPagesSpanProcessor is an alternative to external exporters. It sends span data to zPages server
18/// where it will be archive and user can use this information for debug purpose.
19///
20/// ZPagesSpanProcessor employs a `SpanAggregator` running as another task to aggregate the spans
21/// using the name of spans.
22#[deprecated(note = "This crate is deprecated and no longer maintained.")]
23pub struct ZPagesSpanProcessor {
24    tx: Sender<TracezMessage>,
25}
26
27impl std::fmt::Debug for ZPagesSpanProcessor {
28    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
29        f.write_str("ZPageProcessor")
30    }
31}
32
33impl ZPagesSpanProcessor {
34    /// Create a new `ZPagesSpanProcessor`.
35    pub fn new(tx: Sender<TracezMessage>) -> ZPagesSpanProcessor {
36        ZPagesSpanProcessor { tx }
37    }
38}
39
40impl SpanProcessor for ZPagesSpanProcessor {
41    fn on_start(&self, span: &mut Span, _cx: &Context) {
42        // if the aggregator is already dropped. This is a no-op
43        if let Some(data) = span.exported_data() {
44            let _ = self.tx.try_send(TracezMessage::SampleSpan(data));
45        }
46    }
47
48    fn on_end(&self, span: SpanData) {
49        // if the aggregator is already dropped. This is a no-op
50        let _ = self.tx.try_send(TracezMessage::SpanEnd(span));
51    }
52
53    fn force_flush(&self) -> OTelSdkResult {
54        // do nothing
55        Ok(())
56    }
57
58    fn shutdown(&self) -> OTelSdkResult {
59        // do nothing
60        Ok(())
61    }
62}