scouter_tracing/exporter/
stdout.rs

1use crate::error::TraceError;
2use crate::exporter::traits::SpanExporterBuilder;
3use crate::exporter::ExporterType;
4use opentelemetry_stdout::SpanExporter as OTelStdoutSpanExporter;
5use pyo3::prelude::*;
6use scouter_types::PyHelperFuncs;
7use serde::Serialize;
8#[derive(Debug, Clone, Serialize, Default)]
9#[pyclass]
10pub struct StdoutSpanExporter {
11    #[pyo3(get)]
12    pub sample_ratio: Option<f64>,
13    #[pyo3(get)]
14    pub batch_export: bool,
15}
16
17#[pymethods]
18impl StdoutSpanExporter {
19    #[new]
20    #[pyo3(signature = (batch_export=false, sample_ratio=None))]
21    pub fn new(batch_export: bool, sample_ratio: Option<f64>) -> Self {
22        StdoutSpanExporter {
23            batch_export,
24            sample_ratio,
25        }
26    }
27
28    pub fn __str__(&self) -> String {
29        PyHelperFuncs::__str__(self)
30    }
31}
32
33impl SpanExporterBuilder for StdoutSpanExporter {
34    type Exporter = OTelStdoutSpanExporter;
35
36    fn export_type(&self) -> ExporterType {
37        ExporterType::Stdout
38    }
39
40    fn sample_ratio(&self) -> Option<f64> {
41        self.sample_ratio
42    }
43
44    fn batch_export(&self) -> bool {
45        self.batch_export
46    }
47
48    fn build_exporter(&self) -> Result<Self::Exporter, TraceError> {
49        Ok(OTelStdoutSpanExporter::default())
50    }
51}