From 89a20cb136dfc8439525006ee92d0d1245fa0907 Mon Sep 17 00:00:00 2001 From: Harold Dost Date: Mon, 26 Feb 2024 15:03:07 +0100 Subject: [PATCH] Update opentelemetry-jaeger to use OTLP Jaeger has been compatibile with OTLP for over 2 years. We want to encourage usage of OTLP exporter. https://github.com/open-telemetry/opentelemetry-rust/issues/995 --- examples/poem/opentelemetry-jaeger/Cargo.toml | 8 +++----- examples/poem/opentelemetry-jaeger/README.md | 2 +- .../poem/opentelemetry-jaeger/src/client.rs | 17 +++++++++++------ .../poem/opentelemetry-jaeger/src/server1.rs | 17 +++++++++++------ .../poem/opentelemetry-jaeger/src/server2.rs | 19 ++++++++++++------- 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/examples/poem/opentelemetry-jaeger/Cargo.toml b/examples/poem/opentelemetry-jaeger/Cargo.toml index ddd7832515..b40ef52114 100644 --- a/examples/poem/opentelemetry-jaeger/Cargo.toml +++ b/examples/poem/opentelemetry-jaeger/Cargo.toml @@ -9,12 +9,10 @@ poem = { workspace = true, features = ["opentelemetry"] } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } tracing-subscriber.workspace = true opentelemetry = { version = "0.21.0", features = ["metrics"] } -opentelemetry_sdk = "0.21.0" +opentelemetry_sdk = { version = "0.21.0", features = ["rt-tokio"] } opentelemetry-http = { version = "0.10.0" } -opentelemetry-jaeger = { version = "0.20.0", features = [ - "rt-tokio", - "collector_client", - "hyper_collector_client", +opentelemetry-otlp = { version = "0.14.0", features = [ + "trace", ] } reqwest = "0.11.6" diff --git a/examples/poem/opentelemetry-jaeger/README.md b/examples/poem/opentelemetry-jaeger/README.md index 1276e61253..e5d0c959c6 100644 --- a/examples/poem/opentelemetry-jaeger/README.md +++ b/examples/poem/opentelemetry-jaeger/README.md @@ -3,7 +3,7 @@ First make sure you have a running version of the Jaeger instance you want to send data to: ```shell -docker run -d -p6831:6831/udp -p6832:6832/udp -p16686:16686 -p14268:14268 jaegertracing/all-in-one:latest +docker run -e COLLECTOR_OTLP_ENABLED=true -p 4317:4317 -p 4318:4318 -p16686:16686 -p14268:14268 jaegertracing/all-in-one:latest ``` Launch the servers: diff --git a/examples/poem/opentelemetry-jaeger/src/client.rs b/examples/poem/opentelemetry-jaeger/src/client.rs index e3a49a72e2..2803b65966 100644 --- a/examples/poem/opentelemetry-jaeger/src/client.rs +++ b/examples/poem/opentelemetry-jaeger/src/client.rs @@ -6,17 +6,22 @@ use opentelemetry::{ Context, KeyValue, }; use opentelemetry_http::HeaderInjector; -use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::Tracer}; +use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::Tracer, Resource}; use reqwest::{Client, Method, Url}; fn init_tracer() -> Tracer { global::set_text_map_propagator(TraceContextPropagator::new()); - opentelemetry_jaeger::new_collector_pipeline() - .with_service_name("poem") - .with_endpoint("http://localhost:14268/api/traces") - .with_hyper() + opentelemetry_otlp::new_pipeline() + .tracing() + .with_trace_config( + opentelemetry_sdk::trace::config().with_resource(Resource::new(vec![KeyValue::new( + "service.name", + "poem", + )])), + ) + .with_exporter(opentelemetry_otlp::new_exporter().tonic()) .install_batch(opentelemetry_sdk::runtime::Tokio) - .unwrap() + .expect("Trace Pipeline should initialize.") } #[tokio::main] diff --git a/examples/poem/opentelemetry-jaeger/src/server1.rs b/examples/poem/opentelemetry-jaeger/src/server1.rs index 8978245853..c929cbca8f 100644 --- a/examples/poem/opentelemetry-jaeger/src/server1.rs +++ b/examples/poem/opentelemetry-jaeger/src/server1.rs @@ -6,7 +6,7 @@ use opentelemetry::{ Context, KeyValue, }; use opentelemetry_http::HeaderInjector; -use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::Tracer}; +use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::Tracer, Resource}; use poem::{ get, handler, listener::TcpListener, @@ -18,12 +18,17 @@ use reqwest::{Client, Url}; fn init_tracer() -> Tracer { global::set_text_map_propagator(TraceContextPropagator::new()); - opentelemetry_jaeger::new_collector_pipeline() - .with_service_name("poem") - .with_endpoint("http://localhost:14268/api/traces") - .with_hyper() + opentelemetry_otlp::new_pipeline() + .tracing() + .with_trace_config( + opentelemetry_sdk::trace::config().with_resource(Resource::new(vec![KeyValue::new( + "service.name", + "server1", + )])), + ) + .with_exporter(opentelemetry_otlp::new_exporter().tonic()) .install_batch(opentelemetry_sdk::runtime::Tokio) - .unwrap() + .expect("Trace Pipeline should initialize.") } #[handler] diff --git a/examples/poem/opentelemetry-jaeger/src/server2.rs b/examples/poem/opentelemetry-jaeger/src/server2.rs index 20a27a4063..fe58590235 100644 --- a/examples/poem/opentelemetry-jaeger/src/server2.rs +++ b/examples/poem/opentelemetry-jaeger/src/server2.rs @@ -1,5 +1,5 @@ -use opentelemetry::global; -use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::Tracer}; +use opentelemetry::{global, KeyValue}; +use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::Tracer, Resource}; use poem::{ get, handler, listener::TcpListener, @@ -9,12 +9,17 @@ use poem::{ fn init_tracer() -> Tracer { global::set_text_map_propagator(TraceContextPropagator::new()); - opentelemetry_jaeger::new_collector_pipeline() - .with_service_name("poem") - .with_endpoint("http://localhost:14268/api/traces") - .with_hyper() + opentelemetry_otlp::new_pipeline() + .tracing() + .with_trace_config( + opentelemetry_sdk::trace::config().with_resource(Resource::new(vec![KeyValue::new( + "service.name", + "server2", + )])), + ) + .with_exporter(opentelemetry_otlp::new_exporter().tonic()) .install_batch(opentelemetry_sdk::runtime::Tokio) - .unwrap() + .expect("Trace Pipeline should initialize.") } #[handler]