Skip to content

Commit 94caea2

Browse files
authored
Merge branch 'main' into int-test-fiox
2 parents 3d56a4f + c51c4b2 commit 94caea2

File tree

4 files changed

+86
-23
lines changed

4 files changed

+86
-23
lines changed

opentelemetry-sdk/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ metadata, a feature introduced in version 0.1.40. [#2418](https://github.com/ope
217217
- Update `EnvResourceDetector` to allow resource attribute values containing
218218
equal signs (`"="`). [#2120](https://github.com/open-telemetry/opentelemetry-rust/pull/2120)
219219

220+
- **Breaking** Introduced `experimental_async_runtime` feature for runtime-specific traits.
221+
- Runtime-specific features (`rt-tokio`, `rt-tokio-current-thread`, and `rt-async-std`)
222+
now depend on the `experimental_async_runtime` feature.
223+
- For most users, no action is required. Enabling runtime features such as `rt-tokio`, `rt-tokio-current-thread`,
224+
or `rt-async-std` will automatically enable the `experimental_async_runtime` feature.
225+
- If you're implementing a custom runtime, you must explicitly enable the experimental_async_runtime` feature in your
226+
Cargo.toml and implement the required `Runtime` traits.
227+
220228
## 0.27.1
221229

222230
Released 2024-Nov-27

opentelemetry-sdk/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ logs = ["opentelemetry/logs", "serde_json"]
4949
spec_unstable_logs_enabled = ["logs", "opentelemetry/spec_unstable_logs_enabled"]
5050
metrics = ["opentelemetry/metrics", "glob", "async-trait"]
5151
testing = ["opentelemetry/testing", "trace", "metrics", "logs", "rt-async-std", "rt-tokio", "rt-tokio-current-thread", "tokio/macros", "tokio/rt-multi-thread"]
52-
rt-tokio = ["tokio", "tokio-stream"]
53-
rt-tokio-current-thread = ["tokio", "tokio-stream"]
54-
rt-async-std = ["async-std"]
52+
experimental_async_runtime = []
53+
rt-tokio = ["tokio", "tokio-stream", "experimental_async_runtime"]
54+
rt-tokio-current-thread = ["tokio", "tokio-stream", "experimental_async_runtime"]
55+
rt-async-std = ["async-std", "experimental_async_runtime"]
5556
internal-logs = ["tracing"]
5657
experimental_metrics_periodicreader_with_async_runtime = ["metrics"]
5758
spec_unstable_metrics_views = ["metrics"]

opentelemetry-sdk/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
//! Support for recording and exporting telemetry asynchronously and perform
9595
//! metrics aggregation can be added via the following flags:
9696
//!
97+
//! * `experimental_async_runtime`: Enables the experimental `Runtime` trait and related functionality.
9798
//! * `rt-tokio`: Spawn telemetry tasks using [tokio]'s multi-thread runtime.
9899
//! * `rt-tokio-current-thread`: Spawn telemetry tasks on a separate runtime so that the main runtime won't be blocked.
99100
//! * `rt-async-std`: Spawn telemetry tasks using [async-std]'s runtime.
@@ -133,6 +134,7 @@ pub mod metrics;
133134
#[cfg_attr(docsrs, doc(cfg(feature = "trace")))]
134135
pub mod propagation;
135136
pub mod resource;
137+
#[cfg(feature = "experimental_async_runtime")]
136138
pub mod runtime;
137139
#[cfg(any(feature = "testing", test))]
138140
#[cfg_attr(docsrs, doc(cfg(any(feature = "testing", test))))]

opentelemetry-sdk/src/runtime.rs

+72-20
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use thiserror::Error;
1515
///
1616
/// [Tokio]: https://crates.io/crates/tokio
1717
/// [async-std]: https://crates.io/crates/async-std
18+
#[cfg(feature = "experimental_async_runtime")]
1819
pub trait Runtime: Clone + Send + Sync + 'static {
1920
/// A future stream, which returns items in a previously specified interval. The item type is
2021
/// not important.
@@ -44,13 +45,19 @@ pub trait Runtime: Clone + Send + Sync + 'static {
4445
}
4546

4647
/// Runtime implementation, which works with Tokio's multi thread runtime.
47-
#[cfg(feature = "rt-tokio")]
48-
#[cfg_attr(docsrs, doc(cfg(feature = "rt-tokio")))]
48+
#[cfg(all(feature = "experimental_async_runtime", feature = "rt-tokio"))]
49+
#[cfg_attr(
50+
docsrs,
51+
doc(cfg(all(feature = "experimental_async_runtime", feature = "rt-tokio")))
52+
)]
4953
#[derive(Debug, Clone)]
5054
pub struct Tokio;
5155

52-
#[cfg(feature = "rt-tokio")]
53-
#[cfg_attr(docsrs, doc(cfg(feature = "rt-tokio")))]
56+
#[cfg(all(feature = "experimental_async_runtime", feature = "rt-tokio"))]
57+
#[cfg_attr(
58+
docsrs,
59+
doc(cfg(all(feature = "experimental_async_runtime", feature = "rt-tokio")))
60+
)]
5461
impl Runtime for Tokio {
5562
type Interval = tokio_stream::wrappers::IntervalStream;
5663
type Delay = ::std::pin::Pin<Box<tokio::time::Sleep>>;
@@ -71,13 +78,31 @@ impl Runtime for Tokio {
7178
}
7279

7380
/// Runtime implementation, which works with Tokio's current thread runtime.
74-
#[cfg(feature = "rt-tokio-current-thread")]
75-
#[cfg_attr(docsrs, doc(cfg(feature = "rt-tokio-current-thread")))]
81+
#[cfg(all(
82+
feature = "experimental_async_runtime",
83+
feature = "rt-tokio-current-thread"
84+
))]
85+
#[cfg_attr(
86+
docsrs,
87+
doc(cfg(all(
88+
feature = "experimental_async_runtime",
89+
feature = "rt-tokio-current-thread"
90+
)))
91+
)]
7692
#[derive(Debug, Clone)]
7793
pub struct TokioCurrentThread;
7894

79-
#[cfg(feature = "rt-tokio-current-thread")]
80-
#[cfg_attr(docsrs, doc(cfg(feature = "rt-tokio-current-thread")))]
95+
#[cfg(all(
96+
feature = "experimental_async_runtime",
97+
feature = "rt-tokio-current-thread"
98+
))]
99+
#[cfg_attr(
100+
docsrs,
101+
doc(cfg(all(
102+
feature = "experimental_async_runtime",
103+
feature = "rt-tokio-current-thread"
104+
)))
105+
)]
81106
impl Runtime for TokioCurrentThread {
82107
type Interval = tokio_stream::wrappers::IntervalStream;
83108
type Delay = ::std::pin::Pin<Box<tokio::time::Sleep>>;
@@ -108,13 +133,19 @@ impl Runtime for TokioCurrentThread {
108133
}
109134

110135
/// Runtime implementation, which works with async-std.
111-
#[cfg(feature = "rt-async-std")]
112-
#[cfg_attr(docsrs, doc(cfg(feature = "rt-async-std")))]
136+
#[cfg(all(feature = "experimental_async_runtime", feature = "rt-async-std"))]
137+
#[cfg_attr(
138+
docsrs,
139+
doc(cfg(all(feature = "experimental_async_runtime", feature = "rt-async-std")))
140+
)]
113141
#[derive(Debug, Clone)]
114142
pub struct AsyncStd;
115143

116-
#[cfg(feature = "rt-async-std")]
117-
#[cfg_attr(docsrs, doc(cfg(feature = "rt-async-std")))]
144+
#[cfg(all(feature = "experimental_async_runtime", feature = "rt-async-std"))]
145+
#[cfg_attr(
146+
docsrs,
147+
doc(cfg(all(feature = "experimental_async_runtime", feature = "rt-async-std")))
148+
)]
118149
impl Runtime for AsyncStd {
119150
type Interval = async_std::stream::Interval;
120151
type Delay = BoxFuture<'static, ()>;
@@ -138,6 +169,7 @@ impl Runtime for AsyncStd {
138169
///
139170
/// [log]: crate::logs::BatchLogProcessor
140171
/// [span]: crate::trace::BatchSpanProcessor
172+
#[cfg(feature = "experimental_async_runtime")]
141173
pub trait RuntimeChannel: Runtime {
142174
/// A future stream to receive batch messages from channels.
143175
type Receiver<T: Debug + Send>: Stream<Item = T> + Send;
@@ -152,6 +184,7 @@ pub trait RuntimeChannel: Runtime {
152184
}
153185

154186
/// Error returned by a [`TrySend`] implementation.
187+
#[cfg(feature = "experimental_async_runtime")]
155188
#[derive(Debug, Error)]
156189
pub enum TrySendError {
157190
/// Send failed due to the channel being full.
@@ -166,6 +199,7 @@ pub enum TrySendError {
166199
}
167200

168201
/// TrySend is an abstraction of `Sender` that is capable of sending messages through a reference.
202+
#[cfg(feature = "experimental_async_runtime")]
169203
pub trait TrySend: Sync + Send {
170204
/// The message that will be sent.
171205
type Message;
@@ -176,7 +210,10 @@ pub trait TrySend: Sync + Send {
176210
fn try_send(&self, item: Self::Message) -> Result<(), TrySendError>;
177211
}
178212

179-
#[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))]
213+
#[cfg(all(
214+
feature = "experimental_async_runtime",
215+
any(feature = "rt-tokio", feature = "rt-tokio-current-thread")
216+
))]
180217
impl<T: Send> TrySend for tokio::sync::mpsc::Sender<T> {
181218
type Message = T;
182219

@@ -188,8 +225,11 @@ impl<T: Send> TrySend for tokio::sync::mpsc::Sender<T> {
188225
}
189226
}
190227

191-
#[cfg(feature = "rt-tokio")]
192-
#[cfg_attr(docsrs, doc(cfg(feature = "rt-tokio")))]
228+
#[cfg(all(feature = "experimental_async_runtime", feature = "rt-tokio"))]
229+
#[cfg_attr(
230+
docsrs,
231+
doc(cfg(all(feature = "experimental_async_runtime", feature = "rt-tokio")))
232+
)]
193233
impl RuntimeChannel for Tokio {
194234
type Receiver<T: Debug + Send> = tokio_stream::wrappers::ReceiverStream<T>;
195235
type Sender<T: Debug + Send> = tokio::sync::mpsc::Sender<T>;
@@ -206,8 +246,17 @@ impl RuntimeChannel for Tokio {
206246
}
207247
}
208248

209-
#[cfg(feature = "rt-tokio-current-thread")]
210-
#[cfg_attr(docsrs, doc(cfg(feature = "rt-tokio-current-thread")))]
249+
#[cfg(all(
250+
feature = "experimental_async_runtime",
251+
feature = "rt-tokio-current-thread"
252+
))]
253+
#[cfg_attr(
254+
docsrs,
255+
doc(cfg(all(
256+
feature = "experimental_async_runtime",
257+
feature = "rt-tokio-current-thread"
258+
)))
259+
)]
211260
impl RuntimeChannel for TokioCurrentThread {
212261
type Receiver<T: Debug + Send> = tokio_stream::wrappers::ReceiverStream<T>;
213262
type Sender<T: Debug + Send> = tokio::sync::mpsc::Sender<T>;
@@ -224,7 +273,7 @@ impl RuntimeChannel for TokioCurrentThread {
224273
}
225274
}
226275

227-
#[cfg(feature = "rt-async-std")]
276+
#[cfg(all(feature = "experimental_async_runtime", feature = "rt-async-std"))]
228277
impl<T: Send> TrySend for async_std::channel::Sender<T> {
229278
type Message = T;
230279

@@ -236,8 +285,11 @@ impl<T: Send> TrySend for async_std::channel::Sender<T> {
236285
}
237286
}
238287

239-
#[cfg(feature = "rt-async-std")]
240-
#[cfg_attr(docsrs, doc(cfg(feature = "rt-async-std")))]
288+
#[cfg(all(feature = "experimental_async_runtime", feature = "rt-async-std"))]
289+
#[cfg_attr(
290+
docsrs,
291+
doc(cfg(all(feature = "experimental_async_runtime", feature = "rt-async-std")))
292+
)]
241293
impl RuntimeChannel for AsyncStd {
242294
type Receiver<T: Debug + Send> = async_std::channel::Receiver<T>;
243295
type Sender<T: Debug + Send> = async_std::channel::Sender<T>;

0 commit comments

Comments
 (0)