Skip to content

Commit

Permalink
Update opentelemetry-jaeger to use OTLP
Browse files Browse the repository at this point in the history
Jaeger has been compatibile with OTLP for over 2 years. We want to
encourage usage of OTLP exporter.

open-telemetry/opentelemetry-rust#995
  • Loading branch information
hdost committed Feb 28, 2024
1 parent e3b2201 commit 0f03c17
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
8 changes: 3 additions & 5 deletions examples/poem/opentelemetry-jaeger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion examples/poem/opentelemetry-jaeger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 9 additions & 6 deletions examples/poem/opentelemetry-jaeger/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ 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]
Expand Down
17 changes: 11 additions & 6 deletions examples/poem/opentelemetry-jaeger/src/server1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]
Expand Down
19 changes: 12 additions & 7 deletions examples/poem/opentelemetry-jaeger/src/server2.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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]
Expand Down

0 comments on commit 0f03c17

Please sign in to comment.