Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions opentelemetry-otlp/src/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
data::ResourceMetrics, exporter::PushMetricExporter, Temporality,
};
use std::fmt::{Debug, Formatter};
use std::time::Duration;

/// Target to which the exporter is going to send metrics, defaults to https://localhost:4317/v1/metrics.
/// Learn about the relationship between this constant and default/spans/logs at
Expand Down Expand Up @@ -163,6 +164,10 @@
}

fn shutdown(&self) -> OTelSdkResult {
self.shutdown_with_timeout(Duration::from_secs(5))
}

Check warning on line 168 in opentelemetry-otlp/src/metric.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/metric.rs#L167-L168

Added lines #L167 - L168 were not covered by tests

fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {

Check warning on line 170 in opentelemetry-otlp/src/metric.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/metric.rs#L170

Added line #L170 was not covered by tests
match &self.client {
#[cfg(feature = "grpc-tonic")]
SupportedTransportClient::Tonic(client) => client.shutdown(),
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Released 2025-Mar-21

Custom exporters will need to internally synchronize any mutable state, if applicable.

- **Breaking** The `shutdown_with_timeout` method is added to MetricExporter trait. This is breaking change for custom `MetricExporter` authors.
- Bug Fix: `BatchLogProcessor` now correctly calls `shutdown` on the exporter
when its `shutdown` is invoked.

Expand Down
9 changes: 8 additions & 1 deletion opentelemetry-sdk/src/metrics/exporter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Interfaces for exporting metrics

use crate::error::OTelSdkResult;
use std::time::Duration;

use crate::metrics::data::ResourceMetrics;

Expand All @@ -26,7 +28,12 @@
///
/// After Shutdown is called, calls to Export will perform no operation and
/// instead will return an error indicating the shutdown state.
fn shutdown(&self) -> OTelSdkResult;
fn shutdown_with_timeout(&self, timeout: Duration) -> OTelSdkResult;

/// Shutdown with the default timeout of 5 seconds.
fn shutdown(&self) -> OTelSdkResult {
self.shutdown_with_timeout(Duration::from_secs(5))
}

Check warning on line 36 in opentelemetry-sdk/src/metrics/exporter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/exporter.rs#L34-L36

Added lines #L34 - L36 were not covered by tests

/// Access the [Temporality] of the MetricExporter.
fn temporality(&self) -> Temporality;
Expand Down
5 changes: 5 additions & 0 deletions opentelemetry-sdk/src/metrics/in_memory_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use std::collections::VecDeque;
use std::fmt;
use std::sync::{Arc, Mutex};
use std::time::Duration;

use super::data::{AggregatedMetrics, Metric, ScopeMetrics};

Expand Down Expand Up @@ -253,6 +254,10 @@
Ok(())
}

fn shutdown_with_timeout(&self, _timeout: Duration) -> OTelSdkResult {
Ok(())
}

Check warning on line 259 in opentelemetry-sdk/src/metrics/in_memory_exporter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/in_memory_exporter.rs#L257-L259

Added lines #L257 - L259 were not covered by tests

fn temporality(&self) -> Temporality {
self.temporality
}
Expand Down
8 changes: 8 additions & 0 deletions opentelemetry-sdk/src/metrics/periodic_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@
Ok(())
}

fn shutdown_with_timeout(&self, _timeout: Duration) -> OTelSdkResult {
Ok(())
}

Check warning on line 571 in opentelemetry-sdk/src/metrics/periodic_reader.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/periodic_reader.rs#L569-L571

Added lines #L569 - L571 were not covered by tests

fn temporality(&self) -> Temporality {
Temporality::Cumulative
}
Expand All @@ -586,6 +590,10 @@
}

fn shutdown(&self) -> OTelSdkResult {
self.shutdown_with_timeout(Duration::from_secs(5))
}

fn shutdown_with_timeout(&self, _timeout: Duration) -> OTelSdkResult {
self.is_shutdown.store(true, Ordering::Relaxed);
Ok(())
}
Expand Down
5 changes: 5 additions & 0 deletions opentelemetry-stdout/src/metrics/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
};
use std::fmt::Debug;
use std::sync::atomic;
use std::time::Duration;

/// An OpenTelemetry exporter that writes to stdout on export.
pub struct MetricExporter {
Expand Down Expand Up @@ -65,6 +66,10 @@
}

fn shutdown(&self) -> OTelSdkResult {
self.shutdown_with_timeout(Duration::from_secs(5))
}

Check warning on line 70 in opentelemetry-stdout/src/metrics/exporter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-stdout/src/metrics/exporter.rs#L69-L70

Added lines #L69 - L70 were not covered by tests

fn shutdown_with_timeout(&self, _timeout: Duration) -> OTelSdkResult {

Check warning on line 72 in opentelemetry-stdout/src/metrics/exporter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-stdout/src/metrics/exporter.rs#L72

Added line #L72 was not covered by tests
self.is_shutdown.store(true, atomic::Ordering::SeqCst);
Ok(())
}
Expand Down