Skip to content

Commit 6a68b44

Browse files
committed
Make a common Error enum for export shutdown and flush operations
1 parent b017c7b commit 6a68b44

File tree

9 files changed

+22
-22
lines changed

9 files changed

+22
-22
lines changed

examples/metrics-basic/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use opentelemetry::{global, KeyValue};
2-
use opentelemetry_sdk::error::ShutdownError;
2+
use opentelemetry_sdk::error::OTelSdkError;
33
use opentelemetry_sdk::metrics::{PeriodicReader, SdkMeterProvider};
44
use opentelemetry_sdk::Resource;
55
use std::error::Error;

opentelemetry-otlp/src/exporter/http/metrics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use async_trait::async_trait;
44
use http::{header::CONTENT_TYPE, Method};
55
use opentelemetry::otel_debug;
6-
use opentelemetry_sdk::error::{ShutdownError, ShutdownResult};
6+
use opentelemetry_sdk::error::{OTelSdkError, ShutdownResult};
77
use opentelemetry_sdk::metrics::data::ResourceMetrics;
88
use opentelemetry_sdk::metrics::{MetricError, MetricResult};
99

@@ -47,7 +47,7 @@ impl MetricsClient for OtlpHttpClient {
4747
fn shutdown(&self) -> ShutdownResult {
4848
self.client
4949
.lock()
50-
.map_err(|e| ShutdownError::InternalFailure(format!("Failed to acquire lock: {}", e)))?
50+
.map_err(|e| OTelSdkError::InternalFailure(format!("Failed to acquire lock: {}", e)))?
5151
.take();
5252

5353
Ok(())

opentelemetry-otlp/src/exporter/tonic/metrics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use opentelemetry::otel_debug;
66
use opentelemetry_proto::tonic::collector::metrics::v1::{
77
metrics_service_client::MetricsServiceClient, ExportMetricsServiceRequest,
88
};
9-
use opentelemetry_sdk::error::{ShutdownError, ShutdownResult};
9+
use opentelemetry_sdk::error::{OTelSdkError, ShutdownResult};
1010
use opentelemetry_sdk::metrics::data::ResourceMetrics;
1111
use opentelemetry_sdk::metrics::{MetricError, MetricResult};
1212
use tonic::{codegen::CompressionEncoding, service::Interceptor, transport::Channel, Request};
@@ -93,7 +93,7 @@ impl MetricsClient for TonicMetricsClient {
9393
fn shutdown(&self) -> ShutdownResult {
9494
self.inner
9595
.lock()
96-
.map_err(|e| ShutdownError::InternalFailure(format!("Failed to acquire lock: {}", e)))?
96+
.map_err(|e| OTelSdkError::InternalFailure(format!("Failed to acquire lock: {}", e)))?
9797
.take();
9898

9999
Ok(())

opentelemetry-sdk/src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub trait ExportError: std::error::Error + Send + Sync + 'static {
1111
}
1212

1313
#[derive(Error, Debug)]
14-
/// Errors that can occur during shutdown.
15-
pub enum ShutdownError {
14+
/// Errors that can occur during SDK operations export(), force_flush() and shutdown().
15+
pub enum OTelSdkError {
1616
/// Shutdown has already been invoked.
1717
///
1818
/// While shutdown is idempotent and calling it multiple times has no
@@ -42,4 +42,4 @@ pub enum ShutdownError {
4242
}
4343

4444
/// A specialized `Result` type for Shutdown operations.
45-
pub type ShutdownResult = Result<(), ShutdownError>;
45+
pub type ShutdownResult = Result<(), OTelSdkError>;

opentelemetry-sdk/src/metrics/manual_reader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
use opentelemetry::otel_debug;
77

88
use crate::{
9-
error::{ShutdownError, ShutdownResult},
9+
error::{OTelSdkError, ShutdownResult},
1010
metrics::{MetricError, MetricResult, Temporality},
1111
};
1212

@@ -112,7 +112,7 @@ impl MetricReader for ManualReader {
112112
/// Closes any connections and frees any resources used by the reader.
113113
fn shutdown(&self) -> ShutdownResult {
114114
let mut inner = self.inner.lock().map_err(|e| {
115-
ShutdownError::InternalFailure(format!("Failed to acquire lock: {}", e))
115+
OTelSdkError::InternalFailure(format!("Failed to acquire lock: {}", e))
116116
})?;
117117

118118
// Any future call to collect will now return an error.

opentelemetry-sdk/src/metrics/meter_provider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl SdkMeterProviderInner {
141141
.swap(true, std::sync::atomic::Ordering::SeqCst)
142142
{
143143
// If the previous value was true, shutdown was already invoked.
144-
Err(crate::error::ShutdownError::AlreadyShutdown)
144+
Err(crate::error::OTelSdkError::AlreadyShutdown)
145145
} else {
146146
self.pipes.shutdown()
147147
}

opentelemetry-sdk/src/metrics/periodic_reader.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
use opentelemetry::{otel_debug, otel_error, otel_info, otel_warn};
1212

1313
use crate::{
14-
error::{ShutdownError, ShutdownResult},
14+
error::{OTelSdkError, ShutdownResult},
1515
metrics::{exporter::PushMetricExporter, reader::SdkProducer, MetricError, MetricResult},
1616
Resource,
1717
};
@@ -479,22 +479,22 @@ impl PeriodicReaderInner {
479479
let (response_tx, response_rx) = mpsc::channel();
480480
self.message_sender
481481
.send(Message::Shutdown(response_tx))
482-
.map_err(|e| ShutdownError::InternalFailure(e.to_string()))?;
482+
.map_err(|e| OTelSdkError::InternalFailure(e.to_string()))?;
483483

484484
// TODO: Make this timeout configurable.
485485
match response_rx.recv_timeout(Duration::from_secs(5)) {
486486
Ok(response) => {
487487
if response {
488488
Ok(())
489489
} else {
490-
Err(ShutdownError::InternalFailure("Failed to shutdown".into()))
490+
Err(OTelSdkError::InternalFailure("Failed to shutdown".into()))
491491
}
492492
}
493493
Err(mpsc::RecvTimeoutError::Timeout) => {
494-
Err(ShutdownError::Timeout(Duration::from_secs(5)))
494+
Err(OTelSdkError::Timeout(Duration::from_secs(5)))
495495
}
496496
Err(mpsc::RecvTimeoutError::Disconnected) => {
497-
Err(ShutdownError::InternalFailure("Failed to shutdown".into()))
497+
Err(OTelSdkError::InternalFailure("Failed to shutdown".into()))
498498
}
499499
}
500500
}
@@ -543,7 +543,7 @@ impl MetricReader for PeriodicReader {
543543
mod tests {
544544
use super::PeriodicReader;
545545
use crate::{
546-
error::{ShutdownError, ShutdownResult},
546+
error::{OTelSdkError, ShutdownResult},
547547
metrics::{
548548
data::ResourceMetrics, exporter::PushMetricExporter, reader::MetricReader,
549549
InMemoryMetricExporter, MetricError, MetricResult, SdkMeterProvider, Temporality,
@@ -675,12 +675,12 @@ mod tests {
675675
// calling shutdown again should return Err
676676
let result = meter_provider.shutdown();
677677
assert!(result.is_err());
678-
assert!(matches!(result, Err(ShutdownError::AlreadyShutdown)));
678+
assert!(matches!(result, Err(OTelSdkError::AlreadyShutdown)));
679679

680680
// calling shutdown again should return Err
681681
let result = meter_provider.shutdown();
682682
assert!(result.is_err());
683-
assert!(matches!(result, Err(ShutdownError::AlreadyShutdown)));
683+
assert!(matches!(result, Err(OTelSdkError::AlreadyShutdown)));
684684
}
685685

686686
#[test]

opentelemetry-sdk/src/metrics/pipeline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ impl Pipelines {
661661
if errs.is_empty() {
662662
Ok(())
663663
} else {
664-
Err(crate::error::ShutdownError::InternalFailure(format!(
664+
Err(crate::error::OTelSdkError::InternalFailure(format!(
665665
"{errs:?}"
666666
)))
667667
}

opentelemetry-sdk/src/testing/metrics/metric_reader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::{Arc, Mutex, Weak};
22

3-
use crate::error::{ShutdownError, ShutdownResult};
3+
use crate::error::{OTelSdkError, ShutdownResult};
44
use crate::metrics::{
55
data::ResourceMetrics, pipeline::Pipeline, reader::MetricReader, InstrumentKind,
66
};
@@ -48,7 +48,7 @@ impl MetricReader for TestMetricReader {
4848
let mut is_shutdown = self.is_shutdown.lock().unwrap();
4949
*is_shutdown = true;
5050
}
51-
result.map_err(|e| ShutdownError::InternalFailure(e.to_string()))
51+
result.map_err(|e| OTelSdkError::InternalFailure(e.to_string()))
5252
}
5353

5454
fn temporality(&self, _kind: InstrumentKind) -> Temporality {

0 commit comments

Comments
 (0)