Skip to content

Commit c5631d7

Browse files
authored
chore: slightly improve error message on version mismatch (#211)
## Motivation Users keep sending issues about unimplemented traits when they have wrong versions, usually after `opentelemetry` is released and before `tracing-opentelemetry` is. ## Solution Reorder our bounds so that errors we control are shown first and add `on_unimplemented` message and note. The errors are still very long, but now the first one should be ours (not just "type does not implement `opentelemetry::Tracer`") and we can provide more information there. It's somewhat probable some people will see the long errors and not read it at all, but this has the potential to help at least some users.
1 parent cf35cf1 commit c5631d7

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ tracing-core = "0.1.28"
3030
tracing-subscriber = { version = "0.3.0", default-features = false, features = ["registry", "std"] }
3131
tracing-log = { version = "0.2.0", default-features = false, optional = true }
3232
once_cell = "1.13.0"
33+
rustversion = "1.0.9"
3334
smallvec = { version = "1.0", optional = true }
3435

3536
# Fix minimal-versions

src/tracer.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ use opentelemetry_sdk::trace::{IdGenerator, Tracer as SdkTracer};
3434
/// [`OpenTelemetrySpanExt::set_parent`]: crate::OpenTelemetrySpanExt::set_parent
3535
/// [`OpenTelemetrySpanExt::context`]: crate::OpenTelemetrySpanExt::context
3636
/// [`Context`]: opentelemetry::Context
37+
#[rustversion::attr(
38+
since(1.78),
39+
diagnostic::on_unimplemented(
40+
note = "Make sure you're using correct `opentelemetry` versions compatible with this \
41+
`tracing-opentelemetry`. The `opentelemetry` versions are usually one version lower \
42+
than `tracing-opentelemetry`."
43+
)
44+
)]
3745
pub trait PreSampledTracer {
3846
/// Produce an otel context containing an active and pre-sampled span for
3947
/// the given span builder data.

0 commit comments

Comments
 (0)