File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
opentelemetry-sdk/src/trace Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments