From d4244a930ce2913db40dfc32fbce5fc70447d26b Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Tue, 16 Apr 2024 22:25:39 +0700 Subject: [PATCH] support zipkin b3 propagation --- Cargo.lock | 42 +++++++++++++++++++++++++++++++++++++++ crates/sdk/Cargo.toml | 1 + crates/sdk/src/tracing.rs | 8 +++++--- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index caf9c77..08c1bbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -962,6 +962,7 @@ dependencies = [ "opentelemetry-http", "opentelemetry-otlp", "opentelemetry-semantic-conventions", + "opentelemetry-zipkin", "opentelemetry_sdk", "prometheus", "reqwest", @@ -1157,6 +1158,27 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9ab5bd6c42fb9349dcf28af2ba9a0667f697f9bdcca045d39f2cec5543e2910" +[[package]] +name = "opentelemetry-zipkin" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6943c09b1b7c17b403ae842b00f23e6d5fc6f5ec06cccb3f39aca97094a899a" +dependencies = [ + "async-trait", + "futures-core", + "http", + "once_cell", + "opentelemetry", + "opentelemetry-http", + "opentelemetry-semantic-conventions", + "opentelemetry_sdk", + "reqwest", + "serde", + "serde_json", + "thiserror", + "typed-builder", +] + [[package]] name = "opentelemetry_sdk" version = "0.22.1" @@ -2171,6 +2193,26 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "typed-builder" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77739c880e00693faef3d65ea3aad725f196da38b22fdc7ea6ded6e1ce4d3add" +dependencies = [ + "typed-builder-macro", +] + +[[package]] +name = "typed-builder-macro" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f718dfaf347dcb5b983bfc87608144b0bad87970aebcbea5ce44d2a30c08e63" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.55", +] + [[package]] name = "unicase" version = "2.7.0" diff --git a/crates/sdk/Cargo.toml b/crates/sdk/Cargo.toml index 4e19f76..841ab7f 100644 --- a/crates/sdk/Cargo.toml +++ b/crates/sdk/Cargo.toml @@ -39,6 +39,7 @@ opentelemetry-http = "0.11.0" opentelemetry-otlp = { version = "0.15.0", features = ["reqwest-client"] } opentelemetry-semantic-conventions = "0.14.0" opentelemetry_sdk = { version = "0.22.1", features = ["rt-tokio"] } +opentelemetry-zipkin = "0.20.0" prometheus = "0.13.3" reqwest = "0.11.27" serde = { version = "1.0.197", features = ["derive"] } diff --git a/crates/sdk/src/tracing.rs b/crates/sdk/src/tracing.rs index 7134b6a..2198529 100644 --- a/crates/sdk/src/tracing.rs +++ b/crates/sdk/src/tracing.rs @@ -4,6 +4,7 @@ use std::time::Duration; use axum::body::{Body, BoxBody}; use http::{Request, Response}; +use opentelemetry::propagation::composite::TextMapCompositePropagator; use opentelemetry_otlp::WithExportConfig; use tracing::Span; use tracing_opentelemetry::OpenTelemetrySpanExt; @@ -13,9 +14,10 @@ pub fn init_tracing( service_name: Option<&str>, otlp_endpoint: Option<&str>, ) -> Result<(), Box> { - opentelemetry::global::set_text_map_propagator( - opentelemetry_sdk::propagation::TraceContextPropagator::new(), - ); + opentelemetry::global::set_text_map_propagator(TextMapCompositePropagator::new(vec![ + Box::new(opentelemetry_sdk::propagation::TraceContextPropagator::new()), + Box::new(opentelemetry_zipkin::Propagator::new()), + ])); let tracer = opentelemetry_otlp::new_pipeline() .tracing()