mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-05 20:37:41 +00:00
refactor: rework init_tracing to avoid unused variable
... when feature `telemetry-otlp` is not enabled move feature management into tracing_setup module to make the server code cleaner.
This commit is contained in:
@@ -7,7 +7,6 @@ extern crate tracing;
|
||||
mod cli;
|
||||
mod secrets;
|
||||
mod server;
|
||||
#[cfg(feature = "telemetry-otlp")]
|
||||
mod tracing_setup;
|
||||
|
||||
#[cfg(not(any(feature = "bundled-libs", feature = "system-libs")))]
|
||||
|
||||
@@ -15,8 +15,7 @@ use garage_web::WebServer;
|
||||
use garage_api_k2v::api_server::K2VApiServer;
|
||||
|
||||
use crate::secrets::{fill_secrets, Secrets};
|
||||
#[cfg(feature = "telemetry-otlp")]
|
||||
use crate::tracing_setup::*;
|
||||
use crate::tracing_setup::init_tracing;
|
||||
|
||||
async fn wait_from(mut chan: watch::Receiver<bool>) {
|
||||
while !*chan.borrow() {
|
||||
@@ -54,12 +53,7 @@ pub async fn run_server(config_file: PathBuf, secrets: Secrets) -> Result<(), Er
|
||||
|
||||
if let Some(admin_trace_sink) = &config.admin.trace_sink {
|
||||
info!("Initialize tracing...");
|
||||
|
||||
#[cfg(feature = "telemetry-otlp")]
|
||||
init_tracing(admin_trace_sink, garage.system.id)?;
|
||||
|
||||
#[cfg(not(feature = "telemetry-otlp"))]
|
||||
error!("Garage was built without OTLP exporter, admin.trace_sink is ignored.");
|
||||
}
|
||||
|
||||
info!("Initialize Admin API server and metrics collector...");
|
||||
|
||||
+50
-34
@@ -1,37 +1,53 @@
|
||||
use std::time::Duration;
|
||||
pub use telemetry::init_tracing;
|
||||
|
||||
use opentelemetry::sdk::{
|
||||
trace::{self, IdGenerator, Sampler},
|
||||
Resource,
|
||||
};
|
||||
use opentelemetry::KeyValue;
|
||||
use opentelemetry_otlp::WithExportConfig;
|
||||
#[cfg(not(feature = "telemetry-otlp"))]
|
||||
mod telemetry {
|
||||
use garage_util::data::Uuid;
|
||||
use garage_util::error::Error;
|
||||
|
||||
use garage_util::data::*;
|
||||
use garage_util::error::*;
|
||||
|
||||
pub fn init_tracing(export_to: &str, node_id: Uuid) -> Result<(), Error> {
|
||||
let node_id = hex::encode(&node_id.as_slice()[..8]);
|
||||
|
||||
opentelemetry_otlp::new_pipeline()
|
||||
.tracing()
|
||||
.with_exporter(
|
||||
opentelemetry_otlp::new_exporter()
|
||||
.tonic()
|
||||
.with_endpoint(export_to)
|
||||
.with_timeout(Duration::from_secs(3)),
|
||||
)
|
||||
.with_trace_config(
|
||||
trace::config()
|
||||
.with_id_generator(IdGenerator::default())
|
||||
.with_sampler(Sampler::AlwaysOn)
|
||||
.with_resource(Resource::new(vec![
|
||||
KeyValue::new("service.name", "garage"),
|
||||
KeyValue::new("service.instance.id", node_id),
|
||||
])),
|
||||
)
|
||||
.install_batch(opentelemetry::runtime::Tokio)
|
||||
.ok_or_message("Unable to initialize tracing")?;
|
||||
|
||||
Ok(())
|
||||
pub fn init_tracing(_: &str, _: Uuid) -> Result<(), Error> {
|
||||
error!("Garage was built without OTLP exporter, admin.trace_sink is ignored.");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "telemetry-otlp")]
|
||||
mod telemetry {
|
||||
use std::time::Duration;
|
||||
|
||||
use opentelemetry::sdk::{
|
||||
trace::{self, IdGenerator, Sampler},
|
||||
Resource,
|
||||
};
|
||||
use opentelemetry::KeyValue;
|
||||
use opentelemetry_otlp::WithExportConfig;
|
||||
|
||||
use garage_util::data::*;
|
||||
use garage_util::error::*;
|
||||
|
||||
pub fn init_tracing(export_to: &str, node_id: Uuid) -> Result<(), Error> {
|
||||
let node_id = hex::encode(&node_id.as_slice()[..8]);
|
||||
|
||||
opentelemetry_otlp::new_pipeline()
|
||||
.tracing()
|
||||
.with_exporter(
|
||||
opentelemetry_otlp::new_exporter()
|
||||
.tonic()
|
||||
.with_endpoint(export_to)
|
||||
.with_timeout(Duration::from_secs(3)),
|
||||
)
|
||||
.with_trace_config(
|
||||
trace::config()
|
||||
.with_id_generator(IdGenerator::default())
|
||||
.with_sampler(Sampler::AlwaysOn)
|
||||
.with_resource(Resource::new(vec![
|
||||
KeyValue::new("service.name", "garage"),
|
||||
KeyValue::new("service.instance.id", node_id),
|
||||
])),
|
||||
)
|
||||
.install_batch(opentelemetry::runtime::Tokio)
|
||||
.ok_or_message("Unable to initialize tracing")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user