Skip to content

Commit 79be94c

Browse files
authored
chore: remove thiserror and unused dependencies (#238)
## Motivation Was aiming to reduce `syn` usage in my dependency tree, and noticed a fairly unnecessary use of `thiserror` here. Also noticed a handful of unused deps, thanks to `cargo-shear`. ## Solution Removal of the unused deps, and replacing `thiserror` with a manual implementation.
1 parent ccaf19e commit 79be94c

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,12 @@ tracing-subscriber = { version = "0.3.0", default-features = false, features = [
3434
"std",
3535
] }
3636
tracing-log = { version = "0.2.0", default-features = false, optional = true }
37-
rustversion = "1.0.9"
3837
smallvec = { version = "1.0", optional = true }
39-
thiserror = { version = "2", default-features = false }
4038

4139
# Fix minimal-versions
4240
lazy_static = { version = "1.0.2", optional = true }
4341

4442
[dev-dependencies]
45-
async-trait = "0.1.56"
4643
criterion = { version = "0.5.1", default-features = false, features = [
4744
"html_reports",
4845
] }
@@ -61,9 +58,7 @@ opentelemetry-otlp = { version = "0.31.0", features = [
6158
opentelemetry-semantic-conventions = { version = "0.31.0", features = [
6259
"semconv_experimental",
6360
] }
64-
futures-util = { version = "0.3.17", default-features = false }
6561
tokio = { version = "1", features = ["full"] }
66-
tokio-stream = "0.1"
6762
tracing = { version = "0.1.35", default-features = false, features = [
6863
"std",
6964
"attributes",

src/span_ext.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use opentelemetry::{
55
trace::{SpanContext, Status, TraceContextExt},
66
Context, Key, KeyValue, Value,
77
};
8-
use std::{borrow::Cow, time::SystemTime};
9-
use thiserror::Error;
8+
use std::{borrow::Cow, fmt, time::SystemTime};
109

1110
/// Utility functions to allow tracing [`Span`]s to accept and return
1211
/// [OpenTelemetry] [`Context`]s.
@@ -227,28 +226,43 @@ pub trait OpenTelemetrySpanExt {
227226
}
228227

229228
/// An error returned if [`OpenTelemetrySpanExt::set_parent`] could not set the parent.
230-
#[derive(Error, Debug)]
229+
#[derive(Debug)]
231230
pub enum SetParentError {
232231
/// The layer could not be found and therefore the action could not be carried out. This can
233232
/// happen with some advanced layers that do not handle downcasting well, for example
234233
/// [`tracing_subscriber::reload::Layer`].
235-
#[error("OpenTelemetry layer not found")]
236234
LayerNotFound,
237235

238236
/// The span has been already started.
239237
///
240238
/// Someone already called a context-starting method such as [`OpenTelemetrySpanExt::context`]
241239
/// or the span has been entered and automatic context starting was not configured out.
242-
#[error("Span has already been started, cannot set parent")]
243240
AlreadyStarted,
244241

245242
/// The span is filtered out by tracing filters.
246243
///
247244
/// If the filtered out span had children, they will not be connected to the parent span either.
248-
#[error("Span disabled")]
249245
SpanDisabled,
250246
}
251247

248+
impl fmt::Display for SetParentError {
249+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
250+
match self {
251+
SetParentError::LayerNotFound => {
252+
write!(f, "OpenTelemetry layer not found")
253+
}
254+
SetParentError::AlreadyStarted => {
255+
write!(f, "Span has already been started, cannot set parent")
256+
}
257+
SetParentError::SpanDisabled => {
258+
write!(f, "Span disabled")
259+
}
260+
}
261+
}
262+
}
263+
264+
impl std::error::Error for SetParentError {}
265+
252266
impl OpenTelemetrySpanExt for tracing::Span {
253267
fn set_parent(&self, cx: Context) -> Result<(), SetParentError> {
254268
let mut cx = Some(cx);

0 commit comments

Comments
 (0)