From 911d67b7774b632ca9696d8923d4d5583a5d1c21 Mon Sep 17 00:00:00 2001 From: Piotr Figiela <77412592+Draggu@users.noreply.github.com> Date: Wed, 18 Dec 2024 17:43:20 +0100 Subject: [PATCH] Add tracing spans for procmacros expansion (#45) --- src/lang/proc_macros/client/mod.rs | 6 ++++++ src/lang/proc_macros/controller.rs | 8 ++++++++ src/lang/proc_macros/plugins/mod.rs | 2 ++ 3 files changed, 16 insertions(+) diff --git a/src/lang/proc_macros/client/mod.rs b/src/lang/proc_macros/client/mod.rs index 7a0cdb9..243a25b 100644 --- a/src/lang/proc_macros/client/mod.rs +++ b/src/lang/proc_macros/client/mod.rs @@ -45,18 +45,22 @@ impl ProcMacroClient { } } + #[tracing::instrument(level = "trace", skip_all)] pub fn request_attribute(&self, params: ExpandAttributeParams) { self.send_request::(params, RequestParams::Attribute) } + #[tracing::instrument(level = "trace", skip_all)] pub fn request_derives(&self, params: ExpandDeriveParams) { self.send_request::(params, RequestParams::Derive) } + #[tracing::instrument(level = "trace", skip_all)] pub fn request_inline_macros(&self, params: ExpandInlineMacroParams) { self.send_request::(params, RequestParams::Inline) } + #[tracing::instrument(level = "trace", skip_all)] pub fn start_initialize(&self) { if let Err(err) = self.request_defined_macros() { error!("failed to request defined macros: {err:?}"); @@ -65,6 +69,7 @@ impl ProcMacroClient { } } + #[tracing::instrument(level = "trace", skip_all)] pub fn finish_initialize(&self) -> Result { self.handle_defined_macros() .inspect_err(|err| error!("failed to fetch defined macros: {err:?}")) @@ -151,6 +156,7 @@ impl ProcMacroClient { } } + #[tracing::instrument(level = "trace", skip_all)] fn failed(&self) { let _ = self.error_channel.try_send(()); } diff --git a/src/lang/proc_macros/controller.rs b/src/lang/proc_macros/controller.rs index 15e88b0..6b47bab 100644 --- a/src/lang/proc_macros/controller.rs +++ b/src/lang/proc_macros/controller.rs @@ -82,6 +82,7 @@ impl ProcMacroClientController { /// Start proc-macro-server after config reload. /// Note that this will only try to go from `ClientStatus::Pending` to /// `ClientStatus::Starting` if config allows this. + #[tracing::instrument(level = "trace", skip_all)] pub fn on_config_change(&mut self, db: &mut AnalysisDatabase, config: &Config) { if db.proc_macro_client_status().is_pending() { self.try_initialize(db, config); @@ -92,6 +93,7 @@ impl ProcMacroClientController { /// /// A new server instance is only started if there are available restart attempts left. /// This ensures that a fresh proc-macro-server is used. + #[tracing::instrument(level = "trace", skip_all)] pub fn force_restart(&mut self, db: &mut AnalysisDatabase, config: &Config) { // We have to make sure that snapshots will not report errors from previous client after we // create new one. @@ -108,6 +110,7 @@ impl ProcMacroClientController { } /// Check if an error was reported. If so, try to restart. + #[tracing::instrument(level = "trace", skip_all)] pub fn handle_error(&mut self, db: &mut AnalysisDatabase, config: &Config) { if !self.try_initialize(db, config) { self.fatal_failed(db, InitializationFailedInfo::NoMoreRetries); @@ -115,6 +118,7 @@ impl ProcMacroClientController { } /// If the client is ready, apply all available responses. + #[tracing::instrument(level = "trace", skip_all)] pub fn on_response(&mut self, db: &mut AnalysisDatabase, config: &Config) { match db.proc_macro_client_status() { ClientStatus::Starting(client) => { @@ -148,6 +152,7 @@ impl ProcMacroClientController { /// Tries starting proc-macro-server initialization process, if allowed by config. /// /// Returns value indicating if initialization was attempted. + #[tracing::instrument(level = "trace", skip_all)] fn try_initialize(&mut self, db: &mut AnalysisDatabase, config: &Config) -> bool { // Keep the rate limiter check as second condition when config doesn't allow it to make // sure it is not impacted. @@ -161,6 +166,7 @@ impl ProcMacroClientController { } /// Spawns proc-macro-server. + #[tracing::instrument(level = "trace", skip_all)] fn spawn_server(&mut self, db: &mut AnalysisDatabase) { match self.scarb.proc_macro_server() { Ok(proc_macro_server) => { @@ -184,6 +190,7 @@ impl ProcMacroClientController { } } + #[tracing::instrument(level = "trace", skip_all)] fn fatal_failed( &self, db: &mut AnalysisDatabase, @@ -197,6 +204,7 @@ impl ProcMacroClientController { }); } + #[tracing::instrument(level = "trace", skip_all)] fn apply_responses( &mut self, db: &mut AnalysisDatabase, diff --git a/src/lang/proc_macros/plugins/mod.rs b/src/lang/proc_macros/plugins/mod.rs index 9bdc83a..cf063b5 100644 --- a/src/lang/proc_macros/plugins/mod.rs +++ b/src/lang/proc_macros/plugins/mod.rs @@ -40,6 +40,7 @@ struct ProcMacroPlugin { } impl MacroPlugin for ProcMacroPlugin { + #[tracing::instrument(level = "trace", skip_all)] fn generate_code( &self, db: &dyn cairo_lang_syntax::node::db::SyntaxGroup, @@ -66,6 +67,7 @@ impl MacroPlugin for ProcMacroPlugin { struct InlineProcMacroPlugin; impl InlineMacroExprPlugin for InlineProcMacroPlugin { + #[tracing::instrument(level = "trace", skip_all)] fn generate_code( &self, db: &dyn cairo_lang_syntax::node::db::SyntaxGroup,