-
Notifications
You must be signed in to change notification settings - Fork 7
/
otelstdout.rs
39 lines (34 loc) · 1.11 KB
/
otelstdout.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::vec;
use crate::TraceEvent;
use anyhow::Result;
use super::{otel_formatter::OtelFormatter, Adapter, AdapterHandle};
/// An adapter to send events from your module to stdout using OpenTelemetry json format.
pub struct OtelStdoutAdapter {}
impl Adapter for OtelStdoutAdapter {
fn handle_trace_event(&mut self, trace_evt: TraceEvent) -> Result<()> {
let mut spans = vec![];
let trace_id = trace_evt.telemetry_id.to_hex_16();
for span in trace_evt.events {
self.event_to_otel_spans(
&mut spans,
span,
vec![],
trace_id.clone(),
&trace_evt.metadata,
)?;
}
if !spans.is_empty() {
let otf = OtelFormatter::new(spans, "stdout".into());
println!("{:?}", &otf.traces_data);
}
Ok(())
}
}
impl OtelStdoutAdapter {
/// Creates the Otel Stdout adapter and spawns a task for it.
/// This should ideally be created once per process of
/// your rust application.
pub fn create() -> AdapterHandle {
Self::spawn(Self {})
}
}