Skip to content

Commit 52604ef

Browse files
committed
Check suppression during sampling
1 parent 2440573 commit 52604ef

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

opentelemetry-sdk/src/trace/sampler.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,24 @@ impl ShouldSample for Sampler {
172172
attributes: &[KeyValue],
173173
links: &[Link],
174174
) -> SamplingResult {
175+
// Checking suppression mode in sampler is more efficient than checking
176+
// it in the span processor as this allows earlier short-circuiting.
177+
// Also, it is currently *NOT* possible to check suppression mode or
178+
// even access current context in the span processor's OnEnd method. See
179+
// https://github.com/open-telemetry/opentelemetry-rust/issues/2871
180+
// TODO: Check and fix: why this methods gets Option<&Context> and not
181+
// Context?
182+
if let Some(parent_context) = parent_context {
183+
if parent_context.is_telemetry_suppressed() {
184+
return SamplingResult {
185+
decision: SamplingDecision::Drop,
186+
// No extra attributes ever set by the SDK samplers.
187+
attributes: Vec::new(),
188+
// all sampler in SDK will not modify trace state.
189+
trace_state: TraceState::default(),
190+
};
191+
}
192+
}
175193
let decision = match self {
176194
// Always sample the trace
177195
Sampler::AlwaysOn => SamplingDecision::RecordAndSample,

opentelemetry-sdk/src/trace/span_processor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ impl<T: SpanExporter> SpanProcessor for SimpleSpanProcessor<T> {
130130
}
131131

132132
fn on_end(&self, span: SpanData) {
133-
let _suppress_guard = Context::enter_telemetry_suppressed_scope();
134133
if !span.span_context.is_sampled() {
135134
return;
136135
}

0 commit comments

Comments
 (0)