tracing_honeycomb/
reporter.rsuse chrono::{DateTime, Utc};
use libhoney::FieldHolder;
use std::collections::HashMap;
#[cfg(feature = "use_parking_lot")]
use parking_lot::Mutex;
#[cfg(not(feature = "use_parking_lot"))]
use std::sync::Mutex;
pub trait Reporter {
fn report_data(&self, data: HashMap<String, libhoney::Value>, timestamp: DateTime<Utc>);
}
pub type LibhoneyReporter = Mutex<libhoney::Client<libhoney::transmission::Transmission>>;
impl Reporter for LibhoneyReporter {
fn report_data(&self, data: HashMap<String, libhoney::Value>, timestamp: DateTime<Utc>) {
#[cfg(not(feature = "use_parking_lot"))]
let mut reporter = self.lock().unwrap();
#[cfg(feature = "use_parking_lot")]
let mut reporter = self.lock();
let mut ev = reporter.new_event();
ev.add(data);
ev.set_timestamp(timestamp);
let res = ev.send(&mut reporter);
if let Err(err) = res {
eprintln!("error sending event to honeycomb, {:?}", err);
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct StdoutReporter;
impl Reporter for StdoutReporter {
fn report_data(&self, data: HashMap<String, libhoney::Value>, _timestamp: DateTime<Utc>) {
if let Ok(data) = serde_json::to_string(&data) {
println!("{}", data);
}
}
}