Additional Otel logging and spans

This commit is contained in:
Cameron
2025-05-23 14:51:54 -04:00
parent 24d2123fc2
commit d37deb36fe
3 changed files with 35 additions and 7 deletions

View File

@@ -83,6 +83,9 @@ async fn get_image(
req: web::Query<ThumbnailRequest>,
app_state: Data<AppState>,
) -> impl Responder {
let tracer = global_tracer();
let mut span = tracer.start("get_image");
if let Some(path) = is_valid_full_path(&app_state.base_path, &req.path, false) {
let image_size = req.size.unwrap_or(PhotoSize::Full);
if image_size == PhotoSize::Thumb {
@@ -95,16 +98,21 @@ async fn get_image(
trace!("Thumbnail path: {:?}", thumb_path);
if let Ok(file) = NamedFile::open(&thumb_path) {
span.set_status(Status::Ok);
file.into_response(&request)
} else {
span.set_status(Status::error("Not found"));
HttpResponse::NotFound().finish()
}
} else if let Ok(file) = NamedFile::open(path) {
span.set_status(Status::Ok);
file.into_response(&request)
} else {
span.set_status(Status::error("Not found"));
HttpResponse::NotFound().finish()
}
} else {
span.set_status(Status::error("Bad photos request"));
error!("Bad photos request: {}", req.path);
HttpResponse::BadRequest().finish()
}
@@ -309,7 +317,7 @@ async fn get_video_part(
path: web::Path<ThumbnailRequest>,
app_state: Data<AppState>,
) -> impl Responder {
let tracer = global::tracer("image-server");
let tracer = global_tracer();
let mut span = tracer.start("get_video_part");
let part = &path.path;
@@ -381,15 +389,15 @@ async fn put_add_favorite(
.await
{
Ok(Err(e)) if e.kind == DbErrorKind::AlreadyExists => {
debug!("Favorite: {} exists for user: {}", &body.path, user_id);
warn!("Favorite: {} exists for user: {}", &body.path, user_id);
HttpResponse::Ok()
}
Ok(Err(e)) => {
info!("{:?} {}. for user: {}", e, body.path, user_id);
error!("{:?} {}. for user: {}", e, body.path, user_id);
HttpResponse::BadRequest()
}
Ok(Ok(_)) => {
debug!("Adding favorite \"{}\" for userid: {}", body.path, user_id);
info!("Adding favorite \"{}\" for userid: {}", body.path, user_id);
HttpResponse::Created()
}
Err(e) => {