Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more tracing to storare APIs, pass span into spawn_blocking #2438

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading