Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trait bound in OpenTelemetryLayer::<S, T>::with_tracer with opentelemetry v0.22.0 #110

Closed
hkford opened this issue Mar 1, 2024 · 2 comments

Comments

@hkford
Copy link

hkford commented Mar 1, 2024

Bug Report

Version

tracing = { version = "0.1.40", features = ["log","attributes"] }
tracing-subscriber = { version = "0.3.18", features = ["std", "env-filter","json"] }
opentelemetry = { version = "0.22.0" }
opentelemetry_sdk = { version = "0.22.0", features = ["rt-tokio"] }
opentelemetry-aws = "0.10.0"
opentelemetry-otlp = { version = "0.15.0", features = ["grpc-tonic", "tls"] }
tracing-opentelemetry = "0.22.0"

Platform

$ uname -a
Linux ip-172-31-86-254.ec2.internal 6.1.77-99.164.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 13 19:20:28 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Description

I tried this code with opentelemetry v0.21.0:

opentelemetry = { version = "0.21.0" }
opentelemetry_sdk = { version = "0.21.0", features = ["rt-tokio"] }
opentelemetry-aws = "0.9.0"
opentelemetry-otlp = { version = "0.14.0", features = ["grpc-tonic", "tls"] }
tracing-opentelemetry = "0.22.0"
use opentelemetry_sdk::trace::TracerProvider;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, fmt::format, EnvFilter};

pub fn init_observability() -> Result<(), Error> {
    let exporter = opentelemetry_otlp::new_exporter()
        .tonic()
        .build_span_exporter()?;
    // Create a new OpenTelemetry trace pipeline that prints to stdout
    let provider = TracerProvider::builder()
        .with_simple_exporter(exporter)
        .build();
    let tracer = provider.tracer("readme_example");
    let fmt_layer = fmt::layer().event_format(format().json());
    let filter_layer = EnvFilter::from_default_env();
    let telemetry_layer = tracing_opentelemetry::layer().with_tracer(tracer);

    let subscriber = tracing_subscriber::registry()
        .with(filter_layer)
        .with(fmt_layer)
        .with(telemetry_layer);
    tracing::subscriber::set_global_default(subscriber)?;
    Ok(())
}

When using opentelemetry v0.21.0, rustc raises no error.

However, if using opentelemetry v0.22.0 rustc raises the following error.

tracing = { version = "0.1.40", features = ["log","attributes"] }
tracing-subscriber = { version = "0.3.18", features = ["std", "env-filter","json"] }
opentelemetry = { version = "0.22.0" }
opentelemetry_sdk = { version = "0.22.0", features = ["rt-tokio"] }
opentelemetry-aws = "0.10.0"
opentelemetry-otlp = { version = "0.15.0", features = ["grpc-tonic", "tls"] }
tracing-opentelemetry = "0.22.0"
error[E0277]: the trait bound `opentelemetry_sdk::trace::Tracer: opentelemetry::trace::tracer::Tracer` is not satisfied
   --> src/observability.rs:28:70
    |
28  |     let telemetry_layer = tracing_opentelemetry::layer().with_tracer(tracer);
    |                                                          ----------- ^^^^^^ the trait `opentelemetry::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::trace::tracer::Tracer`:
              opentelemetry::global::trace::BoxedTracer
              opentelemetry::trace::noop::NoopTracer
              opentelemetry_sdk::trace::tracer::Tracer
note: required by a bound in `OpenTelemetryLayer::<S, T>::with_tracer`
   --> /home/ec2-user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-opentelemetry-0.22.0/src/layer.rs:541:17
    |
539 |     pub fn with_tracer<Tracer>(self, tracer: Tracer) -> OpenTelemetryLayer<S, Tracer>
    |            ----------- required by a bound in this associated function
540 |     where
541 |         Tracer: otel::Tracer + PreSampledTracer + 'static,
    |                 ^^^^^^^^^^^^ required by this bound in `OpenTelemetryLayer::<S, T>::with_tracer`


Screenshot 2024-03-01 at 19 32 42
@ymgyt
Copy link
Contributor

ymgyt commented Mar 1, 2024

#100 will fix this

@hkford
Copy link
Author

hkford commented Mar 6, 2024

Thank you. I checked tracing-opentelemetry v0.23.0 and succeeded to upgrade to opentelemetry v0.22.

@hkford hkford closed this as completed Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants