Skip to content

Commit b878197

Browse files
committed
Doc additions to warn about tokio current
1 parent a81ad24 commit b878197

File tree

3 files changed

+92
-22
lines changed

3 files changed

+92
-22
lines changed

opentelemetry-sdk/src/logs/log_processor.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,33 @@ type LogsData = Box<(LogRecord, InstrumentationScope)>;
228228
/// individually. It uses a **dedicated background thread** to manage and export logs
229229
/// asynchronously, ensuring that the application's main execution flow is not blocked.
230230
///
231-
/// - This processor supports the following configurations:
232-
/// - **Queue size**: Maximum number of log records that can be buffered.
233-
/// - **Batch size**: Maximum number of log records to include in a single export.
234-
/// - **Scheduled delay**: Frequency at which the batch is exported.
231+
/// This processor supports the following configurations:
232+
/// - **Queue size**: Maximum number of log records that can be buffered.
233+
/// - **Batch size**: Maximum number of log records to include in a single export.
234+
/// - **Scheduled delay**: Frequency at which the batch is exported.
235235
///
236236
/// When using this processor with the OTLP Exporter, the following exporter
237237
/// features are supported:
238-
/// - `grpc-tonic`: This requires `MeterProvider` to be created within a tokio
239-
/// runtime.
238+
/// - `grpc-tonic`: Requires `LoggerProvider` to be created within a tokio runtime.
240239
/// - `reqwest-blocking-client`: Works with a regular `main` or `tokio::main`.
241240
///
242241
/// In other words, other clients like `reqwest` and `hyper` are not supported.
243242
///
243+
/// `BatchLogProcessor` buffers logs in memory and exports them in batches. An
244+
/// export is triggered when `max_export_batch_size` is reached or every
245+
/// `scheduled_delay` milliseconds. Users can explicitly trigger an export using
246+
/// the `force_flush` method. Shutdown also triggers an export of all buffered
247+
/// logs and is recommended to be called before the application exits to ensure
248+
/// all buffered logs are exported.
249+
///
250+
/// **Warning**: When using tokio's current-thread runtime, `shutdown()`, which
251+
/// is a blocking call ,should not be called from your main thread. This can
252+
/// cause deadlock. Instead, call `shutdown()` from a separate thread or use
253+
/// tokio's `spawn_blocking`.
254+
///
255+
/// [`shutdown()`]: crate::logs::LoggerProvider::shutdown
256+
/// [`force_flush()`]: crate::logs::LoggerProvider::force_flush
257+
///
244258
/// ### Using a BatchLogProcessor:
245259
///
246260
/// ```rust

opentelemetry-sdk/src/metrics/periodic_reader.rs

+40-15
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,50 @@ where
9191
}
9292
}
9393

94-
/// A [MetricReader] that continuously collects and exports metrics at a set
95-
/// interval.
94+
/// A `MetricReader` that periodically collects and exports metrics at a configurable interval.
9695
///
97-
/// By default, `PeriodicReader` will collect and export metrics every 60
98-
/// seconds. The export time is not counted towards the interval between
99-
/// attempts. `PeriodicReader` itself does not enforce a timeout. Instead, the
100-
/// timeout is passed on to the configured exporter for each export attempt.
96+
/// By default, [`PeriodicReader`] collects and exports metrics every **60 seconds**.
97+
/// The time taken for export is **not** included in the interval. Use [`PeriodicReaderBuilder`]
98+
/// to customize the interval.
10199
///
102-
/// `PeriodicReader` spawns a background thread to handle the periodic
103-
/// collection and export of metrics. The background thread will continue to run
104-
/// until `shutdown()` is called.
100+
/// [`PeriodicReader`] spawns a background thread to handle metric collection and export.
101+
/// This thread remains active until [`shutdown()`] is called.
105102
///
106-
/// When using this reader with the OTLP Exporter, the following exporter
107-
/// features are supported:
108-
/// - `grpc-tonic`: This requires `MeterProvider` to be created within a tokio
109-
/// runtime.
110-
/// - `reqwest-blocking-client`: Works with a regular `main` or `tokio::main`.
103+
/// ## Collection Process
104+
/// "Collection" refers to gathering aggregated metrics from the SDK's internal storage.
105+
/// During this phase, callbacks from observable instruments are also triggered.
111106
///
112-
/// In other words, other clients like `reqwest` and `hyper` are not supported.
107+
/// [`PeriodicReader`] does **not** enforce a timeout for collection. If an
108+
/// observable callback takes too long, it may delay the next collection cycle.
109+
/// If a callback never returns, it **will stall** all metric collection (and exports)
110+
/// indefinitely.
111+
///
112+
/// ## Exporter Compatibility
113+
/// When used with the [`OTLP Exporter`](https://docs.rs/opentelemetry-otlp), the following
114+
/// transport options are supported:
115+
///
116+
/// - **`grpc-tonic`**: Requires [`MeterProvider`] to be initialized within a `tokio` runtime.
117+
/// - **`reqwest-blocking-client`**: Works with both a standard (`main`) function and `tokio::main`.
118+
///
119+
/// [`PeriodicReader`] does **not** enforce a timeout for exports either. Instead,
120+
/// the configured exporter is responsible for enforcing timeouts. If an export operation
121+
/// never returns, [`PeriodicReader`] will **stop exporting new metrics**, stalling
122+
/// metric collection.
123+
///
124+
/// ## Manual Export & Shutdown
125+
/// Users can manually trigger an export via [`force_flush()`]. Calling [`shutdown()`]
126+
/// exports any remaining metrics and should be done before application exit to ensure
127+
/// all data is sent.
128+
///
129+
/// **Warning**: If using **tokio’s current-thread runtime**, calling [`shutdown()`]
130+
/// from the main thread may cause a deadlock. To prevent this, call [`shutdown()`]
131+
/// from a separate thread or use tokio's `spawn_blocking`.
132+
///
133+
/// [`PeriodicReader`]: crate::metrics::PeriodicReader
134+
/// [`PeriodicReaderBuilder`]: crate::metrics::PeriodicReaderBuilder
135+
/// [`MeterProvider`]: crate::metrics::SdkMeterProvider
136+
/// [`shutdown()`]: crate::metrics::SdkMeterProvider::shutdown
137+
/// [`force_flush()`]: crate::metrics::SdkMeterProvider::force_flush
113138
///
114139
/// # Example
115140
///

opentelemetry-sdk/src/trace/span_processor.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,38 @@ enum BatchMessage {
253253
SetResource(Arc<Resource>),
254254
}
255255

256-
/// A batch span processor with a dedicated background thread.
256+
/// The `BatchSpanProcessor` collects finished spans in a buffer and exports them
257+
/// in batches to the configured `SpanExporter`. This processor is ideal for
258+
/// high-throughput environments, as it minimizes the overhead of exporting spans
259+
/// individually. It uses a **dedicated background thread** to manage and export spans
260+
/// asynchronously, ensuring that the application's main execution flow is not blocked.
261+
///
262+
/// This processor supports the following configurations:
263+
/// - **Queue size**: Maximum number of spans that can be buffered.
264+
/// - **Batch size**: Maximum number of spans to include in a single export.
265+
/// - **Scheduled delay**: Frequency at which the batch is exported.
266+
///
267+
/// When using this processor with the OTLP Exporter, the following exporter
268+
/// features are supported:
269+
/// - `grpc-tonic`: Requires `TracerProvider` to be created within a tokio runtime.
270+
/// - `reqwest-blocking-client`: Works with a regular `main` or `tokio::main`.
271+
///
272+
/// In other words, other clients like `reqwest` and `hyper` are not supported.
273+
///
274+
/// `BatchSpanProcessor` buffers spans in memory and exports them in batches. An
275+
/// export is triggered when `max_export_batch_size` is reached or every
276+
/// `scheduled_delay` milliseconds. Users can explicitly trigger an export using
277+
/// the `force_flush` method. Shutdown also triggers an export of all buffered
278+
/// spans and is recommended to be called before the application exits to ensure
279+
/// all buffered spans are exported.
280+
///
281+
/// **Warning**: When using tokio's current-thread runtime, `shutdown()`, which
282+
/// is a blocking call ,should not be called from your main thread. This can
283+
/// cause deadlock. Instead, call `shutdown()` from a separate thread or use
284+
/// tokio's `spawn_blocking`.
285+
///
286+
/// [`shutdown()`]: crate::trace::TracerProvider::shutdown
287+
/// [`force_flush()`]: crate::trace::TracerProvider::force_flush
257288
#[derive(Debug)]
258289
pub struct BatchSpanProcessor {
259290
span_sender: SyncSender<SpanData>, // Data channel to store spans

0 commit comments

Comments
 (0)