mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 16:21:24 +01:00
switch all tracing imports to observability::prelude
This commit is contained in:
parent
bc5f31b3a2
commit
5fca67054e
63 changed files with 824 additions and 735 deletions
|
|
@ -9,9 +9,8 @@ use tokio::{
|
|||
fs::{self, File},
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
};
|
||||
use tracing::{debug, warn};
|
||||
|
||||
use crate::{services, utils, Error, Result};
|
||||
use crate::{observability::prelude::*, services, utils, Error, Result};
|
||||
|
||||
mod data;
|
||||
|
||||
|
|
@ -47,7 +46,7 @@ pub(crate) struct Service {
|
|||
|
||||
impl Service {
|
||||
/// Uploads a file.
|
||||
#[tracing::instrument(skip(self, file))]
|
||||
#[t::instrument(skip(self, file))]
|
||||
pub(crate) async fn create(
|
||||
&self,
|
||||
mxc: OwnedMxcUri,
|
||||
|
|
@ -68,7 +67,7 @@ impl Service {
|
|||
}
|
||||
|
||||
/// Uploads or replaces a file thumbnail.
|
||||
#[tracing::instrument(skip(self, file))]
|
||||
#[t::instrument(skip(self, file))]
|
||||
pub(crate) async fn upload_thumbnail(
|
||||
&self,
|
||||
mxc: OwnedMxcUri,
|
||||
|
|
@ -89,7 +88,7 @@ impl Service {
|
|||
}
|
||||
|
||||
/// Downloads a file.
|
||||
#[tracing::instrument(skip(self))]
|
||||
#[t::instrument(skip(self))]
|
||||
pub(crate) async fn get(
|
||||
&self,
|
||||
mxc: OwnedMxcUri,
|
||||
|
|
@ -102,7 +101,7 @@ impl Service {
|
|||
}
|
||||
|
||||
/// Deletes a media object and all associated thumbnails.
|
||||
#[tracing::instrument(skip(self))]
|
||||
#[t::instrument(skip(self))]
|
||||
pub(crate) async fn delete(&self, mxc: OwnedMxcUri) -> Result<()> {
|
||||
let mut any_files = false;
|
||||
|
||||
|
|
@ -111,7 +110,7 @@ impl Service {
|
|||
any_files = true;
|
||||
self.delete_by_key(thumbnail_key.clone()).await.inspect_err(
|
||||
|error| {
|
||||
warn!(
|
||||
t::warn!(
|
||||
thumbnail_key = utils::u8_slice_to_hex(
|
||||
thumbnail_key.as_bytes()
|
||||
),
|
||||
|
|
@ -124,12 +123,12 @@ impl Service {
|
|||
|
||||
if let Some((_, key)) =
|
||||
self.db.search_file_metadata(mxc, 0, 0).inspect_err(
|
||||
|error| warn!(%error, "Failed to find original media key"),
|
||||
|error| t::warn!(%error, "Failed to find original media key"),
|
||||
)?
|
||||
{
|
||||
any_files = true;
|
||||
self.delete_by_key(key).await.inspect_err(
|
||||
|error| warn!(%error, "Failed to delete original media"),
|
||||
|error| t::warn!(%error, "Failed to delete original media"),
|
||||
)?;
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +137,7 @@ impl Service {
|
|||
} else {
|
||||
let error =
|
||||
Error::BadRequest(ErrorKind::NotFound, "Media not found");
|
||||
warn!(%error, "Failed to delete media");
|
||||
t::warn!(%error, "Failed to delete media");
|
||||
Err(error)
|
||||
}
|
||||
}
|
||||
|
|
@ -167,7 +166,7 @@ impl Service {
|
|||
///
|
||||
/// Each MXC is listed once. Thumbnails are not included separately from the
|
||||
/// original media.
|
||||
#[tracing::instrument(skip(self))]
|
||||
#[t::instrument(skip(self))]
|
||||
pub(crate) fn iter_all(&self) -> impl Iterator<Item = Result<OwnedMxcUri>> {
|
||||
let mut prev_mxc = None;
|
||||
self.db
|
||||
|
|
@ -206,7 +205,7 @@ impl Service {
|
|||
|
||||
/// Generates a thumbnail from the given image file contents. Returns
|
||||
/// `Ok(None)` if the input image should be used as-is.
|
||||
#[tracing::instrument(
|
||||
#[t::instrument(
|
||||
skip(file),
|
||||
fields(input_size = file.len(), original_width, original_height),
|
||||
)]
|
||||
|
|
@ -219,18 +218,18 @@ impl Service {
|
|||
let image = match image::load_from_memory(file) {
|
||||
Ok(image) => image,
|
||||
Err(error) => {
|
||||
warn!(%error, "Failed to parse source image");
|
||||
t::warn!(%error, "Failed to parse source image");
|
||||
return Ok(None);
|
||||
}
|
||||
};
|
||||
|
||||
let original_width = image.width();
|
||||
let original_height = image.height();
|
||||
tracing::Span::current().record("original_width", original_width);
|
||||
tracing::Span::current().record("original_height", original_height);
|
||||
t::Span::current().record("original_width", original_width);
|
||||
t::Span::current().record("original_height", original_height);
|
||||
|
||||
if width > original_width || height > original_height {
|
||||
debug!("Requested thumbnail is larger than source image");
|
||||
t::debug!("Requested thumbnail is larger than source image");
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
|
|
@ -276,7 +275,7 @@ impl Service {
|
|||
image.thumbnail_exact(exact_width, exact_height)
|
||||
};
|
||||
|
||||
debug!("Serializing thumbnail as PNG");
|
||||
t::debug!("Serializing thumbnail as PNG");
|
||||
let mut thumbnail_bytes = Vec::new();
|
||||
thumbnail.write_to(
|
||||
&mut Cursor::new(&mut thumbnail_bytes),
|
||||
|
|
@ -299,7 +298,7 @@ impl Service {
|
|||
///
|
||||
/// For width,height <= 96 the server uses another thumbnailing algorithm
|
||||
/// which crops the image afterwards.
|
||||
#[tracing::instrument(skip(self))]
|
||||
#[t::instrument(skip(self))]
|
||||
pub(crate) async fn get_thumbnail(
|
||||
&self,
|
||||
mxc: OwnedMxcUri,
|
||||
|
|
@ -313,26 +312,26 @@ impl Service {
|
|||
if let Some((meta, key)) =
|
||||
self.db.search_file_metadata(mxc.clone(), width, height)?
|
||||
{
|
||||
debug!("Using saved thumbnail");
|
||||
t::debug!("Using saved thumbnail");
|
||||
return Ok(self.read_content(&key).await?.map(|file| (meta, file)));
|
||||
}
|
||||
|
||||
let Some((meta, key)) =
|
||||
self.db.search_file_metadata(mxc.clone(), 0, 0)?
|
||||
else {
|
||||
debug!("Original image not found, can't generate thumbnail");
|
||||
t::debug!("Original image not found, can't generate thumbnail");
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let Some(file) = self.read_content(&key).await? else {
|
||||
debug!("Original image not found, can't generate thumbnail");
|
||||
t::debug!("Original image not found, can't generate thumbnail");
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
debug!("Generating thumbnail");
|
||||
t::debug!("Generating thumbnail");
|
||||
let thumbnail_result = {
|
||||
let file = file.clone();
|
||||
let outer_span = tracing::span::Span::current();
|
||||
let outer_span = t::span::Span::current();
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
outer_span.in_scope(|| {
|
||||
|
|
@ -344,11 +343,11 @@ impl Service {
|
|||
};
|
||||
|
||||
let Some(thumbnail_bytes) = thumbnail_result? else {
|
||||
debug!("Returning source image as-is");
|
||||
t::debug!("Returning source image as-is");
|
||||
return Ok(Some((meta, file)));
|
||||
};
|
||||
|
||||
debug!("Saving created thumbnail");
|
||||
t::debug!("Saving created thumbnail");
|
||||
|
||||
// Save thumbnail in database so we don't have to generate it
|
||||
// again next time
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue