Skip to content

Commit

Permalink
Update opentelemetry.
Browse files Browse the repository at this point in the history
  • Loading branch information
ISibboI committed Dec 1, 2023
1 parent 72c47a5 commit 6e20664
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 69 deletions.
97 changes: 47 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions backend/rvoc-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ clap = { version = "4.4.7", features = ["derive"] }
# logging and telemetry
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.17", features = ["fmt", "json"] }
tracing-opentelemetry = { version = "0.21.0" }
opentelemetry = { version = "0.20.0", features = ["rt-tokio-current-thread"] }
opentelemetry-otlp = { version = "0.13.0" }
tracing-opentelemetry = { version = "0.22.0" }
opentelemetry = { version = "0.21.0" }
opentelemetry_sdk = { version = "0.21.1", features = [
"rt-tokio-current-thread",
] }
opentelemetry-otlp = { version = "0.14.0" }

# error handling
thiserror = "1.0.50"
Expand Down
33 changes: 17 additions & 16 deletions backend/rvoc-backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ mod web;

#[instrument(err, skip(configuration))]
fn setup_tracing_subscriber(configuration: &Configuration) -> RVocResult<()> {
use opentelemetry::sdk::Resource;
use opentelemetry::KeyValue;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::Resource;
use tracing::subscriber::set_global_default;
use tracing_subscriber::fmt::Layer;
use tracing_subscriber::layer::SubscriberExt;
Expand All @@ -38,21 +38,22 @@ fn setup_tracing_subscriber(configuration: &Configuration) -> RVocResult<()> {
let subscriber = Registry::default().with(logging_layer);

let with_otel = if let Some(opentelemetry_url) = configuration.opentelemetry_url.as_ref() {
let tracer =
opentelemetry_otlp::new_pipeline()
.tracing()
.with_trace_config(opentelemetry::sdk::trace::config().with_resource(
Resource::new(vec![KeyValue::new("service.name", "rvoc-backend")]),
))
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint(opentelemetry_url),
)
.install_batch(opentelemetry::runtime::TokioCurrentThread)
.map_err(|error| RVocError::SetupTracing {
source: Box::new(error),
})?;
let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_trace_config(
opentelemetry_sdk::trace::config().with_resource(Resource::new(vec![
KeyValue::new("service.name", "rvoc-backend"),
])),
)
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint(opentelemetry_url),
)
.install_batch(opentelemetry_sdk::runtime::TokioCurrentThread)
.map_err(|error| RVocError::SetupTracing {
source: Box::new(error),
})?;

let otel_layer = tracing_opentelemetry::layer().with_tracer(tracer);

Expand Down

0 comments on commit 6e20664

Please sign in to comment.