Skip to content

Commit 8a19bf3

Browse files
committed
move to tracer
1 parent 06e69dc commit 8a19bf3

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

opentelemetry-sdk/CHANGELOG.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
## vNext
44

5-
`SdkLogger` modified to respect telemetry suppression based on `Context`. A
6-
similar change is done for Tracing signal too, by returning `Sampling::Drop`
7-
when telemetry is suppressed. In other words, if the current context has
8-
telemetry suppression enabled, then logs/spans will be ignored. The flag is
9-
typically set by OTel components to prevent telemetry from itself being fed back
10-
into OTel. `BatchLogProcessor`, `BatchSpanProcessor`, and `PeriodicReader`
11-
modified to set the suppression flag in their dedicated thread, so that
12-
telemetry generated from those threads will not be fed back into OTel.
13-
Similarly, `SimpleLogProcessor` also modified to suppress telemetry before
14-
invoking exporters.
5+
`SdkLogger`, `SdkTracer` modified to respect telemetry suppression based on
6+
`Context`. In other words, if the current context has telemetry suppression
7+
enabled, then logs/spans will be ignored. The flag is typically set by OTel
8+
components to prevent telemetry from itself being fed back into OTel.
9+
`BatchLogProcessor`, `BatchSpanProcessor`, and `PeriodicReader` modified to set
10+
the suppression flag in their dedicated thread, so that telemetry generated from
11+
those threads will not be fed back into OTel. Similarly, `SimpleLogProcessor`
12+
also modified to suppress telemetry before invoking exporters.
1513

1614
## 0.29.0
1715

opentelemetry-sdk/src/trace/sampler.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,6 @@ 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: Can we move this even earlier, i.e. in the Tracer itself?
181-
// TODO: Check and fix: why this methods gets Option<&Context> and not
182-
// Context?
183-
if let Some(parent_context) = parent_context {
184-
if parent_context.is_telemetry_suppressed() {
185-
return SamplingResult {
186-
decision: SamplingDecision::Drop,
187-
// No extra attributes ever set by the SDK samplers.
188-
attributes: Vec::new(),
189-
// all sampler in SDK will not modify trace state.
190-
trace_state: TraceState::default(),
191-
};
192-
}
193-
}
194175
let decision = match self {
195176
// Always sample the trace
196177
Sampler::AlwaysOn => SamplingDecision::RecordAndSample,

opentelemetry-sdk/src/trace/tracer.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ impl opentelemetry::trace::Tracer for SdkTracer {
178178
/// trace includes a single root span, which is the shared ancestor of all other
179179
/// spans in the trace.
180180
fn build_with_context(&self, mut builder: SpanBuilder, parent_cx: &Context) -> Self::Span {
181+
if parent_cx.is_telemetry_suppressed() {
182+
return Span::new(
183+
SpanContext::empty_context(),
184+
None,
185+
self.clone(),
186+
SpanLimits::default(),
187+
);
188+
}
189+
181190
let provider = self.provider();
182191
// no point start a span if the tracer provider has already being shutdown
183192
if provider.is_shutdown() {

0 commit comments

Comments
 (0)