Skip to content

Commit

Permalink
Use latest sampler decision names (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtescher authored Oct 6, 2020
1 parent 90a6e36 commit 503503c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions src/sdk/trace/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ pub struct SamplingResult {
pub enum SamplingDecision {
/// `is_recording() == false`, span will not be recorded and all events and
/// attributes will be dropped.
NotRecord,
Drop,
/// `is_recording() == true`, but `Sampled` flag MUST NOT be set.
Record,
RecordOnly,
/// `is_recording() == true` AND `Sampled` flag` MUST be set.
RecordAndSampled,
RecordAndSample,
}

/// Sampling options
Expand Down Expand Up @@ -107,35 +107,35 @@ impl ShouldSample for Sampler {
) -> SamplingResult {
let decision = match self {
// Always sample the trace
Sampler::AlwaysOn => SamplingDecision::RecordAndSampled,
Sampler::AlwaysOn => SamplingDecision::RecordAndSample,
// Never sample the trace
Sampler::AlwaysOff => SamplingDecision::NotRecord,
Sampler::AlwaysOff => SamplingDecision::Drop,
// The parent decision if sampled; otherwise the decision of delegate_sampler
Sampler::ParentBased(delegate_sampler) => parent_context.map_or(
delegate_sampler
.should_sample(parent_context, trace_id, name, span_kind, attributes, links)
.decision,
|ctx| {
if ctx.is_sampled() {
SamplingDecision::RecordAndSampled
SamplingDecision::RecordAndSample
} else {
SamplingDecision::NotRecord
SamplingDecision::Drop
}
},
),
// Probabilistically sample the trace.
Sampler::TraceIdRatioBased(prob) => {
if *prob >= 1.0 {
SamplingDecision::RecordAndSampled
SamplingDecision::RecordAndSample
} else {
let prob_upper_bound = (prob.max(0.0) * (1u64 << 63) as f64) as u64;
// The trace_id is already randomly generated, so we don't need a new one here
let rnd_from_trace_id = (trace_id.to_u128() as u64) >> 1;

if rnd_from_trace_id < prob_upper_bound {
SamplingDecision::RecordAndSampled
SamplingDecision::RecordAndSample
} else {
SamplingDecision::NotRecord
SamplingDecision::Drop
}
}
}
Expand Down Expand Up @@ -241,7 +241,7 @@ mod tests {
&[],
)
.decision
== SamplingDecision::RecordAndSampled
== SamplingDecision::RecordAndSample
{
sampled += 1;
}
Expand Down
8 changes: 4 additions & 4 deletions src/sdk/trace/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ impl Tracer {
) -> Option<(u8, Vec<api::KeyValue>, TraceState)> {
match sampling_result {
sdk::SamplingResult {
decision: sdk::SamplingDecision::NotRecord,
decision: sdk::SamplingDecision::Drop,
..
} => None,
sdk::SamplingResult {
decision: sdk::SamplingDecision::Record,
decision: sdk::SamplingDecision::RecordOnly,
attributes,
trace_state,
} => {
Expand All @@ -97,7 +97,7 @@ impl Tracer {
))
}
sdk::SamplingResult {
decision: sdk::SamplingDecision::RecordAndSampled,
decision: sdk::SamplingDecision::RecordAndSample,
attributes,
trace_state,
} => {
Expand Down Expand Up @@ -302,7 +302,7 @@ mod tests {
) -> SamplingResult {
let trace_state = parent_context.unwrap().trace_state().clone();
SamplingResult {
decision: SamplingDecision::RecordAndSampled,
decision: SamplingDecision::RecordAndSample,
attributes: Vec::new(),
trace_state: trace_state.insert("foo".into(), "notbar".into()).unwrap(),
}
Expand Down

0 comments on commit 503503c

Please sign in to comment.