From 73fd339f9eb94f6affd761dc018b05b80b3224dc Mon Sep 17 00:00:00 2001 From: Nikola-3 <81659591+Nikola-3@users.noreply.github.com> Date: Fri, 15 Nov 2024 10:51:15 +1100 Subject: [PATCH] add high level trace logs to v3 (#212) Co-authored-by: ngrujic --- crates/atlaspack/src/requests/asset_graph_request.rs | 1 + crates/atlaspack/src/requests/entry_request.rs | 1 + crates/atlaspack/src/requests/target_request.rs | 1 + crates/atlaspack_monitoring/src/tracer.rs | 6 ++++-- crates/node-bindings/src/atlaspack/atlaspack.rs | 4 ++++ 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/atlaspack/src/requests/asset_graph_request.rs b/crates/atlaspack/src/requests/asset_graph_request.rs index 0b131d78f..7fc57f40a 100644 --- a/crates/atlaspack/src/requests/asset_graph_request.rs +++ b/crates/atlaspack/src/requests/asset_graph_request.rs @@ -73,6 +73,7 @@ impl AssetGraphBuilder { } } + #[tracing::instrument(level = "info", skip_all)] fn build(mut self) -> Result { for entry in self.request_context.options.clone().entries.iter() { self.work_count += 1; diff --git a/crates/atlaspack/src/requests/entry_request.rs b/crates/atlaspack/src/requests/entry_request.rs index 08e4a1bbb..e6c7db7b8 100644 --- a/crates/atlaspack/src/requests/entry_request.rs +++ b/crates/atlaspack/src/requests/entry_request.rs @@ -28,6 +28,7 @@ pub struct EntryRequestOutput { #[async_trait] impl Request for EntryRequest { + #[tracing::instrument(level = "info", skip_all)] async fn run( &self, request_context: RunRequestContext, diff --git a/crates/atlaspack/src/requests/target_request.rs b/crates/atlaspack/src/requests/target_request.rs index cd6de9f41..cd57275a5 100644 --- a/crates/atlaspack/src/requests/target_request.rs +++ b/crates/atlaspack/src/requests/target_request.rs @@ -647,6 +647,7 @@ fn fallback_output_format(context: EnvironmentContext) -> OutputFormat { #[async_trait] impl Request for TargetRequest { + #[tracing::instrument(level = "info", skip_all)] async fn run( &self, request_context: RunRequestContext, diff --git a/crates/atlaspack_monitoring/src/tracer.rs b/crates/atlaspack_monitoring/src/tracer.rs index 682521b74..a7c901862 100644 --- a/crates/atlaspack_monitoring/src/tracer.rs +++ b/crates/atlaspack_monitoring/src/tracer.rs @@ -3,14 +3,14 @@ //! Tracing is disabled by default. use std::sync::Arc; +use crate::from_env::{optional_var, FromEnvError}; use anyhow::anyhow; use serde::Deserialize; use serde::Serialize; use tracing_appender::non_blocking::WorkerGuard; +use tracing_subscriber::fmt::format::FmtSpan; use tracing_subscriber::EnvFilter; -use crate::from_env::{optional_var, FromEnvError}; - #[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase", tag = "mode")] pub enum TracerMode { @@ -73,6 +73,7 @@ impl Tracer { TracerMode::Stdout => { tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) + .with_span_events(FmtSpan::CLOSE) .try_init() .map_err(|err| { anyhow::anyhow!(err) @@ -96,6 +97,7 @@ impl Tracer { tracing_subscriber::fmt() .with_writer(non_blocking) + .with_span_events(FmtSpan::CLOSE) .try_init() .map_err(|err| { anyhow::anyhow!(err).context("Failed to setup file tracing, is another tracer running?") diff --git a/crates/node-bindings/src/atlaspack/atlaspack.rs b/crates/node-bindings/src/atlaspack/atlaspack.rs index b642794e3..9c9d0f924 100644 --- a/crates/node-bindings/src/atlaspack/atlaspack.rs +++ b/crates/node-bindings/src/atlaspack/atlaspack.rs @@ -55,6 +55,7 @@ pub struct AtlaspackNapi { #[napi] impl AtlaspackNapi { + #[tracing::instrument(level = "info", skip_all)] #[napi] pub fn create(napi_options: AtlaspackNapiOptions, lmdb: &LMDB, env: Env) -> napi::Result { let thread_id = std::thread::current().id(); @@ -108,6 +109,7 @@ impl AtlaspackNapi { }) } + #[tracing::instrument(level = "info", skip_all)] #[napi] pub fn build_asset_graph( &self, @@ -144,6 +146,7 @@ impl AtlaspackNapi { Ok(promise) } + #[tracing::instrument(level = "info", skip_all)] fn register_workers(&self, options: &AtlaspackNapiBuildOptions) -> napi::Result<()> { for _ in 0..self.node_worker_count { let transferable = JsTransferable::new(self.tx_worker.clone()); @@ -161,6 +164,7 @@ impl AtlaspackNapi { /// JavaScript does all its writes through a single thread, which is not this handle. If we want /// to sequence writes with the JavaScript writes, we should be using the /// [`lmdb_js_lite::writer::DatabaseWriterHandle`] instead. + #[tracing::instrument(level = "info", skip_all)] fn run_db_healthcheck(db: &Arc) -> napi::Result<()> { let run_healthcheck = || -> anyhow::Result<()> { let txn = db.read_txn()?;