Only use Otel on release builds

This commit is contained in:
Cameron
2025-05-17 13:41:30 -04:00
parent 5b17fba51f
commit 484eec8b39

View File

@@ -184,8 +184,10 @@ async fn upload_image(
&full_path.to_str().unwrap().to_string(), &full_path.to_str().unwrap().to_string(),
true, true,
) { ) {
let context = opentelemetry::Context::new().with_remote_span_context(span.span_context().clone()); let context =
tracer.span_builder("file write") opentelemetry::Context::new().with_remote_span_context(span.span_context().clone());
tracer
.span_builder("file write")
.start_with_context(&tracer, &context); .start_with_context(&tracer, &context);
if !full_path.is_file() && is_image_or_video(&full_path) { if !full_path.is_file() && is_image_or_video(&full_path) {
@@ -322,7 +324,10 @@ async fn get_video_part(
file.into_response(&request) file.into_response(&request)
} else { } else {
error!("Video part not found: {:?}", file_part); error!("Video part not found: {:?}", file_part);
span.set_status(Status::error(format!("Video part not found '{}'", file_part.to_str().unwrap()))); span.set_status(Status::error(format!(
"Video part not found '{}'",
file_part.to_str().unwrap()
)));
HttpResponse::NotFound().finish() HttpResponse::NotFound().finish()
} }
} }
@@ -454,7 +459,8 @@ fn create_thumbnails() {
let mut video_span = tracer.start_with_context( let mut video_span = tracer.start_with_context(
"generate_video_thumbnail", "generate_video_thumbnail",
&opentelemetry::Context::new().with_remote_span_context(span.span_context().clone()), &opentelemetry::Context::new()
.with_remote_span_context(span.span_context().clone()),
); );
video_span.set_attributes(vec![ video_span.set_attributes(vec![
KeyValue::new("type", "video"), KeyValue::new("type", "video"),
@@ -538,7 +544,6 @@ fn main() -> std::io::Result<()> {
if let Err(err) = dotenv::dotenv() { if let Err(err) = dotenv::dotenv() {
println!("Error parsing .env {:?}", err); println!("Error parsing .env {:?}", err);
} }
// env_logger::init();
run_migrations(&mut connect()).expect("Failed to run migrations"); run_migrations(&mut connect()).expect("Failed to run migrations");
@@ -546,9 +551,17 @@ fn main() -> std::io::Result<()> {
let system = actix::System::new(); let system = actix::System::new();
system.block_on(async { system.block_on(async {
// Just use basic logger when running a non-release build
#[cfg(debug_assertions)]
{
env_logger::init();
}
#[cfg(not(debug_assertions))]
{
otel::init_logs();
otel::init_tracing();
}
otel::init_logs();
otel::init_tracing();
create_thumbnails(); create_thumbnails();
let app_data = Data::new(AppState::default()); let app_data = Data::new(AppState::default());