You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue is simple example to showcase broken traces when intermixing OTel Tracing API and Tokio-tracing API.
Cargo.toml
[package]
name = "otel-tracing-interop"version = "0.1.0"edition = "2021"# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
opentelemetry = "0.22.0"opentelemetry-stdout = { version = "0.3.0", features = ["trace"] }
opentelemetry_sdk = "0.22.1"serde_json = "1.0.116"tracing = "0.1.40"tracing-opentelemetry = "0.23.0"tracing-subscriber = "0.3.18"
main.rs
use opentelemetry::{
trace::{Span,Tracer,TracerProvideras _},KeyValue,};use opentelemetry_sdk::{
resource,
trace::{config,Config,TracerProvider},Resource,};use opentelemetry_stdout::SpanExporterBuilder;use tracing::span;use tracing_subscriber::{layer::SubscriberExt,Registry};fnmain(){println!("Hello, world!");let stdout_exporter = SpanExporterBuilder::default().with_encoder(|writer, data| {
serde_json::to_writer_pretty(writer,&data).unwrap();Ok(())}).build();let provider = TracerProvider::builder().with_config(Config::default().with_resource(Resource::new(vec![]))).with_simple_exporter(stdout_exporter).build();let tracer = provider.tracer("tracing-opentelemetry");let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);let subscriber = Registry::default().with(telemetry);
tracing::subscriber::with_default(subscriber, || {let tracer = provider.tracer("otel-tracing");// this is the root span created using tokio tracing apilet root = span!(tracing::Level::TRACE, "tokio-tracing-span-parent");let _enter = root.enter();// this is a child span created using tokio tracing api// this correctly parented to the root spanlet child = span!(tracing::Level::TRACE, "tokio-tracing-span-child");let _enter_child = child.enter();// this is another child, created using otel tracing api// but this is *NOT* parented to the above spans// demonstrating broken traces when mixing and matching tracing and opentelemetry apisletmut span = tracer.span_builder("otel-tracing-span").start(&tracer);
span.end();});}
The text was updated successfully, but these errors were encountered:
The problem here is that if the Span is active in the tracing context, tracing-opentelemetry willn't make it active in the thread_local otel context. So any span created thereafter using otel API will have no information of the span created and made active by tracing API. So in the current state, the Otel tracing API will need to read the active span from the tracing context (along with the otel context as done already) to figure out the parent. The issue is somewhat similar to logging as described here.
This issue is simple example to showcase broken traces when intermixing OTel Tracing API and Tokio-tracing API.
Cargo.toml
main.rs
The text was updated successfully, but these errors were encountered: