Manually pass the current context around
This commit is contained in:
19
src/files.rs
19
src/files.rs
@@ -13,7 +13,7 @@ use actix_web::web::Data;
|
||||
use actix_web::{web::{self, Query}, HttpRequest, HttpResponse};
|
||||
use log::{debug, error, info, trace};
|
||||
use opentelemetry::KeyValue;
|
||||
use opentelemetry::trace::{Span, Status, Tracer};
|
||||
use opentelemetry::trace::{Span, Status, TraceContextExt, Tracer};
|
||||
use crate::data::{Claims, FilesRequest, FilterMode, PhotosResponse, SortType};
|
||||
use crate::{create_thumbnails, AppState};
|
||||
|
||||
@@ -41,6 +41,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
let context = extract_context_from_request(&request);
|
||||
let mut span = tracer.start_with_context("list_photos", &context);
|
||||
span.set_attribute(KeyValue::new("path", search_path.to_string()));
|
||||
let span_context = opentelemetry::Context::current_with_span(span);
|
||||
|
||||
let search_recursively = req.recursive.unwrap_or(false);
|
||||
if let Some(tag_ids) = &req.tag_ids {
|
||||
@@ -66,8 +67,8 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
.collect::<Vec<i32>>();
|
||||
|
||||
return match filter_mode {
|
||||
FilterMode::Any => dao.get_files_with_any_tag_ids(tag_ids.clone(), exclude_tag_ids),
|
||||
FilterMode::All => dao.get_files_with_all_tag_ids(tag_ids.clone(), exclude_tag_ids),
|
||||
FilterMode::Any => dao.get_files_with_any_tag_ids(tag_ids.clone(), exclude_tag_ids, &span_context),
|
||||
FilterMode::All => dao.get_files_with_all_tag_ids(tag_ids.clone(), exclude_tag_ids, &span_context),
|
||||
}
|
||||
.context(format!(
|
||||
"Failed to get files with tag_ids: {:?} with filter_mode: {:?}",
|
||||
@@ -104,8 +105,8 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
tagged_files.len(),
|
||||
tagged_files
|
||||
);
|
||||
span.set_attribute(KeyValue::new("file_count", tagged_files.len().to_string()));
|
||||
span.set_status(Status::Ok);
|
||||
span_context.span().set_attribute(KeyValue::new("file_count", tagged_files.len().to_string()));
|
||||
span_context.span().set_status(Status::Ok);
|
||||
|
||||
HttpResponse::Ok().json(PhotosResponse {
|
||||
photos: tagged_files,
|
||||
@@ -138,7 +139,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
.map(|f| f.to_str().unwrap().to_string())
|
||||
.map(|file_name| {
|
||||
let mut tag_dao = tag_dao.lock().expect("Unable to get TagDao");
|
||||
let file_tags = tag_dao.get_tags_for_path(&file_name).unwrap_or_default();
|
||||
let file_tags = tag_dao.get_tags_for_path(&span_context, &file_name).unwrap_or_default();
|
||||
|
||||
(file_name, file_tags)
|
||||
})
|
||||
@@ -197,8 +198,8 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
.map(|f| f.to_str().unwrap().to_string())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
span.set_attribute(KeyValue::new("file_count", files.len().to_string()));
|
||||
span.set_status(Status::Ok);
|
||||
span_context.span().set_attribute(KeyValue::new("file_count", files.len().to_string()));
|
||||
span_context.span().set_status(Status::Ok);
|
||||
|
||||
HttpResponse::Ok().json(PhotosResponse {
|
||||
photos: response_files,
|
||||
@@ -206,7 +207,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
})
|
||||
} else {
|
||||
error!("Bad photos request: {}", req.path);
|
||||
span.set_status(Status::error("Invalid path"));
|
||||
span_context.span().set_status(Status::error("Invalid path"));
|
||||
HttpResponse::BadRequest().finish()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user