micromegas_tracing/event/
sink.rs

1use std::{fmt, sync::Arc};
2
3use crate::{
4    logs::{LogBlock, LogMetadata, LogStream},
5    metrics::{MetricsBlock, MetricsStream},
6    prelude::*,
7    property_set::Property,
8    spans::{ThreadBlock, ThreadStream},
9};
10
11pub type BoxedEventSink = Box<dyn EventSink>;
12
13/// interface needed by the dispatch module to send out telemetry
14pub trait EventSink: Send + Sync {
15    fn on_startup(&self, process_info: Arc<ProcessInfo>);
16    fn on_shutdown(&self);
17
18    fn on_log_enabled(&self, metadata: &LogMetadata) -> bool;
19    fn on_log(
20        &self,
21        desc: &LogMetadata,
22        properties: &[Property],
23        time: i64,
24        args: fmt::Arguments<'_>,
25    );
26    fn on_init_log_stream(&self, log_stream: &LogStream);
27    fn on_process_log_block(&self, log_block: Arc<LogBlock>);
28
29    fn on_init_metrics_stream(&self, metrics_stream: &MetricsStream);
30    fn on_process_metrics_block(&self, metrics_block: Arc<MetricsBlock>);
31
32    fn on_init_thread_stream(&self, thread_stream: &ThreadStream);
33    fn on_process_thread_block(&self, thread_block: Arc<ThreadBlock>);
34
35    fn is_busy(&self) -> bool; // sink is busy writing to disk or network, avoid extra flushing
36}
37
38/// for tests where the data can be dropped
39pub struct NullEventSink {}
40
41impl EventSink for NullEventSink {
42    fn on_startup(&self, _: Arc<ProcessInfo>) {}
43    fn on_shutdown(&self) {}
44
45    fn on_log_enabled(&self, _: &LogMetadata) -> bool {
46        false
47    }
48    fn on_log(
49        &self,
50        _desc: &LogMetadata,
51        _properties: &[Property],
52        _time: i64,
53        _args: fmt::Arguments<'_>,
54    ) {
55    }
56    fn on_init_log_stream(&self, _: &LogStream) {}
57    fn on_process_log_block(&self, _: Arc<LogBlock>) {}
58
59    fn on_init_metrics_stream(&self, _: &MetricsStream) {}
60    fn on_process_metrics_block(&self, _: Arc<MetricsBlock>) {}
61
62    fn on_init_thread_stream(&self, _: &ThreadStream) {}
63    fn on_process_thread_block(&self, _: Arc<ThreadBlock>) {}
64
65    fn is_busy(&self) -> bool {
66        false
67    }
68}