Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions rust/tracing/src/init_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use tokio::runtime::Handle;
use tracing_subscriber::fmt;
use tracing_subscriber::layer::Identity;
use tracing_subscriber::Registry;
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Layer};

Expand Down Expand Up @@ -131,6 +132,11 @@ pub fn init_otel_layer(
service_name: &String,
otel_endpoint: &String,
) -> Box<dyn Layer<Registry> + Send + Sync> {
if otel_endpoint.trim().is_empty() {
tracing::info!("OpenTelemetry is disabled because its endpoint is empty");
return Box::new(Identity::new());
}

install_rustls_crypto_provider();

tracing::info!(
Expand Down Expand Up @@ -406,3 +412,17 @@ pub fn init_otel_tracing(
init_tracing(layers);
init_panic_tracing_hook();
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn empty_otel_endpoint_does_not_initialize_exporters() {
let service_name = "test-service".to_string();

for endpoint in ["", " ", "\t\n"] {
let _layer = init_otel_layer(&service_name, &endpoint.to_string());
}
}
}