Skip to content

Commit

Permalink
chore(examples/bank-accounting): use opentelemetry-otlp as trace expo…
Browse files Browse the repository at this point in the history
…rter (#297)
  • Loading branch information
ar3s3ru authored Mar 16, 2024
1 parent 59b1c7e commit 7d65829
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/bank-accounting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ eventually = { path = "../../eventually", features = [
eventually-macros = { path = "../../eventually-macros" }
eventually-postgres = { path = "../../eventually-postgres" }
opentelemetry = "0.21.0"
opentelemetry-jaeger = "0.20.0"
opentelemetry-otlp = "0.14.0"
opentelemetry_sdk = { version = "0.21.2", features = ["rt-tokio"] }
prost = "0.12.3"
rust_decimal = "1.34.3"
sqlx = { version = "0.7.3", features = ["runtime-tokio-rustls", "postgres"] }
Expand Down
19 changes: 14 additions & 5 deletions examples/bank-accounting/src/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
use anyhow::anyhow;
use opentelemetry::KeyValue;
use opentelemetry_sdk::{trace, Resource};
use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;

pub fn initialize(service_name: &str) -> anyhow::Result<()> {
let tracer = opentelemetry_jaeger::new_agent_pipeline()
.with_service_name(service_name)
.install_simple()
.map_err(|e| anyhow!("failed to initialize jaeger tracer: {}", e))?;
pub fn initialize(service_name: &'static str) -> anyhow::Result<()> {
let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(opentelemetry_otlp::new_exporter().tonic())
.with_trace_config(
opentelemetry_sdk::trace::config()
.with_sampler(trace::Sampler::AlwaysOn)
.with_id_generator(trace::RandomIdGenerator::default())
.with_resource(Resource::new([KeyValue::new("service.name", service_name)])),
)
.install_batch(opentelemetry_sdk::runtime::Tokio)
.map_err(|e| anyhow!("failed to initialize OTLP tracer: {}", e))?;

let filter_layer = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new("info"))
Expand Down

0 comments on commit 7d65829

Please sign in to comment.