-
Hi there, use opentelemetry::trace::{TracerProvider as _};
use opentelemetry::KeyValue;
use opentelemetry_sdk::trace::{TracerProvider};
use opentelemetry_stdout as stdout;
use tracing::{error, span};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::{Registry};
fn main() {
// Create a new OpenTelemetry trace pipeline that prints to stdout
let provider = TracerProvider::builder()
.with_simple_exporter(stdout::SpanExporter::default())
.build();
let tracer = provider
.tracer_builder("my_library")
.with_version(env!("CARGO_PKG_VERSION"))
.with_schema_url("https://opentelemetry.io/schema/1.0.0")
.with_attributes(vec![KeyValue::new("key", "value")])
.build();
// Create a tracing layer with the configured tracer
let telemetry = tracing_opentelemetry::OpenTelemetryLayer::new(tracer);
// Use the tracing subscriber `Registry`, or any other subscriber
// that impls `LookupSpan`
let subscriber = Registry::default().with(telemetry);
// Trace executed code
tracing::subscriber::with_default(subscriber, || {
// Spans will be sent to the configured OpenTelemetry exporter
let root = span!(tracing::Level::TRACE, "app_start", work_units = 2);
let _enter = root.enter();
error!("This event will be logged in the root span.");
});
} with these dependencies versions: [dependencies]
# Telemetry
opentelemetry = { version = "0.23", features = ["trace", "metrics"] }
opentelemetry_sdk = { version = "0.23", features = ["trace", "metrics"] }
opentelemetry-stdout = { version = "0.4", features = ["trace", "metrics"] }
tracing = "0.1"
tracing-opentelemetry = { version = "0.23", features = ["metrics"] }
tracing-subscriber = "0.3" Causes this error: error[E0277]: the trait bound `opentelemetry_sdk::trace::Tracer: opentelemetry::trace::tracer::Tracer` is not satisfied
--> Source/email_templated/src/main.rs:21:64
|
21 | let telemetry = 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/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-opentelemetry-0.23.0/src/layer.rs:581:17
|
579 | pub fn with_tracer<Tracer>(self, tracer: Tracer) -> OpenTelemetryLayer<S, Tracer>
| ----------- required by a bound in this associated function
580 | where
581 | 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
--> Source/email_templated/src/main.rs:21:64
|
21 | 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::trace::noop::NoopTracer
opentelemetry_sdk::trace::tracer::Tracer
note: required by a bound in `OpenTelemetryLayer::<S, T>::with_tracer`
--> /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-opentelemetry-0.23.0/src/layer.rs:581:32
|
579 | pub fn with_tracer<Tracer>(self, tracer: Tracer) -> OpenTelemetryLayer<S, Tracer>
| ----------- required by a bound in this associated function
580 | where
581 | Tracer: otel::Tracer + PreSampledTracer + 'static,
| ^^^^^^^^^^^^^^^^ required by this bound in `OpenTelemetryLayer::<S, T>::with_tracer`
For more information about this error, try `rustc --explain E0277`.
warning: `email_templated` (bin "email_templated") generated 2 warnings
error: could not compile `email_templated` (bin "email_templated") due to 2 previous errors; 2 warnings emitted
> cargo run
Compiling email_templated v0.1.0 (/home/me/repo/warpfactor/workers/Source/email_templated)
error[E0283]: type annotations needed for `OpenTelemetryLayer<Registry, T>`
--> Source/email_templated/src/main.rs:21:9
|
21 | let telemetry = tracing_opentelemetry::OpenTelemetryLayer::new(tracer.into());
| ^^^^^^^^^ ---------------------------------------------- ------------- type must be known at this point
| |
| required by a bound introduced by this call
|
= note: cannot satisfy `_: opentelemetry::trace::tracer::Tracer`
= help: the following 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>::new`
--> /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-opentelemetry-0.23.0/src/layer.rs:506:8
|
506 | T: otel::Tracer + PreSampledTracer + 'static,
| ^^^^^^^^^^^^ required by this bound in `OpenTelemetryLayer::<S, T>::new`
...
535 | pub fn new(tracer: T) -> Self {
| --- required by a bound in this associated function
help: consider giving `telemetry` an explicit type, where the type for type parameter `T` is specified
|
21 | let telemetry: OpenTelemetryLayer<Registry, T> = tracing_opentelemetry::OpenTelemetryLayer::new(tracer.into());
| +++++++++++++++++++++++++++++++++
For more information about this error, try `rustc --explain E0283`.
error: could not compile `email_templated` (bin "email_templated") due to 1 previous error This error does not happen when using open telemetry v0.22 of the tracing-opentelemtry crate |
Beta Was this translation helpful? Give feedback.
Answered by
lalitb
May 18, 2024
Replies: 1 comment 1 reply
-
Refer - open-telemetry/opentelemetry-rust#1779 (comment) if that answers the question. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
lmtr0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refer - open-telemetry/opentelemetry-rust#1779 (comment) if that answers the question.