Skip to content

Commit afcbe28

Browse files
committed
fix: Error cleanups continued
1 parent 702c61d commit afcbe28

File tree

7 files changed

+14
-115
lines changed

7 files changed

+14
-115
lines changed

opentelemetry-otlp/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
`Error` which contained many variants unrelated to building an exporter, the
1818
new one returns specific variants applicable to building an exporter. Some
1919
variants might be applicable only on select features.
20+
Also, now unused `Error` enum is removed.
2021
- **Breaking** `ExportConfig`'s `timeout` field is now optional(`Option<Duration>`)
2122
- **Breaking** Export configuration done via code is final. ENV variables cannot be used to override the code config.
2223
Do not use code based config, if there is desire to control the settings via ENV variables.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl OtlpHttpClient {
287287
fn build_trace_export_body(
288288
&self,
289289
spans: Vec<SpanData>,
290-
) -> opentelemetry_sdk::trace::TraceResult<(Vec<u8>, &'static str)> {
290+
) -> Result<(Vec<u8>, &'static str), String> {
291291
use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest;
292292
let resource_spans = group_spans_by_resource_and_scope(spans, &self.resource);
293293

@@ -296,7 +296,7 @@ impl OtlpHttpClient {
296296
#[cfg(feature = "http-json")]
297297
Protocol::HttpJson => match serde_json::to_string_pretty(&req) {
298298
Ok(json) => Ok((json.into_bytes(), "application/json")),
299-
Err(e) => Err(opentelemetry_sdk::trace::TraceError::from(e.to_string())),
299+
Err(e) => Err(e.to_string()),
300300
},
301301
_ => Ok((req.encode_to_vec(), "application/x-protobuf")),
302302
}

opentelemetry-otlp/src/lib.rs

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,6 @@ pub use crate::exporter::{
308308
OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT,
309309
};
310310

311-
use opentelemetry_sdk::ExportError;
312-
313311
/// Type to indicate the builder does not have a client set.
314312
#[derive(Debug, Default, Clone)]
315313
pub struct NoExporterBuilderSet;
@@ -337,104 +335,6 @@ pub use crate::exporter::tonic::{TonicConfig, TonicExporterBuilder};
337335
#[cfg(feature = "serialize")]
338336
use serde::{Deserialize, Serialize};
339337

340-
/// Wrap type for errors from this crate.
341-
#[derive(thiserror::Error, Debug)]
342-
pub enum Error {
343-
/// Wrap error from [`tonic::transport::Error`]
344-
#[cfg(feature = "grpc-tonic")]
345-
#[error("transport error {0}")]
346-
Transport(#[from] tonic::transport::Error),
347-
348-
/// Wrap the [`tonic::codegen::http::uri::InvalidUri`] error
349-
#[cfg(any(feature = "grpc-tonic", feature = "http-proto", feature = "http-json"))]
350-
#[error("invalid URI {0}")]
351-
InvalidUri(#[from] http::uri::InvalidUri),
352-
353-
/// Wrap type for [`tonic::Status`]
354-
#[cfg(feature = "grpc-tonic")]
355-
#[error("the grpc server returns error ({code}): {message}")]
356-
Status {
357-
/// grpc status code
358-
code: tonic::Code,
359-
/// error message
360-
message: String,
361-
},
362-
363-
/// Http requests failed because no http client is provided.
364-
#[cfg(any(feature = "http-proto", feature = "http-json"))]
365-
#[error(
366-
"no http client, you must select one from features or provide your own implementation"
367-
)]
368-
NoHttpClient,
369-
370-
/// Http requests failed.
371-
#[cfg(any(feature = "http-proto", feature = "http-json"))]
372-
#[error("http request failed with {0}")]
373-
RequestFailed(#[from] opentelemetry_http::HttpError),
374-
375-
/// The provided value is invalid in HTTP headers.
376-
#[cfg(any(feature = "grpc-tonic", feature = "http-proto", feature = "http-json"))]
377-
#[error("http header value error {0}")]
378-
InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
379-
380-
/// The provided name is invalid in HTTP headers.
381-
#[cfg(any(feature = "grpc-tonic", feature = "http-proto", feature = "http-json"))]
382-
#[error("http header name error {0}")]
383-
InvalidHeaderName(#[from] http::header::InvalidHeaderName),
384-
385-
/// Prost encode failed
386-
#[cfg(any(
387-
feature = "http-proto",
388-
all(feature = "http-json", not(feature = "trace"))
389-
))]
390-
#[error("prost encoding error {0}")]
391-
EncodeError(#[from] prost::EncodeError),
392-
393-
/// The lock in exporters has been poisoned.
394-
#[cfg(feature = "metrics")]
395-
#[error("the lock of the {0} has been poisoned")]
396-
PoisonedLock(&'static str),
397-
398-
/// Unsupported compression algorithm.
399-
#[error("unsupported compression algorithm '{0}'")]
400-
UnsupportedCompressionAlgorithm(String),
401-
402-
/// Feature required to use the specified compression algorithm.
403-
#[cfg(any(not(feature = "gzip-tonic"), not(feature = "zstd-tonic")))]
404-
#[error("feature '{0}' is required to use the compression algorithm '{1}'")]
405-
FeatureRequiredForCompressionAlgorithm(&'static str, Compression),
406-
}
407-
408-
#[cfg(feature = "grpc-tonic")]
409-
impl From<tonic::Status> for Error {
410-
fn from(status: tonic::Status) -> Error {
411-
Error::Status {
412-
code: status.code(),
413-
message: {
414-
if !status.message().is_empty() {
415-
let mut result = ", detailed error message: ".to_string() + status.message();
416-
if status.code() == tonic::Code::Unknown {
417-
let source = (&status as &dyn std::error::Error)
418-
.source()
419-
.map(|e| format!("{:?}", e));
420-
result.push(' ');
421-
result.push_str(source.unwrap_or_default().as_ref());
422-
}
423-
result
424-
} else {
425-
String::new()
426-
}
427-
},
428-
}
429-
}
430-
}
431-
432-
impl ExportError for Error {
433-
fn exporter_name(&self) -> &'static str {
434-
"otlp"
435-
}
436-
}
437-
438338
/// The communication protocol to use when exporting data.
439339
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
440340
#[derive(Clone, Copy, Debug, Eq, PartialEq)]

opentelemetry-sdk/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@
7575
- **Breaking** for custom `LogProcessor` authors: Changed `set_resource`
7676
to require mutable ref.
7777
`fn set_resource(&mut self, _resource: &Resource) {}`
78-
- **Breaking** Removed deprecated functions and methods related to `trace::Config`
78+
- **Breaking**: InMemoryExporter's return type change.
79+
- `TraceResult<Vec<SpanData>>` to `Result<Vec<SpanData>, String>`
80+
- `MetricResult<Vec<ResourceMetrics>>` to `Result<Vec<ResourceMetrics>, String>`
81+
- `LogResult<Vec<LogDataWithResource>>` to `Result<Vec<LogDataWithResource>, String>`
7982

8083
## 0.28.0
8184

opentelemetry-sdk/src/logs/in_memory_exporter.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ use std::borrow::Cow;
77
use std::sync::atomic::AtomicBool;
88
use std::sync::{Arc, Mutex};
99

10-
type LogResult<T> = Result<T, OTelSdkError>;
11-
1210
/// An in-memory logs exporter that stores logs data in memory..
1311
///
1412
/// This exporter is useful for testing and debugging purposes.
@@ -157,13 +155,13 @@ impl InMemoryLogExporter {
157155
/// let emitted_logs = exporter.get_emitted_logs().unwrap();
158156
/// ```
159157
///
160-
pub fn get_emitted_logs(&self) -> LogResult<Vec<LogDataWithResource>> {
158+
pub fn get_emitted_logs(&self) -> Result<Vec<LogDataWithResource>, String> {
161159
let logs_guard = self
162160
.logs
163161
.lock()
164-
.map_err(|e| OTelSdkError::InternalFailure(format!("Failed to lock logs: {}", e)))?;
162+
.map_err(|e| e.to_string())?;
165163
let resource_guard = self.resource.lock().map_err(|e| {
166-
OTelSdkError::InternalFailure(format!("Failed to lock resource: {}", e))
164+
e.to_string()
167165
})?;
168166
let logs: Vec<LogDataWithResource> = logs_guard
169167
.iter()

opentelemetry-sdk/src/metrics/in_memory_exporter.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use crate::error::{OTelSdkError, OTelSdkResult};
22
use crate::metrics::data::{self, Gauge, Sum};
33
use crate::metrics::data::{Histogram, Metric, ResourceMetrics, ScopeMetrics};
44
use crate::metrics::exporter::PushMetricExporter;
5-
use crate::metrics::MetricError;
6-
use crate::metrics::MetricResult;
75
use crate::metrics::Temporality;
86
use std::collections::VecDeque;
97
use std::fmt;
@@ -143,11 +141,11 @@ impl InMemoryMetricExporter {
143141
/// let exporter = InMemoryMetricExporter::default();
144142
/// let finished_metrics = exporter.get_finished_metrics().unwrap();
145143
/// ```
146-
pub fn get_finished_metrics(&self) -> MetricResult<Vec<ResourceMetrics>> {
144+
pub fn get_finished_metrics(&self) -> Result<Vec<ResourceMetrics>, String> {
147145
self.metrics
148146
.lock()
149147
.map(|metrics_guard| metrics_guard.iter().map(Self::clone_metrics).collect())
150-
.map_err(MetricError::from)
148+
.map_err(|e| e.to_string())
151149
}
152150

153151
/// Clears the internal storage of finished metrics.

opentelemetry-sdk/src/trace/in_memory_exporter.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::error::{OTelSdkError, OTelSdkResult};
22
use crate::resource::Resource;
3-
use crate::trace::error::{TraceError, TraceResult};
43
use crate::trace::{SpanData, SpanExporter};
54
use std::sync::{Arc, Mutex};
65

@@ -104,11 +103,11 @@ impl InMemorySpanExporter {
104103
/// let exporter = InMemorySpanExporter::default();
105104
/// let finished_spans = exporter.get_finished_spans().unwrap();
106105
/// ```
107-
pub fn get_finished_spans(&self) -> TraceResult<Vec<SpanData>> {
106+
pub fn get_finished_spans(&self) -> Result<Vec<SpanData>, String> {
108107
self.spans
109108
.lock()
110109
.map(|spans_guard| spans_guard.iter().cloned().collect())
111-
.map_err(TraceError::from)
110+
.map_err(|e| e.to_string())
112111
}
113112

114113
/// Clears the internal storage of finished spans.

0 commit comments

Comments
 (0)