-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support trace-level sampling #7
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "tracing-honeycomb" | ||
version = "0.2.0" | ||
version = "0.2.1" | ||
authors = ["Inanna Malick <[email protected]>"] | ||
edition = "2018" | ||
description = "Honeycomb.io tracing layer for multiprocess telemetry" | ||
|
@@ -13,7 +13,7 @@ readme = "README.md" | |
[dependencies] | ||
tracing = "0.1.12" | ||
tracing-core = "0.1.9" | ||
tracing-distributed = { path = "../tracing-distributed" , version = "0.2.0"} | ||
tracing-distributed = { path = "../tracing-distributed", version = "0.2.0" } | ||
libhoney-rust = "0.1.3" | ||
rand = "0.7" | ||
chrono = "0.4.9" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,17 +9,18 @@ use tracing_distributed::{Event, Span, Telemetry}; | |
#[derive(Debug)] | ||
pub struct HoneycombTelemetry { | ||
honeycomb_client: Mutex<libhoney::Client<libhoney::transmission::Transmission>>, | ||
sample_rate: usize, | ||
} | ||
|
||
impl HoneycombTelemetry { | ||
pub(crate) fn new(cfg: libhoney::Config) -> Self { | ||
pub(crate) fn new(cfg: libhoney::Config, sample_rate: usize) -> Self { | ||
let honeycomb_client = libhoney::init(cfg); | ||
|
||
// publishing requires &mut so just mutex-wrap it | ||
// FIXME: may not be performant, investigate options (eg mpsc) | ||
let honeycomb_client = Mutex::new(honeycomb_client); | ||
|
||
HoneycombTelemetry { honeycomb_client } | ||
HoneycombTelemetry { honeycomb_client, sample_rate } | ||
} | ||
|
||
fn report_data(&self, data: HashMap<String, ::libhoney::Value>) { | ||
|
@@ -34,6 +35,14 @@ impl HoneycombTelemetry { | |
eprintln!("error sending event to honeycomb, {:?}", err); | ||
} | ||
} | ||
|
||
fn should_report(&self, trace_id: TraceId) -> bool { | ||
if self.sample_rate <= 1 { | ||
return true; | ||
} | ||
|
||
trace_id.0 as usize % self.sample_rate == 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is clever but I would have expected the sample rate to be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also expect a float of some sort here - maybe an f32, with a 0 to 1 range There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, it looks like you're using sample_rate <= 1 to signify 'sample everything' - how do you feel about making this an |
||
} | ||
} | ||
|
||
impl Telemetry for HoneycombTelemetry { | ||
|
@@ -46,13 +55,17 @@ impl Telemetry for HoneycombTelemetry { | |
} | ||
|
||
fn report_span(&self, span: Span<Self::Visitor, Self::SpanId, Self::TraceId>) { | ||
let data = span_to_values(span); | ||
self.report_data(data); | ||
if self.should_report(span.trace_id) { | ||
let data = span_to_values(span); | ||
self.report_data(data); | ||
} | ||
} | ||
|
||
fn report_event(&self, event: Event<Self::Visitor, Self::SpanId, Self::TraceId>) { | ||
let data = event_to_values(event); | ||
self.report_data(data); | ||
if self.should_report(event.trace_id) { | ||
let data = event_to_values(event); | ||
self.report_data(data); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw 0.2 isn't even out yet, see #5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.2 is out, I just never published it (sorry, 2020 has been.. very 2020 recently) https://github.com/inanna-malick/tracing-honeycomb/blob/master/tracing-honeycomb/Cargo.toml#L3