Skip to content

Commit

Permalink
add more tracing to storare APIs, pass span into spawn_blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Mar 2, 2024
1 parent 045ae1c commit f654ba1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::{
sync::Arc,
};
use tokio::{io::AsyncWriteExt, runtime::Runtime};
use tracing::{error, instrument, trace};
use tracing::{error, info_span, instrument, trace, Instrument};

type FileRange = RangeInclusive<u64>;

Expand Down Expand Up @@ -347,6 +347,7 @@ impl AsyncStorage {
Ok(local_index_path)
}

#[instrument(skip(fetch_time))]
pub(crate) async fn get_from_archive(
&self,
archive_path: &str,
Expand All @@ -360,10 +361,14 @@ impl AsyncStorage {
}
let index_filename = self
.download_archive_index(archive_path, latest_build_id)
.instrument(info_span!("download archive index"))
.await?;

let info = {
let path = path.to_owned();
spawn_blocking(move || archive_index::find_in_file(index_filename, &path)).await
spawn_blocking(move || archive_index::find_in_file(index_filename, &path))
.instrument(info_span!("find path in index"))
.await
}?
.ok_or(PathNotFoundError)?;

Expand Down
13 changes: 10 additions & 3 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ use postgres::Client;
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::panic;
use tracing::error;
use tracing::{error, warn, Span};
pub(crate) mod sized_buffer;

use std::{future::Future, thread, time::Duration};
use tracing::warn;

pub(crate) const APP_USER_AGENT: &str = concat!(
env!("CARGO_PKG_NAME"),
Expand Down Expand Up @@ -116,7 +115,15 @@ where
F: FnOnce() -> Result<R> + Send + 'static,
R: Send + 'static,
{
match tokio::task::spawn_blocking(f).await {
let span = Span::current();

let result = tokio::task::spawn_blocking(move || {
let _guard = span.enter();
f()
})
.await;

match result {
Ok(result) => result,
Err(err) if err.is_panic() => panic::resume_unwind(err.into_panic()),
Err(err) => Err(err.into()),
Expand Down

0 comments on commit f654ba1

Please sign in to comment.