opentelemetry-rust icon indicating copy to clipboard operation
opentelemetry-rust copied to clipboard

PreSampledTrace Failure

Open hdost opened this issue 1 year ago • 8 comments

Ran into an interesting edge case when trying to put together a sample for #1337 It seems like they're using OpenTelemetryOTLP exporting. However that's not the main topic here. We have a weird interaction that seems to be happening at it relates to a special trait that's being run. I'm not 100 sure it requires an API change, but it could.

opentelemetry-rust/examples/tracing-axum on  main [$!?] is 📦 v0.1.0 via 🦀 v1.73.0
at 16:25:51 ➜  cargo build
    Blocking waiting for file lock on build directory
   Compiling tracing-axum v0.1.0 (/home/h.dost/projects/github.com/hdost/opentelemetry-rust/examples/tracing-axum)
error[E0277]: the trait bound `opentelemetry_sdk::trace::Tracer: opentelemetry_api::trace::tracer::Tracer` is not satisfied
   --> examples/tracing-axum/src/main.rs:20:64
    |
20  |     let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
    |                                                    ----------- ^^^^^^ the trait `opentelemetry_api::trace::tracer::Tracer` is not implemented for `opentelemetry_sdk::trace::Tracer`
    |                                                    |
    |                                                    required by a bound introduced by this call
    |
    = help: the following other types implement trait `opentelemetry_api::trace::tracer::Tracer`:
              opentelemetry_api::global::trace::BoxedTracer
              opentelemetry_api::trace::noop::NoopTracer
              opentelemetry_sdk::trace::tracer::Tracer
note: required by a bound in `OpenTelemetryLayer::<S, T>::with_tracer`
   --> /home/h.dost/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-opentelemetry-0.21.0/src/layer.rs:469:17
    |
467 |     pub fn with_tracer<Tracer>(self, tracer: Tracer) -> OpenTelemetryLayer<S,...
    |            ----------- required by a bound in this associated function
468 |     where
469 |         Tracer: otel::Tracer + PreSampledTracer + 'static,
    |                 ^^^^^^^^^^^^ required by this bound in `OpenTelemetryLayer::<S, T>::with_tracer`

error[E0277]: the trait bound `opentelemetry_sdk::trace::Tracer: PreSampledTracer` is not satisfied
   --> examples/tracing-axum/src/main.rs:20:64
    |
20  |     let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
    |                                                    ----------- ^^^^^^ the trait `PreSampledTracer` is not implemented for `opentelemetry_sdk::trace::Tracer`
    |                                                    |
    |                                                    required by a bound introduced by this call
    |
    = help: the following other types implement trait `PreSampledTracer`:
              opentelemetry_api::trace::noop::NoopTracer
              opentelemetry_sdk::trace::tracer::Tracer
note: required by a bound in `OpenTelemetryLayer::<S, T>::with_tracer`
   --> /home/h.dost/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-opentelemetry-0.21.0/src/layer.rs:469:32
    |
467 |     pub fn with_tracer<Tracer>(self, tracer: Tracer) -> OpenTelemetryLayer<S,...
    |            ----------- required by a bound in this associated function
468 |     where
469 |         Tracer: otel::Tracer + PreSampledTracer + 'static,
    |                                ^^^^^^^^^^^^^^^^ required by this bound in `OpenTelemetryLayer::<S, T>::with_tracer`

The code is included here https://github.com/open-telemetry/opentelemetry-rust/pull/1339

Not sure if there's any API changed required here, instead it might actually require filing something on the tracing-opentelemetry crate. This could however require some sort of API change.

@jtescher is this something around a generic implementation?

hdost avatar Nov 02 '23 15:11 hdost

Are you using the latest version of the sdk?

jtescher avatar Nov 02 '23 15:11 jtescher

Could be version mismatch. You should use 0.20 of opentelemetry.

Note that since tracing-opentelemetry is not in this repo. It usually depends on last release version instead of the current main version.

TommyCpp avatar Nov 02 '23 15:11 TommyCpp

So as mentioned I have a PR with an example. The #1339 does work, but I had to use versioned_tracer() which mean s that people aren't allowed to use tracer() due to the current type constraints.

hdost avatar Nov 02 '23 16:11 hdost

@hdost which constraints? they should both be referencing the same type https://docs.rs/opentelemetry/0.21.0/opentelemetry/trace/trait.TracerProvider.html

jtescher avatar Nov 07 '23 22:11 jtescher

The tooling requires the PreSampledTracer trait to be implemented, but the implementation is only done for NoopTracer and for the SdkTracer (which with our recent rename will also fail). I believe we may need to have tracing-opentelemetry implementation be a blanket for any Tracer and that should work.

hdost avatar Nov 10 '23 07:11 hdost

Could be version mismatch. You should use 0.20 of opentelemetry.

Sorry I missed this comment.

hdost avatar Nov 29 '23 09:11 hdost

@hdost What ended up being the solution for this? I'm encountering the same issue.

undecidedapollo avatar Mar 18 '24 14:03 undecidedapollo

@hdost What ended up being the solution for this? I'm encountering the same issue.

I had mismatched versions.

https://github.com/open-telemetry/opentelemetry-rust/issues/1340#issuecomment-1831546838

hdost avatar Mar 18 '24 14:03 hdost