Skip to content

Commit 5f7f2d5

Browse files
authored
Remove export timeout configuration for PeriodicReader (#2598)
1 parent 15b5fa4 commit 5f7f2d5

File tree

2 files changed

+22
-46
lines changed

2 files changed

+22
-46
lines changed

opentelemetry-sdk/CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,13 @@ limit.
307307
`opentelemetry_sdk::trace::{InMemorySpanExporter, InMemorySpanExporterBuilder};`
308308
`opentelemetry_sdk::metrics::{InMemoryMetricExporter, InMemoryMetricExporterBuilder};`
309309

310-
- *Breaking*: The `BatchLogProcessor` no longer supports configuration of `max_export_timeout`
310+
- **Breaking**: The `BatchLogProcessor` no longer supports configuration of `max_export_timeout`
311311
or the `OTEL_BLRP_EXPORT_TIMEOUT` environment variable. Timeout handling is now the
312312
responsibility of the exporter.
313313
For example, in the OTLP Logs exporter, the export timeout can be configured using:
314314
- The environment variables `OTEL_EXPORTER_OTLP_TIMEOUT` or `OTEL_EXPORTER_OTLP_LOGS_TIMEOUT`.
315315
- The opentelemetry_otlp API, via `.with_tonic().with_timeout()` or `.with_http().with_timeout()`.
316+
316317
Before:
317318
```rust
318319
let processor = BatchLogProcessor::builder(exporter)
@@ -340,12 +341,13 @@ let processor = BatchLogProcessor::builder(exporter)
340341
.build();
341342
```
342343

343-
- *Breaking*: The `BatchSpanProcessor` no longer supports configuration of `max_export_timeout`
344+
- **Breaking**: The `BatchSpanProcessor` no longer supports configuration of `max_export_timeout`
344345
or the `OTEL_BLRP_EXPORT_TIMEOUT` environment variable. Timeout handling is now the
345346
responsibility of the exporter.
346347
For example, in the OTLP Span exporter, the export timeout can be configured using:
347348
- The environment variables `OTEL_EXPORTER_OTLP_TIMEOUT` or `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT`.
348349
- The opentelemetry_otlp API, via `.with_tonic().with_timeout()` or `.with_http().with_timeout()`.
350+
349351
Before:
350352
```rust
351353
let processor = BatchSpanProcessor::builder(exporter)
@@ -373,6 +375,14 @@ let processor = BatchSpanProcessor::builder(exporter)
373375
.build();
374376
```
375377

378+
- **Breaking**: The `PeriodicReader` no longer supports configuration of export timeout using
379+
`with_timeout` API method.
380+
Timeout handling is now the responsibility of the exporter.
381+
382+
For example, in the OTLP Metrics exporter, the export timeout can be configured using:
383+
- The environment variables `OTEL_EXPORTER_OTLP_TIMEOUT` or `OTEL_EXPORTER_OTLP_METRICS_TIMEOUT`.
384+
- The `opentelemetry_otlp` API, via `.with_tonic().with_timeout()` or `.with_http().with_timeout()`.
385+
376386
- **Breaking**
377387
- The public API changes in the Tracing:
378388
- Before:

opentelemetry-sdk/src/metrics/periodic_reader.rs

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@ use super::{
2020
data::ResourceMetrics, instrument::InstrumentKind, reader::MetricReader, Pipeline, Temporality,
2121
};
2222

23-
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30);
2423
const DEFAULT_INTERVAL: Duration = Duration::from_secs(60);
2524

2625
const METRIC_EXPORT_INTERVAL_NAME: &str = "OTEL_METRIC_EXPORT_INTERVAL";
27-
const METRIC_EXPORT_TIMEOUT_NAME: &str = "OTEL_METRIC_EXPORT_TIMEOUT";
2826

2927
/// Configuration options for [PeriodicReader].
3028
#[derive(Debug)]
3129
pub struct PeriodicReaderBuilder<E> {
3230
interval: Duration,
33-
timeout: Duration,
3431
exporter: E,
3532
}
3633

@@ -43,16 +40,8 @@ where
4340
.ok()
4441
.and_then(|v| v.parse().map(Duration::from_millis).ok())
4542
.unwrap_or(DEFAULT_INTERVAL);
46-
let timeout = env::var(METRIC_EXPORT_TIMEOUT_NAME)
47-
.ok()
48-
.and_then(|v| v.parse().map(Duration::from_millis).ok())
49-
.unwrap_or(DEFAULT_TIMEOUT);
5043

51-
PeriodicReaderBuilder {
52-
interval,
53-
timeout,
54-
exporter,
55-
}
44+
PeriodicReaderBuilder { interval, exporter }
5645
}
5746

5847
/// Configures the intervening time between exports for a [PeriodicReader].
@@ -69,25 +58,9 @@ where
6958
self
7059
}
7160

72-
/// Configures the timeout for an export to complete. PeriodicReader itself
73-
/// does not enforce timeout. Instead timeout is passed on to the exporter
74-
/// for each export attempt.
75-
///
76-
/// This option overrides any value set for the `OTEL_METRIC_EXPORT_TIMEOUT`
77-
/// environment variable.
78-
///
79-
/// If this option is not used or `timeout` is equal to zero, 30 seconds is used
80-
/// as the default.
81-
pub fn with_timeout(mut self, timeout: Duration) -> Self {
82-
if !timeout.is_zero() {
83-
self.timeout = timeout;
84-
}
85-
self
86-
}
87-
8861
/// Create a [PeriodicReader] with the given config.
8962
pub fn build(self) -> PeriodicReader {
90-
PeriodicReader::new(self.exporter, self.interval, self.timeout)
63+
PeriodicReader::new(self.exporter, self.interval)
9164
}
9265
}
9366

@@ -165,7 +138,7 @@ impl PeriodicReader {
165138
PeriodicReaderBuilder::new(exporter)
166139
}
167140

168-
fn new<E>(exporter: E, interval: Duration, timeout: Duration) -> Self
141+
fn new<E>(exporter: E, interval: Duration) -> Self
169142
where
170143
E: PushMetricExporter,
171144
{
@@ -189,7 +162,6 @@ impl PeriodicReader {
189162
otel_info!(
190163
name: "PeriodReaderThreadStarted",
191164
interval_in_millisecs = interval.as_millis(),
192-
timeout_in_millisecs = timeout.as_millis()
193165
);
194166
loop {
195167
otel_debug!(
@@ -200,8 +172,7 @@ impl PeriodicReader {
200172
otel_debug!(
201173
name: "PeriodReaderThreadExportingDueToFlush"
202174
);
203-
204-
let export_result = cloned_reader.collect_and_export(timeout);
175+
let export_result = cloned_reader.collect_and_export();
205176
otel_debug!(
206177
name: "PeriodReaderInvokedExport",
207178
export_result = format!("{:?}", export_result)
@@ -257,7 +228,7 @@ impl PeriodicReader {
257228
Ok(Message::Shutdown(response_sender)) => {
258229
// Perform final export and break out of loop and exit the thread
259230
otel_debug!(name: "PeriodReaderThreadExportingDueToShutdown");
260-
let export_result = cloned_reader.collect_and_export(timeout);
231+
let export_result = cloned_reader.collect_and_export();
261232
otel_debug!(
262233
name: "PeriodReaderInvokedExport",
263234
export_result = format!("{:?}", export_result)
@@ -305,7 +276,7 @@ impl PeriodicReader {
305276
name: "PeriodReaderThreadExportingDueToTimer"
306277
);
307278

308-
let export_result = cloned_reader.collect_and_export(timeout);
279+
let export_result = cloned_reader.collect_and_export();
309280
otel_debug!(
310281
name: "PeriodReaderInvokedExport",
311282
export_result = format!("{:?}", export_result)
@@ -357,8 +328,8 @@ impl PeriodicReader {
357328
reader
358329
}
359330

360-
fn collect_and_export(&self, timeout: Duration) -> OTelSdkResult {
361-
self.inner.collect_and_export(timeout)
331+
fn collect_and_export(&self) -> OTelSdkResult {
332+
self.inner.collect_and_export()
362333
}
363334
}
364335

@@ -402,23 +373,18 @@ impl PeriodicReaderInner {
402373
}
403374
}
404375

405-
fn collect_and_export(&self, timeout: Duration) -> OTelSdkResult {
376+
fn collect_and_export(&self) -> OTelSdkResult {
406377
// TODO: Reuse the internal vectors. Or refactor to avoid needing any
407378
// owned data structures to be passed to exporters.
408379
let mut rm = ResourceMetrics {
409380
resource: Resource::empty(),
410381
scope_metrics: Vec::new(),
411382
};
412383

413-
// Measure time taken for collect, and subtract it from the timeout.
414384
let current_time = Instant::now();
415385
let collect_result = self.collect(&mut rm);
416386
let time_taken_for_collect = current_time.elapsed();
417-
let _timeout = if time_taken_for_collect > timeout {
418-
Duration::from_secs(0)
419-
} else {
420-
timeout - time_taken_for_collect
421-
};
387+
422388
#[allow(clippy::question_mark)]
423389
if let Err(e) = collect_result {
424390
otel_warn!(

0 commit comments

Comments
 (0)