Skip to content

Commit 759b539

Browse files
authored
chore(sampling): move sdk types from opentelemetry to opentelemetry_sdk (#3277)
1 parent 483b420 commit 759b539

File tree

9 files changed

+49
-46
lines changed

9 files changed

+49
-46
lines changed

opentelemetry-sdk/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
- Added `Resource::get_ref(&self, key: &Key) -> Option<&Value>` to allow retrieving a reference to a resource value without cloning.
66
- **Breaking** Removed the following public hidden methods from the `SdkTracer` [#3227][3227]:
77
- `id_generator`, `should_sample`
8+
- **Breaking** Moved the following SDK sampling types from `opentelemetry::trace` to `opentelemetry_sdk::trace` [#3277][3277]:
9+
- `SamplingDecision`, `SamplingResult`
10+
- These types are SDK implementation details and should be imported from `opentelemetry_sdk::trace` instead.
811

912
[3227]: https://github.com/open-telemetry/opentelemetry-rust/pull/3227
13+
[3277]: https://github.com/open-telemetry/opentelemetry-rust/pull/3277
1014

1115
## 0.31.0
1216

opentelemetry-sdk/src/trace/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub use in_memory_exporter::{InMemorySpanExporter, InMemorySpanExporterBuilder};
3838
pub use id_generator::{IdGenerator, RandomIdGenerator};
3939
pub use links::SpanLinks;
4040
pub use provider::{SdkTracerProvider, TracerProviderBuilder};
41-
pub use sampler::{Sampler, ShouldSample};
41+
pub use sampler::{Sampler, SamplingDecision, SamplingResult, ShouldSample};
4242
pub use span::Span;
4343
pub use span_limit::SpanLimits;
4444
pub use span_processor::{
@@ -60,13 +60,14 @@ mod runtime_tests;
6060
mod tests {
6161
use super::*;
6262
use crate::error::OTelSdkResult;
63+
use crate::trace::{SamplingDecision, SamplingResult};
6364
use crate::{
6465
trace::span_limit::{DEFAULT_MAX_EVENT_PER_SPAN, DEFAULT_MAX_LINKS_PER_SPAN},
6566
trace::{InMemorySpanExporter, InMemorySpanExporterBuilder},
6667
};
6768
use opentelemetry::{
6869
baggage::BaggageExt,
69-
trace::{SamplingDecision, SamplingResult, SpanKind, Status, TraceContextExt, TraceState},
70+
trace::{SpanKind, Status, TraceContextExt, TraceState},
7071
};
7172
use opentelemetry::{testing::trace::TestSpan, InstrumentationScope};
7273
use opentelemetry::{

opentelemetry-sdk/src/trace/sampler.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
use opentelemetry::{
2-
trace::{
3-
Link, SamplingDecision, SamplingResult, SpanKind, TraceContextExt, TraceId, TraceState,
4-
},
2+
trace::{Link, SpanKind, TraceContextExt, TraceId, TraceState},
53
Context, KeyValue,
64
};
75

86
#[cfg(feature = "jaeger_remote_sampler")]
97
mod jaeger_remote;
108

9+
/// The result of sampling logic for a given span.
10+
#[derive(Clone, Debug, PartialEq)]
11+
pub struct SamplingResult {
12+
/// The decision about whether or not to sample.
13+
pub decision: SamplingDecision,
14+
15+
/// Extra attributes to be added to the span by the sampler
16+
pub attributes: Vec<KeyValue>,
17+
18+
/// Trace state from parent context, may be modified by samplers.
19+
pub trace_state: TraceState,
20+
}
21+
22+
/// Decision about whether or not to sample
23+
#[derive(Clone, Debug, PartialEq, Eq)]
24+
pub enum SamplingDecision {
25+
/// Span will not be recorded and all events and attributes will be dropped.
26+
Drop,
27+
28+
/// Span data wil be recorded, but not exported.
29+
RecordOnly,
30+
31+
/// Span data will be recorded and exported.
32+
RecordAndSample,
33+
}
34+
1135
#[cfg(feature = "jaeger_remote_sampler")]
1236
pub use jaeger_remote::{JaegerRemoteSampler, JaegerRemoteSamplerBuilder};
1337
#[cfg(feature = "jaeger_remote_sampler")]

opentelemetry-sdk/src/trace/sampler/jaeger_remote/sampler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use crate::runtime::{to_interval_stream, RuntimeChannel};
22
use crate::trace::error::TraceError;
33
use crate::trace::sampler::jaeger_remote::remote::SamplingStrategyResponse;
44
use crate::trace::sampler::jaeger_remote::sampling_strategy::Inner;
5-
use crate::trace::{Sampler, ShouldSample};
5+
use crate::trace::{Sampler, SamplingResult, ShouldSample};
66
use futures_util::{stream, StreamExt as _};
77
use http::Uri;
8-
use opentelemetry::trace::{Link, SamplingResult, SpanKind, TraceId};
8+
use opentelemetry::trace::{Link, SpanKind, TraceId};
99
use opentelemetry::{otel_warn, Context, KeyValue};
1010
use opentelemetry_http::HttpClient;
1111
use std::str::FromStr;

opentelemetry-sdk/src/trace/sampler/jaeger_remote/sampling_strategy.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use crate::trace::sampler::jaeger_remote::remote::{
33
SamplingStrategyResponse,
44
};
55
use crate::trace::sampler::sample_based_on_probability;
6-
use opentelemetry::trace::{
7-
SamplingDecision, SamplingResult, TraceContextExt, TraceId, TraceState,
8-
};
6+
use crate::trace::{SamplingDecision, SamplingResult};
7+
use opentelemetry::trace::{TraceContextExt, TraceId, TraceState};
98
use opentelemetry::{otel_warn, Context};
109
use std::collections::HashMap;
1110
use std::fmt::{Debug, Formatter};

opentelemetry-sdk/src/trace/tracer.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010
use crate::trace::{
1111
provider::SdkTracerProvider,
1212
span::{Span, SpanData},
13-
SpanEvents, SpanLimits, SpanLinks,
13+
SamplingDecision, SpanEvents, SpanLimits, SpanLinks,
1414
};
1515
use opentelemetry::{
16-
trace::{
17-
SamplingDecision, Span as _, SpanBuilder, SpanContext, SpanKind, Status, TraceContextExt,
18-
TraceFlags,
19-
},
16+
trace::{Span as _, SpanBuilder, SpanContext, SpanKind, Status, TraceContextExt, TraceFlags},
2017
Context, InstrumentationScope, KeyValue,
2118
};
2219
use std::fmt;
@@ -270,12 +267,12 @@ impl opentelemetry::trace::Tracer for SdkTracer {
270267
mod tests {
271268
use crate::{
272269
testing::trace::TestSpan,
273-
trace::{Sampler, ShouldSample},
270+
trace::{Sampler, SamplingDecision, SamplingResult, ShouldSample},
274271
};
275272
use opentelemetry::{
276273
trace::{
277-
Link, SamplingDecision, SamplingResult, Span, SpanContext, SpanId, SpanKind,
278-
TraceContextExt, TraceFlags, TraceId, TraceState, Tracer, TracerProvider,
274+
Link, Span, SpanContext, SpanId, SpanKind, TraceContextExt, TraceFlags, TraceId,
275+
TraceState, Tracer, TracerProvider,
279276
},
280277
Context, KeyValue,
281278
};

opentelemetry/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
- `trace_id`, `span_id`, `end_time`, `status`, `sampling_result`
88
- `with_trace_id`, `with_span_id`, `with_end_time`, `with_status`, `with_sampling_result`
99
- **Added** `#[must_use]` attribute to `opentelemetry::metrics::AsyncInstrumentBuilder` to add compile time warning when `.build()` is not called on observable instrument builders, preventing silent failures where callbacks are never registered and metrics are never reported.
10+
- **Breaking** Moved the following SDK sampling types from `opentelemetry::trace` to `opentelemetry_sdk::trace` [#3277][3277]:
11+
- `SamplingDecision`, `SamplingResult`
12+
- These types are SDK implementation details and should be imported from `opentelemetry_sdk::trace` instead.
1013

1114
[3227]: https://github.com/open-telemetry/opentelemetry-rust/pull/3227
15+
[3277]: https://github.com/open-telemetry/opentelemetry-rust/pull/3277
1216

1317
## v0.31.0
1418

opentelemetry/src/trace/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub use self::{
181181
},
182182
span::{Span, SpanKind, Status},
183183
span_context::{SpanContext, TraceState},
184-
tracer::{SamplingDecision, SamplingResult, SpanBuilder, Tracer},
184+
tracer::{SpanBuilder, Tracer},
185185
tracer_provider::TracerProvider,
186186
};
187187
use crate::KeyValue;

opentelemetry/src/trace/tracer.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
trace::{Event, Link, Span, SpanKind, TraceContextExt, TraceState},
2+
trace::{Event, Link, Span, SpanKind, TraceContextExt},
33
Context, KeyValue,
44
};
55
use std::borrow::Cow;
@@ -328,29 +328,3 @@ impl SpanBuilder {
328328
tracer.build_with_context(self, parent_cx)
329329
}
330330
}
331-
332-
/// The result of sampling logic for a given span.
333-
#[derive(Clone, Debug, PartialEq)]
334-
pub struct SamplingResult {
335-
/// The decision about whether or not to sample.
336-
pub decision: SamplingDecision,
337-
338-
/// Extra attributes to be added to the span by the sampler
339-
pub attributes: Vec<KeyValue>,
340-
341-
/// Trace state from parent context, may be modified by samplers.
342-
pub trace_state: TraceState,
343-
}
344-
345-
/// Decision about whether or not to sample
346-
#[derive(Clone, Debug, PartialEq, Eq)]
347-
pub enum SamplingDecision {
348-
/// Span will not be recorded and all events and attributes will be dropped.
349-
Drop,
350-
351-
/// Span data wil be recorded, but not exported.
352-
RecordOnly,
353-
354-
/// Span data will be recorded and exported.
355-
RecordAndSample,
356-
}

0 commit comments

Comments
 (0)