Skip to content

Commit

Permalink
Instrument more functions with tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Jun 9, 2023
1 parent f93f083 commit 2cb7b8f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
13 changes: 13 additions & 0 deletions lib/wasix/src/runtime/package_loader/builtin_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl BuiltinPackageLoader {
Ok(None)
}

#[tracing::instrument(level = "debug", skip_all, fields(%dist.webc, %dist.webc_sha256))]
async fn download(&self, dist: &DistributionInfo) -> Result<Bytes, Error> {
if dist.webc.scheme() == "file" {
match crate::runtime::resolver::utils::file_path_from_url(&dist.webc) {
Expand Down Expand Up @@ -114,8 +115,19 @@ impl BuiltinPackageLoader {
options: Default::default(),
};

tracing::debug!(%request.url, %request.method, "Downloading a webc file");
tracing::trace!(?request.headers);

let response = self.client.request(request).await?;

tracing::trace!(
%response.status,
%response.redirected,
?response.headers,
response.len=response.body.as_ref().map(|body| body.len()),
"Received a response",
);

if !response.is_ok() {
let url = &dist.webc;
return Err(crate::runtime::resolver::utils::http_error(&response)
Expand All @@ -129,6 +141,7 @@ impl BuiltinPackageLoader {
Ok(body.into())
}

#[tracing::instrument(level = "debug", skip_all)]
async fn save_and_load_as_mmapped(
&self,
webc: &[u8],
Expand Down
13 changes: 9 additions & 4 deletions lib/wasix/src/runtime/resolver/wapm_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl Source for WapmSource {
PackageSpecifier::Registry { full_name, version } => (full_name, version),
_ => return Ok(Vec::new()),
};

#[derive(serde::Serialize)]
struct Body {
query: String,
Expand All @@ -49,17 +50,18 @@ impl Source for WapmSource {
let body = Body {
query: WAPM_WEBC_QUERY_ALL.replace("$NAME", full_name),
};
let body = serde_json::to_string(&body)?;
tracing::trace!(%body, "Sending GraphQL query");

let request = HttpRequest {
url: self.registry_endpoint.clone(),
method: Method::POST,
body: Some(body.into_bytes()),
body: Some(serde_json::to_string(&body)?.into_bytes()),
headers: headers(),
options: Default::default(),
};

tracing::debug!(%request.url, %request.method, "Querying the GraphQL API");
tracing::trace!(?request.headers, request.body=body.query.as_str());

let response = self.client.request(request).await?;

if !response.is_ok() {
Expand All @@ -70,7 +72,10 @@ impl Source for WapmSource {

let body = response.body.unwrap_or_default();
tracing::trace!(
body=?String::from_utf8_lossy(&body),
%response.status,
%response.redirected,
?response.headers,
response.body=?String::from_utf8_lossy(&body),
"Received a response from GraphQL",
);

Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/runtime/resolver/web_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl WebSource {
}

/// Download a package and cache it locally.
#[tracing::instrument(skip_all, fields(%url))]
#[tracing::instrument(level = "debug", skip_all, fields(%url))]
async fn get_locally_cached_file(&self, url: &Url) -> Result<PathBuf, Error> {
// This function is a bit tricky because we go to great lengths to avoid
// unnecessary downloads.
Expand Down

0 comments on commit 2cb7b8f

Please sign in to comment.