From 6fedece745ac9c464763fda4a0475872602f7add Mon Sep 17 00:00:00 2001 From: Hana Date: Wed, 16 Oct 2024 20:43:42 +0800 Subject: [PATCH] refactor: init --- .vscode/settings.json | 2 +- Cargo.lock | 139 ++++- Cargo.toml | 2 +- crates/node_binding/Cargo.toml | 8 +- crates/node_binding/binding.d.ts | 3 +- crates/node_binding/src/lib.rs | 96 ++-- crates/node_binding/src/plugins/mod.rs | 2 +- crates/rspack_binding_options/Cargo.toml | 1 + .../src/plugins/js_loader/context.rs | 11 + .../src/build_chunk_graph/code_splitter.rs | 2 +- .../rspack_core/src/build_chunk_graph/mod.rs | 2 +- .../src/chunk_graph/chunk_graph_module.rs | 2 +- .../rspack_core/src/compiler/compilation.rs | 75 +-- crates/rspack_core/src/compiler/hmr.rs | 4 + .../src/compiler/make/repair/build.rs | 1 + crates/rspack_core/src/compiler/mod.rs | 9 +- crates/rspack_core/src/concatenated_module.rs | 2 +- crates/rspack_core/src/context_module.rs | 2 +- .../rspack_core/src/context_module_factory.rs | 2 +- crates/rspack_core/src/external_module.rs | 2 +- crates/rspack_core/src/module_graph/mod.rs | 2 +- crates/rspack_core/src/normal_module.rs | 8 +- .../rspack_core/src/normal_module_factory.rs | 1 - .../src/old_cache/occasion/code_generate.rs | 2 +- .../occasion/process_runtime_requirements.rs | 2 +- crates/rspack_core/src/raw_module.rs | 2 +- crates/rspack_core/src/resolver/mod.rs | 21 + crates/rspack_core/src/self_module.rs | 2 +- .../rspack_core/src/unaffected_cache/mod.rs | 370 ++++++++++++ crates/rspack_core/src/utils/task_loop.rs | 14 +- crates/rspack_loader_runner/Cargo.toml | 1 + crates/rspack_loader_runner/src/runner.rs | 6 + crates/rspack_loader_swc/Cargo.toml | 1 + crates/rspack_loader_swc/src/lib.rs | 1 + crates/rspack_macros/src/plugin.rs | 4 +- .../src/css_module.rs | 2 +- ...sm_export_imported_specifier_dependency.rs | 2 +- .../esm/esm_import_specifier_dependency.rs | 2 +- .../src/parser_and_generator/mod.rs | 1 + .../plugin/flag_dependency_exports_plugin.rs | 2 +- .../src/plugin/side_effects_flag_plugin.rs | 4 +- .../src/module.rs | 2 +- .../src/container/container_entry_module.rs | 2 +- .../src/container/fallback_module.rs | 2 +- .../src/container/remote_module.rs | 2 +- .../src/sharing/consume_shared_module.rs | 2 +- .../src/sharing/provide_shared_module.rs | 2 +- .../src/plugin/chunk.rs | 4 +- .../src/plugin/max_request.rs | 2 +- .../src/plugin/max_size.rs | 2 +- .../src/plugin/min_size.rs | 2 +- .../src/plugin/mod.rs | 11 +- .../src/plugin/module_group.rs | 6 +- crates/rspack_tracing/Cargo.toml | 12 +- crates/rspack_tracing/src/chrome.rs | 51 ++ crates/rspack_tracing/src/lib.rs | 131 +---- crates/rspack_tracing/src/opentelemetry.rs | 47 ++ crates/rspack_tracing/src/stdout.rs | 28 + crates/rspack_tracing/src/tokio_console.rs | 12 + crates/rspack_tracing/src/tracer.rs | 8 + packages/rspack-cli/package.json | 1 + packages/rspack-cli/src/utils/profile.ts | 16 +- .../tests/build/profile/profile.test.ts | 4 +- packages/rspack-tracing/index.d.ts | 3 + packages/rspack-tracing/index.js | 34 ++ packages/rspack-tracing/package.json | 27 + packages/rspack-tracing/tsconfig.build.json | 10 + packages/rspack/package.json | 1 + packages/rspack/src/exports.ts | 22 +- packages/rspack/src/loader-runner/index.ts | 32 ++ pnpm-lock.yaml | 541 ++++++++++++++++++ 71 files changed, 1566 insertions(+), 270 deletions(-) create mode 100644 crates/rspack_core/src/unaffected_cache/mod.rs create mode 100644 crates/rspack_tracing/src/chrome.rs create mode 100644 crates/rspack_tracing/src/opentelemetry.rs create mode 100644 crates/rspack_tracing/src/stdout.rs create mode 100644 crates/rspack_tracing/src/tokio_console.rs create mode 100644 crates/rspack_tracing/src/tracer.rs create mode 100644 packages/rspack-tracing/index.d.ts create mode 100644 packages/rspack-tracing/index.js create mode 100644 packages/rspack-tracing/package.json create mode 100644 packages/rspack-tracing/tsconfig.build.json diff --git a/.vscode/settings.json b/.vscode/settings.json index 6d07ace19b6..6b5e375a759 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -43,4 +43,4 @@ "ukey", "Ukey" ] -} \ No newline at end of file +} diff --git a/Cargo.lock b/Cargo.lock index 4a8b9c00d8c..86c5f7f0a75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2082,9 +2082,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" dependencies = [ "wasm-bindgen", ] @@ -2692,6 +2692,71 @@ dependencies = [ "loom", ] +[[package]] +name = "opentelemetry" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "570074cc999d1a58184080966e5bd3bf3a9a4af650c3b05047c2621e7405cd17" +dependencies = [ + "futures-core", + "futures-sink", + "js-sys", + "once_cell", + "pin-project-lite", + "thiserror", +] + +[[package]] +name = "opentelemetry-otlp" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29e1f9c8b032d4f635c730c0efcf731d5e2530ea13fa8bef7939ddc8420696bd" +dependencies = [ + "async-trait", + "futures-core", + "http", + "opentelemetry", + "opentelemetry-proto", + "opentelemetry_sdk", + "prost", + "thiserror", + "tokio", + "tonic", +] + +[[package]] +name = "opentelemetry-proto" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9d3968ce3aefdcca5c27e3c4ea4391b37547726a70893aab52d3de95d5f8b34" +dependencies = [ + "opentelemetry", + "opentelemetry_sdk", + "prost", + "tonic", +] + +[[package]] +name = "opentelemetry_sdk" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2c627d9f4c9cdc1f21a29ee4bfbd6028fcb8bcf2a857b43f3abdf72c9c862f3" +dependencies = [ + "async-trait", + "futures-channel", + "futures-executor", + "futures-util", + "glob", + "once_cell", + "opentelemetry", + "percent-encoding", + "rand", + "serde_json", + "thiserror", + "tokio", + "tokio-stream", +] + [[package]] name = "outref" version = "0.1.0" @@ -3537,6 +3602,7 @@ dependencies = [ "rspack_plugin_web_worker_template", "rspack_plugin_worker", "rspack_regex", + "rspack_tracing", "rustc-hash 1.1.0", "serde", "serde_json", @@ -3820,6 +3886,7 @@ dependencies = [ "rustc-hash 1.1.0", "serde_json", "tokio", + "tracing", ] [[package]] @@ -3845,6 +3912,7 @@ dependencies = [ "swc_config", "swc_core", "swc_plugin_import", + "tracing", "url", ] @@ -3906,6 +3974,7 @@ dependencies = [ name = "rspack_node" version = "0.1.0" dependencies = [ + "anyhow", "async-trait", "color-backtrace", "cow-utils", @@ -3930,6 +3999,7 @@ dependencies = [ "rspack_tracing", "rspack_util", "tracing", + "tracing-subscriber", ] [[package]] @@ -4629,8 +4699,12 @@ name = "rspack_tracing" version = "0.1.0" dependencies = [ "console-subscriber", + "opentelemetry", + "opentelemetry-otlp", + "opentelemetry_sdk", "tracing", "tracing-chrome", + "tracing-opentelemetry", "tracing-subscriber", ] @@ -6612,9 +6686,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" dependencies = [ "futures-core", "pin-project-lite", @@ -6682,9 +6756,9 @@ dependencies = [ [[package]] name = "tonic" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6f6ba989e4b2c58ae83d862d3a3e27690b6e3ae630d0deb59f3697f32aa88ad" +checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" dependencies = [ "async-stream", "async-trait", @@ -6811,6 +6885,24 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-opentelemetry" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc58af5d3f6c5811462cabb3289aec0093f7338e367e5a33d28c0433b3c7360b" +dependencies = [ + "js-sys", + "once_cell", + "opentelemetry", + "opentelemetry_sdk", + "smallvec", + "tracing", + "tracing-core", + "tracing-log", + "tracing-subscriber", + "web-time", +] + [[package]] name = "tracing-subscriber" version = "0.3.18" @@ -7244,34 +7336,35 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.79", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -7279,22 +7372,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "wasm-encoder" @@ -7640,6 +7733,16 @@ dependencies = [ "wast", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webc" version = "6.0.1" diff --git a/Cargo.toml b/Cargo.toml index a9a066fc487..f2cfd3569d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,7 @@ ustr = { package = "ustr-fxhash", version = "1.0.0" } xxhash-rust = { version = "0.8.10" } # Pinned -napi = { version = "3.0.0-alpha.19" } +napi = { version = "3.0.0-alpha.19", features = ["anyhow"] } napi-build = { version = "2" } napi-derive = { version = "3.0.0-alpha.17" } diff --git a/crates/node_binding/Cargo.toml b/crates/node_binding/Cargo.toml index 0304f1e58f7..9ca35282050 100644 --- a/crates/node_binding/Cargo.toml +++ b/crates/node_binding/Cargo.toml @@ -14,6 +14,7 @@ default = [] plugin = ["rspack_binding_options/plugin"] [dependencies] +anyhow = { workspace = true } ropey = { workspace = true } rspack_allocator = { version = "0.1.0", path = "../rspack_allocator" } rspack_binding_options = { version = "0.1.0", path = "../rspack_binding_options" } @@ -33,9 +34,10 @@ rspack_util = { version = "0.1.0", path = "../rspack_util" } rspack_tracing = { version = "0.1.0", path = "../rspack_tracing" } -async-trait = { workspace = true } -cow-utils = { workspace = true } -tracing = { workspace = true } +async-trait = { workspace = true } +cow-utils = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } napi = { workspace = true } napi-derive = { workspace = true } diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 79455c23db6..e7a28ed7d14 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -676,6 +676,7 @@ export interface JsLoaderContext { loaderIndex: number loaderState: Readonly __internal__error?: JsRspackError + __internal__tracingCarrier?: Record } export interface JsLoaderItem { @@ -1971,7 +1972,7 @@ export interface RawTrustedTypes { * Author Donny/강동윤 * Copyright (c) */ -export declare function registerGlobalTrace(filter: string, layer: "chrome" | "logger"| "console", output: string): void +export declare function registerGlobalTrace(filter: string, layer: "chrome" | "logger"| "console" | "otel", output: string): void export declare enum RegisterJsTapKind { CompilerThisCompilation = 0, diff --git a/crates/node_binding/src/lib.rs b/crates/node_binding/src/lib.rs index 6cc3aec145c..f448822a11c 100644 --- a/crates/node_binding/src/lib.rs +++ b/crates/node_binding/src/lib.rs @@ -5,8 +5,8 @@ extern crate napi_derive; extern crate rspack_allocator; -use std::pin::Pin; use std::sync::Mutex; +use std::{pin::Pin, str::FromStr as _}; use compiler::{Compiler, CompilerState, CompilerStateGuard}; use napi::bindgen_prelude::*; @@ -14,6 +14,7 @@ use rspack_binding_options::BuiltinPlugin; use rspack_core::{Compilation, PluginExt}; use rspack_error::Diagnostic; use rspack_fs_node::{AsyncNodeWritableFileSystem, ThreadsafeNodeFS}; +use rspack_napi::napi::bindgen_prelude::within_runtime_if_available; mod compiler; mod diagnostic; @@ -26,7 +27,10 @@ use plugins::*; use resolver_factory::*; use rspack_binding_options::*; use rspack_binding_values::*; -use rspack_tracing::chrome::FlushGuard; +use rspack_tracing::{ChromeTracer, OtelTracer, StdoutTracer, TokioConsoleTracer, Tracer}; +use tracing::Level; +use tracing_subscriber::EnvFilter; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt as _, Layer, Registry}; #[napi] pub struct Rspack { @@ -196,7 +200,7 @@ fn concurrent_compiler_error() -> Error { #[derive(Default)] enum TraceState { - On(Option), + On(Box), #[default] Off, } @@ -212,7 +216,9 @@ fn print_error_diagnostic(e: rspack_error::Error, colored: bool) -> String { .expect("should print diagnostics") } -static GLOBAL_TRACE_STATE: Mutex = Mutex::new(TraceState::Off); +thread_local! { + static GLOBAL_TRACE_STATE: Mutex = const { Mutex::new(TraceState::Off) }; +} /** * Some code is modified based on @@ -224,41 +230,61 @@ static GLOBAL_TRACE_STATE: Mutex = Mutex::new(TraceState::Off); #[napi] pub fn register_global_trace( filter: String, - #[napi(ts_arg_type = "\"chrome\" | \"logger\"| \"console\"")] layer: String, + #[napi(ts_arg_type = "\"chrome\" | \"logger\"| \"console\" | \"otel\"")] layer: String, output: String, -) { - let mut state = GLOBAL_TRACE_STATE - .lock() - .expect("Failed to lock GLOBAL_TRACE_STATE"); - if matches!(&*state, TraceState::Off) { - let guard = match layer.as_str() { - "chrome" => rspack_tracing::enable_tracing_by_env_with_chrome_layer(&filter, &output), - "console" => { - rspack_tracing::enable_tracing_by_env_with_tokio_console(); - None - } - "logger" => { - rspack_tracing::enable_tracing_by_env(&filter, &output); - None +) -> anyhow::Result<()> { + GLOBAL_TRACE_STATE.with(|state| { + let mut state = state.lock().expect("Failed to lock GLOBAL_TRACE_STATE"); + if let TraceState::Off = *state { + let mut tracer: Box = match layer.as_str() { + "chrome" => Box::new(ChromeTracer::default()), + "otel" => Box::new(within_runtime_if_available(OtelTracer::default)), + "console" => Box::new(TokioConsoleTracer), + "logger" => Box::new(StdoutTracer), + _ => anyhow::bail!( + "Unexpected layer: {}, supported layers: 'chrome', 'logger', 'console' and 'otel' ", + layer + ), + }; + if let Some(layer) = tracer.setup(&output) { + if let Ok(default_level) = Level::from_str(&filter) { + let filter = tracing_subscriber::filter::Targets::new() + .with_target("rspack_core", default_level) + .with_target("node_binding", default_level) + .with_target("rspack_loader_swc", default_level) + .with_target("rspack_loader_runner", default_level) + .with_target("rspack_plugin_javascript", default_level) + .with_target("rspack_resolver", Level::WARN); + tracing_subscriber::registry() + .with(<_ as Layer>::with_filter(layer, filter)) + .init(); + } else { + // SAFETY: we know that trace_var is `Ok(String)` now, + // for the second unwrap, if we can't parse the directive, then the tracing result would be + // unexpected, then panic is reasonable + let filter = EnvFilter::builder() + .with_regex(true) + .parse(filter) + .expect("Parse tracing directive syntax failed, for details about the directive syntax you could refer https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives"); + tracing_subscriber::registry() + .with(<_ as Layer>::with_filter(layer, filter)) + .init(); + } } - _ => panic!("not supported layer type:{layer}"), - }; - let new_state = TraceState::On(guard); - *state = new_state; - } + let new_state = TraceState::On(tracer); + *state = new_state; + } + Ok(()) + }) } #[napi] pub fn cleanup_global_trace() { - let mut state = GLOBAL_TRACE_STATE - .lock() - .expect("Failed to lock GLOBAL_TRACE_STATE"); - if let TraceState::On(guard) = &mut *state - && let Some(g) = guard.take() - { - g.flush(); - drop(g); - let new_state = TraceState::Off; - *state = new_state; - } + GLOBAL_TRACE_STATE.with(|state| { + let mut state = state.lock().expect("Failed to lock GLOBAL_TRACE_STATE"); + if let TraceState::On(ref mut tracer) = *state { + tracer.teardown(); + } + *state = TraceState::Off; + }); } diff --git a/crates/node_binding/src/plugins/mod.rs b/crates/node_binding/src/plugins/mod.rs index 3d5a5b9a18f..9c32dd7b8b5 100644 --- a/crates/node_binding/src/plugins/mod.rs +++ b/crates/node_binding/src/plugins/mod.rs @@ -80,7 +80,7 @@ impl rspack_core::Plugin for JsHooksAdapterPlugin { "rspack.JsHooksAdapterPlugin" } - #[tracing::instrument(name = "js_hooks_adapter::apply", skip_all)] + // #[tracing::instrument("js_hooks_adapter::apply", skip_all)] fn apply( &self, ctx: PluginContext<&mut ApplyContext>, diff --git a/crates/rspack_binding_options/Cargo.toml b/crates/rspack_binding_options/Cargo.toml index d69492e6ad0..3b8d3643f64 100644 --- a/crates/rspack_binding_options/Cargo.toml +++ b/crates/rspack_binding_options/Cargo.toml @@ -74,6 +74,7 @@ rspack_plugin_wasm = { version = "0.1.0", path = "../rspack_ rspack_plugin_web_worker_template = { version = "0.1.0", path = "../rspack_plugin_web_worker_template" } rspack_plugin_worker = { version = "0.1.0", path = "../rspack_plugin_worker" } rspack_regex = { version = "0.1.0", path = "../rspack_regex" } +rspack_tracing = { version = "0.1.0", path = "../rspack_tracing" } rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } diff --git a/crates/rspack_binding_options/src/plugins/js_loader/context.rs b/crates/rspack_binding_options/src/plugins/js_loader/context.rs index 83da01720f6..ee51e63f7bd 100644 --- a/crates/rspack_binding_options/src/plugins/js_loader/context.rs +++ b/crates/rspack_binding_options/src/plugins/js_loader/context.rs @@ -7,6 +7,8 @@ use rspack_core::{LoaderContext, RunnerContext}; use rspack_error::error; use rspack_loader_runner::{LoaderItem, State as LoaderState}; use rspack_napi::threadsafe_js_value_ref::ThreadsafeJsValueRef; +use rspack_tracing::otel::{opentelemetry::global, tracing::OpenTelemetrySpanExt as _}; +use tracing::Span; #[napi(object)] pub struct JsLoaderItem { @@ -83,6 +85,9 @@ pub struct JsLoaderContext { pub loader_state: JsLoaderState, #[napi(js_name = "__internal__error")] pub error: Option, + + #[napi(js_name = "__internal__tracingCarrier")] + pub carrier: Option>, } impl TryFrom<&mut LoaderContext> for JsLoaderContext { @@ -93,6 +98,11 @@ impl TryFrom<&mut LoaderContext> for JsLoaderContext { ) -> std::result::Result { let module = unsafe { cx.context.module.as_ref() }; + let mut carrier = HashMap::new(); + global::get_text_map_propagator(|propagator| { + let cx = Span::current().context(); + propagator.inject_context(&cx, &mut carrier); + }); Ok(JsLoaderContext { resource_data: cx.resource_data.as_ref().into(), module_identifier: module.identifier().to_string(), @@ -140,6 +150,7 @@ impl TryFrom<&mut LoaderContext> for JsLoaderContext { loader_index: cx.loader_index, loader_state: cx.state().into(), error: None, + carrier: Some(carrier), }) } } diff --git a/crates/rspack_core/src/build_chunk_graph/code_splitter.rs b/crates/rspack_core/src/build_chunk_graph/code_splitter.rs index 7d2a004777d..a47be306ad4 100644 --- a/crates/rspack_core/src/build_chunk_graph/code_splitter.rs +++ b/crates/rspack_core/src/build_chunk_graph/code_splitter.rs @@ -745,7 +745,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on Ok(()) } - #[tracing::instrument(skip_all)] + // #[tracing::instrument(skip_all)] pub fn split(&mut self, compilation: &mut Compilation) -> Result<()> { let logger = compilation.get_logger("rspack.buildChunkGraph"); diff --git a/crates/rspack_core/src/build_chunk_graph/mod.rs b/crates/rspack_core/src/build_chunk_graph/mod.rs index ad4a2d23681..8850a5e10a2 100644 --- a/crates/rspack_core/src/build_chunk_graph/mod.rs +++ b/crates/rspack_core/src/build_chunk_graph/mod.rs @@ -8,7 +8,7 @@ use crate::{incremental::IncrementalPasses, Compilation}; pub(crate) mod code_splitter; pub(crate) mod incremental; -#[instrument(skip_all)] +#[instrument("Compilation:build_chunk_graph", skip_all)] pub(crate) fn build_chunk_graph(compilation: &mut Compilation) -> rspack_error::Result<()> { let enable_incremental = compilation .incremental diff --git a/crates/rspack_core/src/chunk_graph/chunk_graph_module.rs b/crates/rspack_core/src/chunk_graph/chunk_graph_module.rs index 269c048a44c..08f55c7581d 100644 --- a/crates/rspack_core/src/chunk_graph/chunk_graph_module.rs +++ b/crates/rspack_core/src/chunk_graph/chunk_graph_module.rs @@ -196,7 +196,7 @@ impl ChunkGraph { .set_hashes(module_identifier, hashes); } - #[instrument(name = "chunk_graph:get_module_graph_hash", skip_all, fields(module = ?module.identifier()))] + #[instrument("chunk_graph:get_module_graph_hash", skip_all, fields(module = ?module.identifier()))] pub fn get_module_graph_hash( &self, module: &dyn Module, diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index 41f4540b6b0..c1c65971117 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -21,7 +21,7 @@ use rspack_hook::define_hook; use rspack_sources::{BoxSource, CachedSource, SourceExt}; use rspack_util::itoa; use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet, FxHasher}; -use tracing::instrument; +use tracing::{info_span, instrument, Instrument}; use super::{ hmr::CompilationRecords, @@ -739,7 +739,7 @@ impl Compilation { ukey } - #[instrument(name = "compilation:make", skip_all)] + #[instrument("Compilation:make", skip_all)] pub async fn make(&mut self) -> Result<()> { self.make_artifact.reset_dependencies_incremental_info(); // self.module_executor. @@ -775,7 +775,7 @@ impl Compilation { .collect::>())) } - #[instrument(name = "compilation:code_generation", skip_all)] + #[instrument("Compilation:code_generation", skip_all)] fn code_generation(&mut self, modules: IdentifierSet) -> Result<()> { let logger = self.get_logger("rspack.Compilation"); let mut codegen_cache_counter = match self.options.cache { @@ -913,7 +913,7 @@ impl Compilation { Ok(()) } - #[instrument(name = "compilation::create_module_assets", skip_all)] + #[instrument("Compilation:create_module_assets", skip_all)] async fn create_module_assets(&mut self, _plugin_driver: SharedPluginDriver) { let mut temp = vec![]; for (module_identifier, assets) in self.module_assets.iter() { @@ -941,7 +941,7 @@ impl Compilation { } } - #[instrument(skip_all)] + #[instrument("Compilation::create_chunk_assets", skip_all)] async fn create_chunk_assets(&mut self, plugin_driver: SharedPluginDriver) -> Result<()> { let results = self .chunk_by_ukey @@ -997,7 +997,16 @@ impl Compilation { Ok(()) } - #[instrument(name = "compilation:after_process_asssets", skip_all)] + #[instrument("Compilation:process_assets", skip_all)] + async fn process_assets(&mut self, plugin_driver: SharedPluginDriver) -> Result<()> { + plugin_driver + .compilation_hooks + .process_assets + .call(self) + .await + } + + #[instrument("Compilation:after_process_asssets", skip_all)] async fn after_process_assets(&mut self, plugin_driver: SharedPluginDriver) -> Result<()> { plugin_driver .compilation_hooks @@ -1006,15 +1015,15 @@ impl Compilation { .await } - #[instrument(name = "compilation:after_seal", skip_all)] + #[instrument("Compilation:after_seal", skip_all)] async fn after_seal(&mut self, plugin_driver: SharedPluginDriver) -> Result<()> { plugin_driver.compilation_hooks.after_seal.call(self).await } - #[instrument( - name = "compilation:chunk_asset", - skip(self, plugin_driver, chunk_ukey) - )] + // #[instrument( + // name = "Compilation:chunk_asset", + // skip(self, plugin_driver, chunk_ukey) + // )] async fn chunk_asset( &self, chunk_ukey: ChunkUkey, @@ -1051,7 +1060,7 @@ impl Compilation { self.chunk_group_by_ukey.expect_get(ukey) } - #[instrument(name = "compilation:finish", skip_all)] + #[instrument("Compilation:finish", skip_all)] pub async fn finish(&mut self, plugin_driver: SharedPluginDriver) -> Result<()> { let logger = self.get_logger("rspack.Compilation"); @@ -1116,7 +1125,7 @@ impl Compilation { Ok(()) } - #[tracing::instrument(skip_all)] + // #[tracing::instrument(skip_all)] fn collect_dependencies_diagnostics(&mut self) { let mutations = self .incremental @@ -1161,7 +1170,7 @@ impl Compilation { self.extend_diagnostics(all_modules_diagnostics.into_values().flatten()); } - #[instrument(name = "compilation:seal", skip_all)] + #[instrument("Compilation:seal", skip_all)] pub async fn seal(&mut self, plugin_driver: SharedPluginDriver) -> Result<()> { self.other_module_graph = Some(ModuleGraphPartial::default()); let logger = self.get_logger("rspack.Compilation"); @@ -1192,6 +1201,7 @@ impl Compilation { .compilation_hooks .optimize_modules .call(self) + .instrument(info_span!("Compilation:optimize_modules")) .await?, Some(true) ) {} @@ -1199,12 +1209,12 @@ impl Compilation { .compilation_hooks .after_optimize_modules .call(self) + .instrument(info_span!("Compilation:after_optimize_modules")) .await?; while matches!( plugin_driver.compilation_hooks.optimize_chunks.call(self)?, Some(true) ) {} - logger.time_end(start); let start = logger.time("optimize"); @@ -1212,22 +1222,25 @@ impl Compilation { .compilation_hooks .optimize_tree .call(self) + .instrument(info_span!("Compilation:optimize_tree")) .await?; plugin_driver .compilation_hooks .optimize_chunk_modules .call(self) + .instrument(info_span!("Compilation:optimize_chunk_modules")) .await?; logger.time_end(start); let start = logger.time("module ids"); - plugin_driver.compilation_hooks.module_ids.call(self)?; + tracing::info_span!("Compilation:module_ids") + .in_scope(|| plugin_driver.compilation_hooks.module_ids.call(self))?; logger.time_end(start); let start = logger.time("chunk ids"); - plugin_driver.compilation_hooks.chunk_ids.call(self)?; - + tracing::info_span!("Compilation:chunk_ids") + .in_scope(|| plugin_driver.compilation_hooks.chunk_ids.call(self))?; logger.time_end(start); self.assign_runtime_ids(); @@ -1250,10 +1263,12 @@ impl Compilation { self.create_module_hashes(create_module_hashes_modules)?; let start = logger.time("optimize code generation"); - plugin_driver - .compilation_hooks - .optimize_code_generation - .call(self)?; + tracing::info_span!("Compilation::optimize_code_generation").in_scope(|| { + plugin_driver + .compilation_hooks + .optimize_code_generation + .call(self) + })?; logger.time_end(start); let start = logger.time("code generation"); @@ -1359,11 +1374,7 @@ impl Compilation { logger.time_end(start); let start = logger.time("process assets"); - plugin_driver - .compilation_hooks - .process_assets - .call(self) - .await?; + self.process_assets(plugin_driver.clone()).await?; logger.time_end(start); let start = logger.time("after process assets"); @@ -1430,7 +1441,7 @@ impl Compilation { entries.chain(async_entries).collect() } - #[instrument(skip_all)] + #[instrument("Compilation:process_modules_runtime_requirements", skip_all)] pub async fn process_modules_runtime_requirements( &mut self, modules: IdentifierSet, @@ -1484,7 +1495,7 @@ impl Compilation { Ok(()) } - #[instrument(skip_all)] + #[instrument(name = "Compilation:process_chunks_runtime_requirements", skip_all)] pub async fn process_chunks_runtime_requirements( &mut self, chunks: UkeySet, @@ -1520,7 +1531,7 @@ impl Compilation { Ok(()) } - #[instrument(skip_all)] + #[instrument(name = "Compilation:process_entries_runtime_requirements", skip_all)] pub async fn process_entries_runtime_requirements( &mut self, chunk_graph_entries: impl Iterator, @@ -1589,7 +1600,7 @@ impl Compilation { Ok(()) } - #[instrument(name = "compilation:create_hash", skip_all)] + #[instrument(name = "Compilation:create_hash", skip_all)] pub async fn create_hash( &mut self, create_hash_chunks: UkeySet, @@ -1876,7 +1887,7 @@ impl Compilation { Ok((chunk_hash, content_hashes)) } - #[instrument(name = "compilation:create_module_hashes", skip_all)] + #[instrument("Compilation:create_module_hashes", skip_all)] pub fn create_module_hashes(&mut self, modules: IdentifierSet) -> Result<()> { let results: Vec<(ModuleIdentifier, RuntimeSpecMap)> = modules .into_par_iter() diff --git a/crates/rspack_core/src/compiler/hmr.rs b/crates/rspack_core/src/compiler/hmr.rs index f044f4f88a9..d5db87c44e4 100644 --- a/crates/rspack_core/src/compiler/hmr.rs +++ b/crates/rspack_core/src/compiler/hmr.rs @@ -13,6 +13,10 @@ use crate::{ }; impl Compiler { + #[tracing::instrument("Compiler:rebuild", skip_all, fields( + compiler.changed_files = ?changed_files.iter().cloned().collect::>(), + compiler.deleted_files = ?deleted_files.iter().cloned().collect::>() + ))] pub async fn rebuild( &mut self, changed_files: std::collections::HashSet, diff --git a/crates/rspack_core/src/compiler/make/repair/build.rs b/crates/rspack_core/src/compiler/make/repair/build.rs index d0ce745daf5..f38bf504e32 100644 --- a/crates/rspack_core/src/compiler/make/repair/build.rs +++ b/crates/rspack_core/src/compiler/make/repair/build.rs @@ -26,6 +26,7 @@ impl Task for BuildTask { fn get_task_type(&self) -> TaskType { TaskType::Async } + async fn async_run(self: Box) -> TaskResult { let Self { compilation_id, diff --git a/crates/rspack_core/src/compiler/mod.rs b/crates/rspack_core/src/compiler/mod.rs index 074e0f72e8d..60457a28aa1 100644 --- a/crates/rspack_core/src/compiler/mod.rs +++ b/crates/rspack_core/src/compiler/mod.rs @@ -66,7 +66,6 @@ pub struct Compiler { } impl Compiler { - #[instrument(skip_all)] pub fn new( options: CompilerOptions, plugins: Vec, @@ -138,7 +137,7 @@ impl Compiler { Ok(()) } - #[instrument(name = "build", skip_all)] + #[instrument("Compiler:build", skip_all)] pub async fn build(&mut self) -> Result<()> { self.old_cache.end_idle(); // TODO: clear the outdated cache entries in resolver, @@ -169,7 +168,7 @@ impl Compiler { Ok(()) } - #[instrument(name = "compile", skip_all)] + #[instrument("Compiler:compile", skip_all)] async fn compile(&mut self) -> Result<()> { let mut compilation_params = self.new_compilation_params(); // FOR BINDING SAFETY: @@ -232,7 +231,7 @@ impl Compiler { Ok(()) } - #[instrument(name = "compile_done", skip_all)] + #[instrument("Compile:done", skip_all)] async fn compile_done(&mut self) -> Result<()> { let logger = self.compilation.get_logger("rspack.Compiler"); @@ -255,7 +254,7 @@ impl Compiler { Ok(()) } - #[instrument(name = "emit_assets", skip_all)] + #[instrument("emit_assets", skip_all)] pub async fn emit_assets(&mut self) -> Result<()> { if self.options.output.clean { if self.emitted_asset_versions.is_empty() { diff --git a/crates/rspack_core/src/concatenated_module.rs b/crates/rspack_core/src/concatenated_module.rs index 1485baf0098..a8605f3ec0c 100644 --- a/crates/rspack_core/src/concatenated_module.rs +++ b/crates/rspack_core/src/concatenated_module.rs @@ -606,7 +606,7 @@ impl Module for ConcatenatedModule { Ok(BuildResult::default()) } - #[tracing::instrument(name = "ConcatenatedModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("ConcatenatedModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, compilation: &Compilation, diff --git a/crates/rspack_core/src/context_module.rs b/crates/rspack_core/src/context_module.rs index aeb8f4a4d7f..d54be65f9e4 100644 --- a/crates/rspack_core/src/context_module.rs +++ b/crates/rspack_core/src/context_module.rs @@ -980,7 +980,7 @@ impl Module for ContextModule { }) } - #[tracing::instrument(name = "ContextModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("ContextModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, compilation: &Compilation, diff --git a/crates/rspack_core/src/context_module_factory.rs b/crates/rspack_core/src/context_module_factory.rs index f2e2ae777cf..77e14767fee 100644 --- a/crates/rspack_core/src/context_module_factory.rs +++ b/crates/rspack_core/src/context_module_factory.rs @@ -96,7 +96,7 @@ pub struct ContextModuleFactory { #[async_trait::async_trait] impl ModuleFactory for ContextModuleFactory { - #[instrument(name = "context_module_factory:create", skip_all)] + #[instrument("context_module_factory:create", skip_all)] async fn create(&self, data: &mut ModuleFactoryCreateData) -> Result { match self.before_resolve(data).await? { BeforeResolveResult::Ignored => return Ok(ModuleFactoryResult::default()), diff --git a/crates/rspack_core/src/external_module.rs b/crates/rspack_core/src/external_module.rs index 1b6283a4168..47c78c2880a 100644 --- a/crates/rspack_core/src/external_module.rs +++ b/crates/rspack_core/src/external_module.rs @@ -517,7 +517,7 @@ impl Module for ExternalModule { Ok(build_result) } - #[tracing::instrument(name = "ExternalModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("ExternalModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, compilation: &Compilation, diff --git a/crates/rspack_core/src/module_graph/mod.rs b/crates/rspack_core/src/module_graph/mod.rs index f435426c83a..114fb486aaf 100644 --- a/crates/rspack_core/src/module_graph/mod.rs +++ b/crates/rspack_core/src/module_graph/mod.rs @@ -184,7 +184,7 @@ impl<'a> ModuleGraph<'a> { res } - #[tracing::instrument(skip_all, fields(module = ?module_id))] + // #[tracing::instrument(skip_all, fields(module = ?module_id))] pub fn get_incoming_connections_by_origin_module( &self, module_id: &ModuleIdentifier, diff --git a/crates/rspack_core/src/normal_module.rs b/crates/rspack_core/src/normal_module.rs index 9c226d861d7..90c7b4bce45 100644 --- a/crates/rspack_core/src/normal_module.rs +++ b/crates/rspack_core/src/normal_module.rs @@ -304,6 +304,7 @@ impl NormalModule { &mut self.presentational_dependencies } + #[tracing::instrument("NormalModule:build_hash")] fn init_build_hash( &self, output_options: &OutputOptions, @@ -390,6 +391,11 @@ impl Module for NormalModule { } } + #[tracing::instrument("NormalModule:build", skip_all, fields( + module.resource = self.resource_resolved_data().resource.as_str(), + module.identifier = self.identifier().as_str(), + module.loaders = ?self.loaders.iter().map(|l| l.identifier().as_str()).collect::>()) + )] async fn build( &mut self, build_context: BuildContext, @@ -590,7 +596,7 @@ impl Module for NormalModule { }) } - #[tracing::instrument(name = "NormalModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("NormalModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, compilation: &Compilation, diff --git a/crates/rspack_core/src/normal_module_factory.rs b/crates/rspack_core/src/normal_module_factory.rs index 2859d227df5..7d13b3ad7f9 100644 --- a/crates/rspack_core/src/normal_module_factory.rs +++ b/crates/rspack_core/src/normal_module_factory.rs @@ -509,7 +509,6 @@ impl NormalModuleFactory { } else { resource_data.resource.clone() }; - tracing::trace!("resolved uri {:?}", request); let file_dependency = resource_data.resource_path.clone(); diff --git a/crates/rspack_core/src/old_cache/occasion/code_generate.rs b/crates/rspack_core/src/old_cache/occasion/code_generate.rs index a29751506ef..f8f1225180c 100644 --- a/crates/rspack_core/src/old_cache/occasion/code_generate.rs +++ b/crates/rspack_core/src/old_cache/occasion/code_generate.rs @@ -16,7 +16,7 @@ impl CodeGenerateOccasion { Self { storage } } - #[tracing::instrument(skip_all, fields(module = ?job.module))] + // #[tracing::instrument(skip_all, fields(module = ?job.module))] pub fn use_cache( &self, job: CodeGenerationJob, diff --git a/crates/rspack_core/src/old_cache/occasion/process_runtime_requirements.rs b/crates/rspack_core/src/old_cache/occasion/process_runtime_requirements.rs index b8f2a401709..1d9a71f7c15 100644 --- a/crates/rspack_core/src/old_cache/occasion/process_runtime_requirements.rs +++ b/crates/rspack_core/src/old_cache/occasion/process_runtime_requirements.rs @@ -18,7 +18,7 @@ impl ProcessRuntimeRequirementsOccasion { Self { storage } } - #[tracing::instrument(skip_all, fields(module = ?module))] + // #[tracing::instrument(skip_all, fields(module = ?module))] pub fn use_cache( &self, module: ModuleIdentifier, diff --git a/crates/rspack_core/src/raw_module.rs b/crates/rspack_core/src/raw_module.rs index 90980bed815..8ce5dfa7fb5 100644 --- a/crates/rspack_core/src/raw_module.rs +++ b/crates/rspack_core/src/raw_module.rs @@ -124,7 +124,7 @@ impl Module for RawModule { }) } - #[tracing::instrument(name = "RawModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("RawModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, _compilation: &crate::Compilation, diff --git a/crates/rspack_core/src/resolver/mod.rs b/crates/rspack_core/src/resolver/mod.rs index 0c0ac472732..7ca761366ba 100644 --- a/crates/rspack_core/src/resolver/mod.rs +++ b/crates/rspack_core/src/resolver/mod.rs @@ -279,6 +279,15 @@ if its extension was not listed in the `resolve.extensions`. Here're some possib } /// Main entry point for module resolution. +// #[tracing::instrument(err, "resolve", skip_all, fields( +// resolve.specifier = args.specifier, +// resolve.importer = ?args.importer, +// resolve.context = ?args.context, +// resolve.dependency_type = ?args.dependency_type, +// resolve.dependency_category = ?args.dependency_category +// ), +// level = "trace" +// )] pub async fn resolve( args: ResolveArgs<'_>, plugin_driver: &SharedPluginDriver, @@ -295,6 +304,18 @@ pub async fn resolve( .resolve_with_context(args.context.as_ref(), args.specifier, &mut context) .map_err(|error| error.into_resolve_error(&args)); + if let Err(ref err) = result { + tracing::error!( + specifier = args.specifier, + importer = ?args.importer, + context = %args.context, + dependency_type = %args.dependency_type, + dependency_category = %args.dependency_category, + "Resolve error: {}", + err.to_string() + ); + } + args.file_dependencies.extend(context.file_dependencies); args .missing_dependencies diff --git a/crates/rspack_core/src/self_module.rs b/crates/rspack_core/src/self_module.rs index 189440c6b85..ee184dd0725 100644 --- a/crates/rspack_core/src/self_module.rs +++ b/crates/rspack_core/src/self_module.rs @@ -125,7 +125,7 @@ impl Module for SelfModule { }) } - #[tracing::instrument(name = "SelfModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("SelfModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, _compilation: &Compilation, diff --git a/crates/rspack_core/src/unaffected_cache/mod.rs b/crates/rspack_core/src/unaffected_cache/mod.rs new file mode 100644 index 00000000000..61ba2b28764 --- /dev/null +++ b/crates/rspack_core/src/unaffected_cache/mod.rs @@ -0,0 +1,370 @@ +mod mutations; + +use std::{ + hash::{BuildHasherDefault, Hash, Hasher}, + sync::Mutex, +}; + +pub use mutations::{Mutation, Mutations}; +use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; +use rspack_collections::{IdentifierDashMap, IdentifierHasher, IdentifierMap, IdentifierSet}; +use rspack_util::fx_hash::FxIndexSet; +use rustc_hash::FxHasher; + +use crate::{ + AffectType, ChunkGraph, Compilation, Module, ModuleGraph, ModuleGraphConnection, ModuleIdentifier, +}; + +#[derive(Debug, Default)] +pub struct UnaffectedModulesCache { + module_to_cache: IdentifierDashMap, + affected_modules_with_module_graph: Mutex, + affected_modules_with_chunk_graph: Mutex, +} + +#[derive(Debug)] +struct UnaffectedModuleCache { + module_graph_invalidate_key: u64, + with_chunk_graph_cache: Option, +} + +#[derive(Debug)] +struct UnaffectedModuleWithChunkGraphCache { + chunk_graph_invalidate_key: u64, +} + +impl UnaffectedModulesCache { + fn par_iter( + &self, + ) -> dashmap::rayon::map::Iter< + ModuleIdentifier, + UnaffectedModuleCache, + BuildHasherDefault, + > { + self.module_to_cache.par_iter() + } + + // #[tracing::instrument(skip_all, fields(module = ?key))] + fn remove_cache(&self, key: &ModuleIdentifier) { + self.module_to_cache.remove(key); + } + + // #[tracing::instrument(skip_all, fields(module = ?key))] + fn insert_cache(&self, key: ModuleIdentifier, value: UnaffectedModuleCache) { + self.module_to_cache.insert(key, value); + } + + // #[tracing::instrument(skip_all, fields(module = ?key))] + fn affect_cache(&self, key: &ModuleIdentifier) -> Option<()> { + let mut cache = self.module_to_cache.get_mut(key)?; + cache.with_chunk_graph_cache = None; + // remove other cache... + Some(()) + } + + // #[tracing::instrument(skip_all, fields(module = ?key))] + fn insert_chunk_graph_cache( + &self, + key: &ModuleIdentifier, + value: UnaffectedModuleWithChunkGraphCache, + ) -> Option<()> { + let mut cache = self.module_to_cache.get_mut(key)?; + cache.with_chunk_graph_cache = Some(value); + Some(()) + } + + // #[tracing::instrument(skip_all)] + pub fn compute_affected_modules_with_module_graph(&self, compilation: &Compilation) { + let mg = compilation.get_module_graph(); + let modules = mg.modules().keys().copied().collect(); + let mut affected_modules = self + .affected_modules_with_module_graph + .lock() + .expect("failed to lock"); + *affected_modules = compute_affected_modules_with_module_graph(compilation, modules); + } + + // #[tracing::instrument(skip_all)] + pub fn get_affected_modules_with_module_graph(&self) -> &Mutex { + &self.affected_modules_with_module_graph + } + + // #[tracing::instrument(skip_all)] + pub fn compute_affected_modules_with_chunk_graph(&self, compilation: &Compilation) { + let mut affected_modules = self + .affected_modules_with_chunk_graph + .lock() + .expect("failed to lock"); + *affected_modules = compute_affected_modules_with_chunk_graph(compilation); + } + + // #[tracing::instrument(skip_all)] + pub fn get_affected_modules_with_chunk_graph(&self) -> &Mutex { + &self.affected_modules_with_chunk_graph + } +} + +impl UnaffectedModuleCache { + fn new(module_graph_invalidate_key: u64) -> Self { + Self { + module_graph_invalidate_key, + with_chunk_graph_cache: None, + } + } + + // #[tracing::instrument(skip_all, fields(module = ?module.identifier()))] + fn create_module_graph_invalidate_key(module_graph: &ModuleGraph, module: &dyn Module) -> u64 { + let mut hasher = FxHasher::default(); + module + .build_info() + .expect("should have build_info after build") + .hash + .as_ref() + .hash(&mut hasher); + for dep_id in module_graph + .get_ordered_connections(&module.identifier()) + .expect("should have module") + { + dep_id.hash(&mut hasher); + } + hasher.finish() + } +} + +impl UnaffectedModuleWithChunkGraphCache { + // #[tracing::instrument(skip_all, fields(module = ?module.identifier()))] + fn create_chunk_graph_invalidate_key( + chunk_graph: &ChunkGraph, + module_graph: &ModuleGraph, + compilation: &Compilation, + module: &dyn Module, + ) -> u64 { + let module_identifier = module.identifier(); + let mut hasher = FxHasher::default(); + chunk_graph + .get_module_id(module_identifier) + .hash(&mut hasher); + let module_ids: FxIndexSet<_> = module_graph + .get_ordered_connections(&module_identifier) + .expect("should have module") + .into_iter() + .filter_map(|dep_id| { + let connection = module_graph + .connection_by_dependency_id(dep_id) + .expect("should have connection"); + chunk_graph.get_module_id(*connection.module_identifier()) + }) + .collect(); + for module_id in module_ids { + module_id.hash(&mut hasher); + } + for block_id in module.get_blocks() { + let Some(chunk_group) = + chunk_graph.get_block_chunk_group(block_id, &compilation.chunk_group_by_ukey) + else { + continue; + }; + for chunk in &chunk_group.chunks { + let chunk = compilation.chunk_by_ukey.expect_get(chunk); + chunk.id.as_ref().hash(&mut hasher); + } + } + hasher.finish() + } +} + +fn compute_affected_modules_with_module_graph( + compilation: &Compilation, + modules: IdentifierSet, +) -> IdentifierSet { + fn reduce_affect_type( + module_graph: &ModuleGraph, + connections: &[ModuleGraphConnection], + ) -> AffectType { + let mut affected = AffectType::False; + for connection in connections { + let Some(dependency) = module_graph.dependency_by_id(&connection.dependency_id) else { + continue; + }; + match dependency.could_affect_referencing_module() { + AffectType::True => affected = AffectType::True, + AffectType::False => continue, + AffectType::Transitive => return AffectType::Transitive, + } + } + affected + } + + enum ModulesCacheOp { + Delete(ModuleIdentifier), + Unaffected(ModuleIdentifier), + Affected(ModuleIdentifier, u64), + } + + let module_graph = compilation.get_module_graph(); + let modules_cache = compilation.unaffected_modules_cache.clone(); + let mut modules_without_cache = modules; + let results: Vec = modules_cache + .par_iter() + .map(|item| { + let (module_identifier, cache) = item.pair(); + if modules_without_cache.contains(module_identifier) { + let module = module_graph + .module_by_identifier(module_identifier) + .expect("should have module"); + let invalidate_key = + UnaffectedModuleCache::create_module_graph_invalidate_key(&module_graph, module.as_ref()); + if cache.module_graph_invalidate_key != invalidate_key { + ModulesCacheOp::Affected(*module_identifier, invalidate_key) + } else { + ModulesCacheOp::Unaffected(*module_identifier) + } + } else { + ModulesCacheOp::Delete(*module_identifier) + } + }) + .collect(); + let mut affected_modules_cache = IdentifierMap::default(); + for result in results { + match result { + ModulesCacheOp::Delete(m) => { + modules_cache.remove_cache(&m); + } + ModulesCacheOp::Unaffected(m) => { + modules_without_cache.remove(&m); + } + ModulesCacheOp::Affected(m, invalidate_key) => { + modules_without_cache.remove(&m); + affected_modules_cache.insert(m, invalidate_key); + } + } + } + let more_affected_modules: Vec<_> = modules_without_cache + .into_par_iter() + .map(|module_identifier| { + let module = module_graph + .module_by_identifier(&module_identifier) + .expect("should have module"); + let invalidate_key = + UnaffectedModuleCache::create_module_graph_invalidate_key(&module_graph, module.as_ref()); + (module_identifier, invalidate_key) + }) + .collect(); + affected_modules_cache.extend(more_affected_modules); + + enum AffectedModuleKind { + Direct(ModuleIdentifier), + Transitive(ModuleIdentifier), + } + let mut all_affected_modules: IdentifierSet = affected_modules_cache.keys().copied().collect(); + let affected_modules_cache_iter = + affected_modules_cache + .par_iter() + .flat_map(|(&module_identifier, &invalidate_key)| { + modules_cache.insert_cache( + module_identifier, + UnaffectedModuleCache::new(invalidate_key), + ); + module_graph + .get_incoming_connections_by_origin_module(&module_identifier) + .into_iter() + .filter_map(|(referencing_module, connections)| { + let referencing_module = referencing_module?; + if all_affected_modules.contains(&referencing_module) { + return None; + } + match reduce_affect_type(&module_graph, &connections) { + AffectType::False => None, + AffectType::True => { + modules_cache.affect_cache(&referencing_module); + Some(AffectedModuleKind::Direct(referencing_module)) + } + AffectType::Transitive => { + modules_cache.affect_cache(&referencing_module); + Some(AffectedModuleKind::Transitive(referencing_module)) + } + } + }) + .collect::>() + }); + let mut direct_affected_modules: IdentifierSet = affected_modules_cache_iter + .clone() + .filter_map(|k| match k { + AffectedModuleKind::Direct(m) => Some(m), + AffectedModuleKind::Transitive(_) => None, + }) + .collect(); + let mut transitive_affected_modules: IdentifierSet = affected_modules_cache_iter + .clone() + .filter_map(|k| match k { + AffectedModuleKind::Transitive(m) => Some(m), + AffectedModuleKind::Direct(_) => None, + }) + .collect(); + while !transitive_affected_modules.is_empty() { + let transitive_affected_modules_current = std::mem::take(&mut transitive_affected_modules); + all_affected_modules.extend(transitive_affected_modules_current.iter().copied()); + for &module_identifier in transitive_affected_modules_current.iter() { + for (referencing_module, connections) in + module_graph.get_incoming_connections_by_origin_module(&module_identifier) + { + let Some(referencing_module) = referencing_module else { + continue; + }; + if all_affected_modules.contains(&referencing_module) { + continue; + } + match reduce_affect_type(&module_graph, &connections) { + AffectType::False => continue, + AffectType::True => { + direct_affected_modules.insert(referencing_module); + } + AffectType::Transitive => { + transitive_affected_modules.insert(referencing_module); + } + }; + modules_cache.affect_cache(&referencing_module); + } + } + } + all_affected_modules.extend(direct_affected_modules); + all_affected_modules +} + +fn compute_affected_modules_with_chunk_graph(compilation: &Compilation) -> IdentifierSet { + let modules_cache = compilation.unaffected_modules_cache.clone(); + let module_graph = compilation.get_module_graph(); + let affected_modules: IdentifierMap = modules_cache + .par_iter() + .filter_map(|item| { + let (module_identifier, cache) = item.pair(); + let module = module_graph + .module_by_identifier(module_identifier) + .expect("should have module"); + let invalidate_key = UnaffectedModuleWithChunkGraphCache::create_chunk_graph_invalidate_key( + &compilation.chunk_graph, + &module_graph, + compilation, + module.as_ref(), + ); + if let Some(module_graph_cache) = &cache.with_chunk_graph_cache { + if module_graph_cache.chunk_graph_invalidate_key != invalidate_key { + Some((*module_identifier, invalidate_key)) + } else { + None + } + } else { + Some((*module_identifier, invalidate_key)) + } + }) + .collect(); + for (module_identifier, invalidate_key) in affected_modules.iter() { + modules_cache.insert_chunk_graph_cache( + module_identifier, + UnaffectedModuleWithChunkGraphCache { + chunk_graph_invalidate_key: *invalidate_key, + }, + ); + } + affected_modules.keys().copied().collect() +} diff --git a/crates/rspack_core/src/utils/task_loop.rs b/crates/rspack_core/src/utils/task_loop.rs index 5fc1ecfd091..b8a1eff7e8f 100644 --- a/crates/rspack_core/src/utils/task_loop.rs +++ b/crates/rspack_core/src/utils/task_loop.rs @@ -11,6 +11,7 @@ use std::{ use rspack_error::Result; use rspack_util::ext::AsAny; use tokio::sync::mpsc::{self, error::TryRecvError}; +use tracing::Instrument; /// Result returned by task /// @@ -83,12 +84,15 @@ pub async fn run_task_loop_with_event( let tx = tx.clone(); let is_expected_shutdown = is_expected_shutdown.clone(); active_task_count += 1; - tokio::spawn(async move { - let r = task.async_run().await; - if !is_expected_shutdown.load(Ordering::Relaxed) { - tx.send(r).expect("failed to send error message"); + tokio::spawn( + async move { + let r = task.async_run().await; + if !is_expected_shutdown.load(Ordering::Relaxed) { + tx.send(r).expect("failed to send error message"); + } } - }); + .in_current_span(), + ); } TaskType::Sync => { // merge sync task result directly diff --git a/crates/rspack_loader_runner/Cargo.toml b/crates/rspack_loader_runner/Cargo.toml index a9202e6f514..87c65740751 100644 --- a/crates/rspack_loader_runner/Cargo.toml +++ b/crates/rspack_loader_runner/Cargo.toml @@ -21,3 +21,4 @@ rspack_paths = { version = "0.1.0", path = "../rspack_paths" } rspack_sources = { workspace = true } rspack_util = { version = "0.1.0", path = "../rspack_util" } serde_json = { workspace = true } +tracing = { workspace = true } diff --git a/crates/rspack_loader_runner/src/runner.rs b/crates/rspack_loader_runner/src/runner.rs index edad776432d..90bb778a303 100644 --- a/crates/rspack_loader_runner/src/runner.rs +++ b/crates/rspack_loader_runner/src/runner.rs @@ -25,6 +25,11 @@ impl LoaderContext { } } +// #[tracing::instrument("LoaderRunner:process_resource", +// skip_all, +// fields(module.resource = loader_context.resource_data.resource), +// level = "trace" +// )] async fn process_resource( loader_context: &mut LoaderContext, fs: Arc, @@ -103,6 +108,7 @@ async fn create_loader_context( Ok(loader_context) } +#[tracing::instrument("LoaderRunner:run_loaders", skip_all, level = "trace")] pub async fn run_loaders( loaders: Vec>>, resource_data: Arc, diff --git a/crates/rspack_loader_swc/Cargo.toml b/crates/rspack_loader_swc/Cargo.toml index c4c29c76fc7..80c4103a06d 100644 --- a/crates/rspack_loader_swc/Cargo.toml +++ b/crates/rspack_loader_swc/Cargo.toml @@ -36,4 +36,5 @@ swc = { workspace = true, features = ["manual-tokio-runtmie swc_config = { workspace = true } swc_core = { workspace = true, features = ["base", "ecma_ast", "common"] } swc_plugin_import = { version = "0.1.5", path = "../swc_plugin_import" } +tracing = { workspace = true } url = "2.5.0" diff --git a/crates/rspack_loader_swc/src/lib.rs b/crates/rspack_loader_swc/src/lib.rs index 8b920b9644c..7ef0de45459 100644 --- a/crates/rspack_loader_swc/src/lib.rs +++ b/crates/rspack_loader_swc/src/lib.rs @@ -147,6 +147,7 @@ pub const SWC_LOADER_IDENTIFIER: &str = "builtin:swc-loader"; #[async_trait::async_trait] impl Loader for SwcLoader { + #[tracing::instrument("SwcLoader:run", skip_all)] async fn run(&self, loader_context: &mut LoaderContext) -> Result<()> { #[allow(unused_mut)] let mut inner = || self.loader_impl(loader_context); diff --git a/crates/rspack_macros/src/plugin.rs b/crates/rspack_macros/src/plugin.rs index 7aeeca3bb24..560c9260064 100644 --- a/crates/rspack_macros/src/plugin.rs +++ b/crates/rspack_macros/src/plugin.rs @@ -182,13 +182,13 @@ pub fn expand_fn(args: HookArgs, input: syn::ItemFn) -> proc_macro::TokenStream let inner_ident = plugin_inner_ident(&name); - let tracing_name = syn::LitStr::new(&format!("{}::{}", &name, &fn_ident), Span::call_site()); + let _tracing_name = syn::LitStr::new(&format!("{}::{}", &name, &fn_ident), Span::call_site()); let tracing_annotation = tracing .map(|bool_lit| bool_lit.value) .unwrap_or(true) .then(|| { quote! { - #[tracing::instrument(name = #tracing_name, skip_all)] + // #[tracing::instrument(name = #tracing_name, skip_all)] } }); diff --git a/crates/rspack_plugin_extract_css/src/css_module.rs b/crates/rspack_plugin_extract_css/src/css_module.rs index 884dcb651f9..bd3e61b0fdb 100644 --- a/crates/rspack_plugin_extract_css/src/css_module.rs +++ b/crates/rspack_plugin_extract_css/src/css_module.rs @@ -185,7 +185,7 @@ impl Module for CssModule { }) } - #[tracing::instrument(name = "ExtractCssModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("ExtractCssModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, _compilation: &Compilation, diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/esm_export_imported_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/esm_export_imported_specifier_dependency.rs index 1bb0b0eeb2c..5e7eb2712f4 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/esm_export_imported_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/esm_export_imported_specifier_dependency.rs @@ -1230,7 +1230,7 @@ impl Dependency for ESMExportImportedSpecifierDependency { Some(self.source_order) } - #[tracing::instrument(skip_all)] + // #[tracing::instrument(skip_all)] fn get_diagnostics(&self, module_graph: &ModuleGraph) -> Option> { let module = module_graph.get_parent_module(&self.id)?; let module = module_graph.module_by_identifier(module)?; diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/esm_import_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/esm_import_specifier_dependency.rs index e881f538508..367a9672d48 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/esm_import_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/esm_import_specifier_dependency.rs @@ -270,7 +270,7 @@ impl Dependency for ESMImportSpecifierDependency { Some(&self.resource_identifier) } - #[tracing::instrument(skip_all)] + // #[tracing::instrument(skip_all)] fn get_diagnostics(&self, module_graph: &ModuleGraph) -> Option> { let module = module_graph.get_parent_module(&self.id)?; let module = module_graph.module_by_identifier(module)?; diff --git a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs index 34f3f495945..7f8ea5f1366 100644 --- a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs @@ -93,6 +93,7 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator { module.original_source().map_or(0, |source| source.size()) as f64 } + #[tracing::instrument("JavaScriptParser:parse", skip_all)] fn parse(&mut self, parse_context: ParseContext) -> Result> { let ParseContext { source, diff --git a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs index fefa76003ed..2ab4b40c947 100644 --- a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs @@ -94,7 +94,7 @@ impl<'a> FlagDependencyExportsState<'a> { } } - #[tracing::instrument(skip_all, fields(module = ?self.current_module_id))] + // #[tracing::instrument(skip_all, fields(module = ?self.current_module_id))] pub fn notify_dependencies(&mut self, q: &mut Queue) { if let Some(set) = self.dependencies.get(&self.current_module_id) { for mi in set.iter() { diff --git a/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs index 3a1b299b018..378950e19ea 100644 --- a/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs @@ -702,7 +702,7 @@ impl Plugin for SideEffectsFlagPlugin { } } -#[tracing::instrument(skip_all, fields(module = ?module_identifier))] +// #[tracing::instrument(skip_all, fields(module = ?module_identifier))] fn optimize_incoming_connections( module_identifier: ModuleIdentifier, to_be_optimized: &mut IdentifierSet, @@ -808,7 +808,7 @@ fn optimize_incoming_connection( ); } -#[tracing::instrument(skip_all, fields(origin = ?origin_module, module = ?module_identifier))] +// #[tracing::instrument(skip_all, fields(origin = ?origin_module, module = ?module_identifier))] fn do_optimize_incoming_connection( dependency_id: DependencyId, module_identifier: ModuleIdentifier, diff --git a/crates/rspack_plugin_lazy_compilation/src/module.rs b/crates/rspack_plugin_lazy_compilation/src/module.rs index 8f08c8a97dc..b31770c3df9 100644 --- a/crates/rspack_plugin_lazy_compilation/src/module.rs +++ b/crates/rspack_plugin_lazy_compilation/src/module.rs @@ -173,7 +173,7 @@ impl Module for LazyCompilationProxyModule { }) } - #[tracing::instrument(name = "LazyCompilationProxyModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("LazyCompilationProxyModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, compilation: &Compilation, diff --git a/crates/rspack_plugin_mf/src/container/container_entry_module.rs b/crates/rspack_plugin_mf/src/container/container_entry_module.rs index 247856db715..d3e49506086 100644 --- a/crates/rspack_plugin_mf/src/container/container_entry_module.rs +++ b/crates/rspack_plugin_mf/src/container/container_entry_module.rs @@ -173,7 +173,7 @@ impl Module for ContainerEntryModule { }) } - #[tracing::instrument(name = "ContainerEntryModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("ContainerEntryModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, compilation: &Compilation, diff --git a/crates/rspack_plugin_mf/src/container/fallback_module.rs b/crates/rspack_plugin_mf/src/container/fallback_module.rs index ef88c88c79e..5973a0a976c 100644 --- a/crates/rspack_plugin_mf/src/container/fallback_module.rs +++ b/crates/rspack_plugin_mf/src/container/fallback_module.rs @@ -143,7 +143,7 @@ impl Module for FallbackModule { }) } - #[tracing::instrument(name = "FallbackModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("FallbackModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, compilation: &Compilation, diff --git a/crates/rspack_plugin_mf/src/container/remote_module.rs b/crates/rspack_plugin_mf/src/container/remote_module.rs index 44f3053b018..a2163c6ac96 100644 --- a/crates/rspack_plugin_mf/src/container/remote_module.rs +++ b/crates/rspack_plugin_mf/src/container/remote_module.rs @@ -164,7 +164,7 @@ impl Module for RemoteModule { }) } - #[tracing::instrument(name = "RemoteModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("RemoteModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, compilation: &Compilation, diff --git a/crates/rspack_plugin_mf/src/sharing/consume_shared_module.rs b/crates/rspack_plugin_mf/src/sharing/consume_shared_module.rs index ca1e489fd6d..f139492089b 100644 --- a/crates/rspack_plugin_mf/src/sharing/consume_shared_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/consume_shared_module.rs @@ -173,7 +173,7 @@ impl Module for ConsumeSharedModule { }) } - #[tracing::instrument(name = "ConsumeSharedModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("ConsumeSharedModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, compilation: &Compilation, diff --git a/crates/rspack_plugin_mf/src/sharing/provide_shared_module.rs b/crates/rspack_plugin_mf/src/sharing/provide_shared_module.rs index 17ef1318b29..fb2a312b353 100644 --- a/crates/rspack_plugin_mf/src/sharing/provide_shared_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/provide_shared_module.rs @@ -168,7 +168,7 @@ impl Module for ProvideSharedModule { }) } - #[tracing::instrument(name = "ProvideSharedModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] + // #[tracing::instrument("ProvideSharedModule::code_generation", skip_all, fields(identifier = ?self.identifier()))] fn code_generation( &self, compilation: &Compilation, diff --git a/crates/rspack_plugin_split_chunks/src/plugin/chunk.rs b/crates/rspack_plugin_split_chunks/src/plugin/chunk.rs index 0bbdc0b6cf9..a5b6c1eb660 100644 --- a/crates/rspack_plugin_split_chunks/src/plugin/chunk.rs +++ b/crates/rspack_plugin_split_chunks/src/plugin/chunk.rs @@ -158,7 +158,7 @@ impl SplitChunksPlugin { } /// This de-duplicated each module fro other chunks, make sure there's only one copy of each module. - #[tracing::instrument(skip_all)] + // #[tracing::instrument(skip_all)] pub(crate) fn move_modules_to_new_chunk_and_remove_from_old_chunks( &self, item: &ModuleGroup, @@ -187,7 +187,7 @@ impl SplitChunksPlugin { /// create a connection between the `new_chunk` and `original_chunks`. /// Thus, if `original_chunks` want to know which chunk contains moved modules, /// it could easily find out. - #[tracing::instrument(skip_all)] + // #[tracing::instrument(skip_all)] pub(crate) fn split_from_original_chunks( &self, _item: &ModuleGroup, diff --git a/crates/rspack_plugin_split_chunks/src/plugin/max_request.rs b/crates/rspack_plugin_split_chunks/src/plugin/max_request.rs index e180f7b1ea8..ba450af62cc 100644 --- a/crates/rspack_plugin_split_chunks/src/plugin/max_request.rs +++ b/crates/rspack_plugin_split_chunks/src/plugin/max_request.rs @@ -8,7 +8,7 @@ use crate::{CacheGroup, SplitChunksPlugin}; impl SplitChunksPlugin { /// Affected by `splitChunks.maxInitialRequests`/`splitChunks.cacheGroups.{cacheGroup}.maxInitialRequests` /// Affected by `splitChunks.maxAsyncRequests`/`splitChunks.cacheGroups.{cacheGroup}.maxAsyncRequests` - #[tracing::instrument(skip_all)] + // #[tracing::instrument(skip_all)] pub(crate) fn ensure_max_request_fit( &self, compilation: &Compilation, diff --git a/crates/rspack_plugin_split_chunks/src/plugin/max_size.rs b/crates/rspack_plugin_split_chunks/src/plugin/max_size.rs index f285418acad..84f3a438d9a 100644 --- a/crates/rspack_plugin_split_chunks/src/plugin/max_size.rs +++ b/crates/rspack_plugin_split_chunks/src/plugin/max_size.rs @@ -208,7 +208,7 @@ struct ChunkWithSizeInfo<'a> { impl SplitChunksPlugin { /// Affected by `splitChunks.minSize`/`splitChunks.cacheGroups.{cacheGroup}.minSize` - #[tracing::instrument(skip_all)] + // #[tracing::instrument(skip_all)] pub(super) fn ensure_max_size_fit( &self, compilation: &mut Compilation, diff --git a/crates/rspack_plugin_split_chunks/src/plugin/min_size.rs b/crates/rspack_plugin_split_chunks/src/plugin/min_size.rs index b86666f65a6..08db6316f3a 100644 --- a/crates/rspack_plugin_split_chunks/src/plugin/min_size.rs +++ b/crates/rspack_plugin_split_chunks/src/plugin/min_size.rs @@ -70,7 +70,7 @@ impl SplitChunksPlugin { } /// Affected by `splitChunks.minSize`/`splitChunks.cacheGroups.{cacheGroup}.minSize` - #[tracing::instrument(skip_all)] + // #[tracing::instrument(skip_all)] pub(crate) fn ensure_min_size_fit( &self, compilation: &Compilation, diff --git a/crates/rspack_plugin_split_chunks/src/plugin/mod.rs b/crates/rspack_plugin_split_chunks/src/plugin/mod.rs index d58761da86f..0e8807c72a6 100644 --- a/crates/rspack_plugin_split_chunks/src/plugin/mod.rs +++ b/crates/rspack_plugin_split_chunks/src/plugin/mod.rs @@ -63,10 +63,10 @@ impl SplitChunksPlugin { module_group_key, module_group_map.len(), ); - let process_span = tracing::trace_span!("Process ModuleGroup({})", module_group_key); + // let process_span = tracing::trace_span!("Process ModuleGroup"); - process_span.in_scope(|| { - let cache_group = module_group.get_cache_group(&self.cache_groups); + // process_span.in_scope(|| { + let cache_group = module_group.get_cache_group(&self.cache_groups); let mut is_reuse_existing_chunk = false; let mut is_reuse_existing_chunk_with_all_modules = false; @@ -111,7 +111,8 @@ impl SplitChunksPlugin { if used_chunks_len < cache_group.min_chunks as usize { // `min_size` is not satisfied, ignore this invalid `ModuleGroup` tracing::trace!("ModuleGroup({module_group_key}) is skipped. Reason: used_chunks_len({used_chunks_len:?}) < cache_group.min_chunks({:?})", cache_group.min_chunks); - return; + continue; + // return; } } @@ -142,7 +143,7 @@ impl SplitChunksPlugin { &used_chunks, compilation, ); - }) + // }) } logger.time_end(start); diff --git a/crates/rspack_plugin_split_chunks/src/plugin/module_group.rs b/crates/rspack_plugin_split_chunks/src/plugin/module_group.rs index a0f890dd99b..827d19af97d 100644 --- a/crates/rspack_plugin_split_chunks/src/plugin/module_group.rs +++ b/crates/rspack_plugin_split_chunks/src/plugin/module_group.rs @@ -252,7 +252,7 @@ impl Combinator { } impl SplitChunksPlugin { - #[tracing::instrument(skip_all)] + // #[tracing::instrument(skip_all)] pub(crate) fn find_best_module_group( &self, module_group_map: &mut ModuleGroupMap, @@ -276,7 +276,7 @@ impl SplitChunksPlugin { (best_entry_key, best_module_group) } - #[tracing::instrument(skip_all)] + // #[tracing::instrument(skip_all)] pub(crate) fn prepare_module_group_map( &self, compilation: &Compilation, @@ -501,7 +501,7 @@ impl SplitChunksPlugin { Ok(module_group_map.into_iter().collect()) } - #[tracing::instrument(skip_all)] + // #[tracing::instrument(skip_all)] pub(crate) fn remove_all_modules_from_other_module_groups( &self, current_module_group: &ModuleGroup, diff --git a/crates/rspack_tracing/Cargo.toml b/crates/rspack_tracing/Cargo.toml index 7cad9f50ff4..1829c9a1ff4 100644 --- a/crates/rspack_tracing/Cargo.toml +++ b/crates/rspack_tracing/Cargo.toml @@ -9,7 +9,11 @@ version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -console-subscriber = { version = "0.4.0" } -tracing = { workspace = true } -tracing-chrome = "0.7.2" -tracing-subscriber = { workspace = true, features = ["env-filter"] } +console-subscriber = { version = "0.4.0" } +opentelemetry = "0.26.0" +opentelemetry-otlp = "0.26.0" +opentelemetry_sdk = { version = "0.26.0", features = ["rt-tokio"] } +tracing = { workspace = true } +tracing-chrome = "0.7.2" +tracing-opentelemetry = "0.27.0" +tracing-subscriber = { workspace = true, features = ["env-filter"] } diff --git a/crates/rspack_tracing/src/chrome.rs b/crates/rspack_tracing/src/chrome.rs new file mode 100644 index 00000000000..59f8b2b801f --- /dev/null +++ b/crates/rspack_tracing/src/chrome.rs @@ -0,0 +1,51 @@ +use tracing_chrome::{ChromeLayerBuilder, FlushGuard}; +use tracing_subscriber::layer::{Filter, Layer}; + +use crate::{ + tracer::{Layered, Tracer}, + TraceWriter, +}; + +#[derive(Default)] +pub struct ChromeTracer { + guard: Option, +} + +impl Tracer for ChromeTracer { + fn setup(&mut self, output: &str) -> Option { + let console_layer = console_subscriber::ConsoleLayer::builder().spawn(); + let trace_writer = TraceWriter::from(output); + let (chrome_layer, guard) = ChromeLayerBuilder::new() + .include_args(true) + .writer(trace_writer.writer()) + .build(); + self.guard = Some(guard); + + Some( + vec![ + chrome_layer.with_filter(FilterEvent {}).boxed(), + console_layer.boxed(), + ] + .boxed(), + ) + } + + fn teardown(&mut self) { + if let Some(guard) = self.guard.take() { + guard.flush(); + } + } +} + +// skip event because it's not useful for performance analysis +struct FilterEvent; + +impl Filter for FilterEvent { + fn enabled( + &self, + meta: &tracing::Metadata<'_>, + _cx: &tracing_subscriber::layer::Context<'_, S>, + ) -> bool { + !meta.is_event() + } +} diff --git a/crates/rspack_tracing/src/lib.rs b/crates/rspack_tracing/src/lib.rs index 95c76ca6aaf..36c543d20fb 100644 --- a/crates/rspack_tracing/src/lib.rs +++ b/crates/rspack_tracing/src/lib.rs @@ -1,120 +1,25 @@ -use std::fs; -use std::io; -use std::path::Path; -use std::str::FromStr; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering; - -use tracing::Level; -use tracing_chrome::FlushGuard; +mod chrome; +mod opentelemetry; +mod stdout; +mod tokio_console; +mod tracer; + +use std::{fs, io, path::Path}; + +pub use chrome::ChromeTracer; +pub use opentelemetry::OtelTracer; +pub use stdout::StdoutTracer; +pub use tokio_console::TokioConsoleTracer; +pub use tracer::Tracer; use tracing_subscriber::fmt::writer::BoxMakeWriter; -use tracing_subscriber::{fmt::format::FmtSpan, layer::Filter}; -use tracing_subscriber::{EnvFilter, Layer}; - -pub mod chrome { - pub use tracing_chrome::FlushGuard; -} - -static IS_TRACING_ENABLED: AtomicBool = AtomicBool::new(false); - -// skip event because it's not useful for performance analysis -struct FilterEvent; -impl Filter for FilterEvent { - fn enabled( - &self, - meta: &tracing::Metadata<'_>, - _cx: &tracing_subscriber::layer::Context<'_, S>, - ) -> bool { - !meta.is_event() - } -} - -pub fn enable_tracing_by_env(filter: &str, output: &str) { - if !IS_TRACING_ENABLED.swap(true, Ordering::Relaxed) { - use tracing_subscriber::{fmt, prelude::*}; - let layers = generate_common_layers(filter); - let trace_writer = TraceWriter::from(output); - - tracing_subscriber::registry() - // .with(EnvFilter::from_env("TRACE").and_then(rspack_only_layer)) - .with(layers) - .with( - fmt::layer() - .pretty() - .with_file(true) - // To keep track of the closing point of spans - .with_span_events(FmtSpan::CLOSE) - .with_writer(trace_writer.make_writer()), - ) - .init(); - tracing::trace!("enable_tracing_by_env"); - } -} - -fn generate_common_layers( - filter: &str, -) -> Vec + Send + Sync>> { - let default_level = Level::from_str(filter).ok(); - - let mut layers = vec![]; - if let Some(default_level) = default_level { - layers.push( - tracing_subscriber::filter::Targets::new() - .with_targets(vec![ - ("rspack_core", default_level), - ("rspack", default_level), - ("rspack_node", default_level), - ("rspack_plugin_javascript", default_level), - ("rspack_plugin_split_chunks", default_level), - ("rspack_binding_options", default_level), - ]) - .boxed(), - ); - } else { - // SAFETY: we know that trace_var is `Ok(StrinG)` now, - // for the second unwrap, if we can't parse the directive, then the tracing result would be - // unexpected, then panic is reasonable - let env_layer = EnvFilter::builder() - .with_regex(true) - .parse(filter) - .expect("Parse tracing directive syntax failed,for details about the directive syntax you could refer https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives"); - - layers.push(env_layer.boxed()); - } - layers -} -// register layer for tokio_console, and tokio_console use network to send trace info so no need to pass result by string back -pub fn enable_tracing_by_env_with_tokio_console() { - if !IS_TRACING_ENABLED.swap(true, Ordering::Relaxed) { - console_subscriber::init(); - } -} -pub fn enable_tracing_by_env_with_chrome_layer(filter: &str, output: &str) -> Option { - if !IS_TRACING_ENABLED.swap(true, Ordering::Relaxed) { - use tracing_chrome::ChromeLayerBuilder; - use tracing_subscriber::prelude::*; - let console_layer = console_subscriber::ConsoleLayer::builder().spawn(); - let trace_writer = TraceWriter::from(output); - let (chrome_layer, guard) = ChromeLayerBuilder::new() - .include_args(true) - .writer(trace_writer.writer()) - .build(); - let layers = generate_common_layers(filter); - // If we don't do this. chrome_layer will collect nothing. - // std::mem::forget(guard); - tracing_subscriber::registry() - .with(layers) - .with(chrome_layer.with_filter(FilterEvent {})) - .with(console_layer) - .init(); - Some(guard) - } else { - None - } +pub mod otel { + pub use opentelemetry; + pub use opentelemetry_sdk as sdk; + pub use tracing_opentelemetry as tracing; } -enum TraceWriter<'a> { +pub(crate) enum TraceWriter<'a> { Stdout, Stderr, File { path: &'a Path }, diff --git a/crates/rspack_tracing/src/opentelemetry.rs b/crates/rspack_tracing/src/opentelemetry.rs new file mode 100644 index 00000000000..f9839686679 --- /dev/null +++ b/crates/rspack_tracing/src/opentelemetry.rs @@ -0,0 +1,47 @@ +use opentelemetry::{global, trace::TracerProvider as _, KeyValue}; +use opentelemetry_sdk::{propagation::TraceContextPropagator, runtime, Resource}; +use tracing_opentelemetry::OpenTelemetryLayer; +use tracing_subscriber::Layer; + +use super::tracer::Tracer; +use crate::tracer::Layered; + +pub struct OtelTracer { + provider: opentelemetry_sdk::trace::TracerProvider, +} + +impl Default for OtelTracer { + fn default() -> Self { + Self::new() + } +} + +impl OtelTracer { + fn new() -> Self { + let provider = + opentelemetry_otlp::new_pipeline() + .tracing() + .with_exporter(opentelemetry_otlp::new_exporter().tonic()) + .with_trace_config(opentelemetry_sdk::trace::Config::default().with_resource( + Resource::new(vec![KeyValue::new("service.name", "rspack-app")]), + )) + .install_batch(runtime::Tokio) + .expect("Should be able to initialize open telemetry"); + + Self { provider } + } +} + +impl Tracer for OtelTracer { + fn setup(&mut self, _output: &str) -> Option { + global::set_text_map_propagator(TraceContextPropagator::new()); + global::set_tracer_provider(self.provider.clone()); + let trace = self.provider.tracer("rspack-app"); + Some(OpenTelemetryLayer::new(trace).boxed()) + } + + fn teardown(&mut self) { + let _ = self.provider.shutdown(); + opentelemetry::global::shutdown_tracer_provider(); + } +} diff --git a/crates/rspack_tracing/src/stdout.rs b/crates/rspack_tracing/src/stdout.rs new file mode 100644 index 00000000000..aed93b03598 --- /dev/null +++ b/crates/rspack_tracing/src/stdout.rs @@ -0,0 +1,28 @@ +use tracing_subscriber::fmt::format::FmtSpan; + +use crate::{ + tracer::{Layered, Tracer}, + TraceWriter, +}; + +pub struct StdoutTracer; + +impl Tracer for StdoutTracer { + fn setup(&mut self, output: &str) -> Option { + use tracing_subscriber::{fmt, prelude::*}; + let trace_writer = TraceWriter::from(output); + Some( + fmt::layer() + .pretty() + .with_file(true) + // To keep track of the closing point of spans + .with_span_events(FmtSpan::CLOSE) + .with_writer(trace_writer.make_writer()) + .boxed(), + ) + } + + fn teardown(&mut self) { + // noop + } +} diff --git a/crates/rspack_tracing/src/tokio_console.rs b/crates/rspack_tracing/src/tokio_console.rs new file mode 100644 index 00000000000..241f8047784 --- /dev/null +++ b/crates/rspack_tracing/src/tokio_console.rs @@ -0,0 +1,12 @@ +use crate::{tracer::Layered, Tracer}; + +pub struct TokioConsoleTracer; + +impl Tracer for TokioConsoleTracer { + fn setup(&mut self, _output: &str) -> Option { + console_subscriber::init(); + None + } + + fn teardown(&mut self) {} +} diff --git a/crates/rspack_tracing/src/tracer.rs b/crates/rspack_tracing/src/tracer.rs new file mode 100644 index 00000000000..aac899f34eb --- /dev/null +++ b/crates/rspack_tracing/src/tracer.rs @@ -0,0 +1,8 @@ +use tracing_subscriber::{Layer, Registry}; + +pub type Layered = Box + Send + Sync>; + +pub trait Tracer { + fn setup(&mut self, output: &str) -> Option; + fn teardown(&mut self); +} diff --git a/packages/rspack-cli/package.json b/packages/rspack-cli/package.json index 6f4c5c18e16..8ab0777b992 100644 --- a/packages/rspack-cli/package.json +++ b/packages/rspack-cli/package.json @@ -35,6 +35,7 @@ "dependencies": { "@discoveryjs/json-ext": "^0.5.7", "@rspack/dev-server": "1.0.9", + "@rspack/tracing": "workspace:*", "colorette": "2.0.19", "exit-hook": "^4.0.0", "interpret": "^3.1.1", diff --git a/packages/rspack-cli/src/utils/profile.ts b/packages/rspack-cli/src/utils/profile.ts index 6681733fe9a..1fcb1fdb79e 100644 --- a/packages/rspack-cli/src/utils/profile.ts +++ b/packages/rspack-cli/src/utils/profile.ts @@ -123,6 +123,11 @@ function resolveJSCPUProfileOptions(value: string): JSCPUProfileOptions { return { output: value || defaultJSCPUProfileOutput }; } +function isSupportedLayer(layer: string): layer is RustTraceOptionsLayer { + const SUPPORTED_LAYERS = ["chrome", "logger", "otel", "console"]; + return SUPPORTED_LAYERS.some(l => l === layer); +} + // TRACE=value function resolveRustTraceOptions(value: string): RustTraceOptions { // filter=trace&output=stdout&layer=logger @@ -134,7 +139,8 @@ function resolveRustTraceOptions(value: string): RustTraceOptions { layer === "chrome" ? parsed.get("output") || defaultRustTraceChromeOutput : parsed.get("output") || defaultRustTraceLoggerOutput; - if (layer !== "chrome" && layer !== "logger" && layer !== "console") { + + if (!isSupportedLayer(layer)) { throw new Error( `${layer} is not a valid layer, should be chrome or logger` ); @@ -210,19 +216,21 @@ class RspackProfileLoggingPlugin { } export async function applyProfile(profileValue: string, item: RspackOptions) { - const { default: exitHook } = await dynamicImport("exit-hook"); + const { asyncExitHook } = await dynamicImport("exit-hook"); const entries = Object.entries(resolveProfile(profileValue)); if (entries.length <= 0) return; await fs.promises.mkdir(defaultOutputDirname); for (const [kind, value] of entries) { await ensureFileDir(value.output); if (kind === "TRACE" && "filter" in value) { - rspack.experiments.globalTrace.register( + await rspack.experiments.globalTrace.register( value.filter, value.layer, value.output ); - exitHook(rspack.experiments.globalTrace.cleanup); + asyncExitHook(rspack.experiments.globalTrace.cleanup, { + wait: 500 + }); } else if (kind === "JSCPU") { (item.plugins ??= []).push( new RspackProfileJSCPUProfilePlugin(value.output) diff --git a/packages/rspack-cli/tests/build/profile/profile.test.ts b/packages/rspack-cli/tests/build/profile/profile.test.ts index 73ce77f8a8d..601a993bb28 100644 --- a/packages/rspack-cli/tests/build/profile/profile.test.ts +++ b/packages/rspack-cli/tests/build/profile/profile.test.ts @@ -124,9 +124,9 @@ describe("profile", () => { __dirname, [], {}, - { RSPACK_PROFILE: `TRACE=layer=logger&filter=rspack_node::plugins` } + { RSPACK_PROFILE: `TRACE=layer=logger&filter=rspack_core::compiler` } ); expect(exitCode).toBe(0); - expect(stdout.includes("rspack_node::plugins")).toBe(true); + expect(stdout.includes("rspack_core::compiler")).toBe(true); }); }); diff --git a/packages/rspack-tracing/index.d.ts b/packages/rspack-tracing/index.d.ts new file mode 100644 index 00000000000..dcdb37aa213 --- /dev/null +++ b/packages/rspack-tracing/index.d.ts @@ -0,0 +1,3 @@ +export function initOpenTelemetry(): Promise; +export function shutdownOpenTelemetry(): Promise; +export { trace, propagation, context } from "@opentelemetry/api"; diff --git a/packages/rspack-tracing/index.js b/packages/rspack-tracing/index.js new file mode 100644 index 00000000000..d1a7674114e --- /dev/null +++ b/packages/rspack-tracing/index.js @@ -0,0 +1,34 @@ +let sdk; + +export async function initOpenTelemetry() { + if (sdk) return; + const otel = await import("@opentelemetry/sdk-node"); + const { Resource } = await import("@opentelemetry/resources"); + const { OTLPTraceExporter } = await import( + "@opentelemetry/exporter-trace-otlp-proto" + ); + const { AsyncHooksContextManager } = await import( + "@opentelemetry/context-async-hooks" + ); + const contextManager = new AsyncHooksContextManager(); + contextManager.enable(); + otel.api.context.setGlobalContextManager(contextManager); + + sdk = new otel.NodeSDK({ + resource: new Resource({ + "service.name": "rspack-app" + }), + traceExporter: new OTLPTraceExporter() + }); + sdk.start(); +} + +export async function shutdownOpenTelemetry() { + if (!sdk) return; + const otel = await import("@opentelemetry/sdk-node"); + await sdk.shutdown(); + otel.api.context.disable(); + sdk = null; +} + +export { trace, propagation, context } from "@opentelemetry/api"; diff --git a/packages/rspack-tracing/package.json b/packages/rspack-tracing/package.json new file mode 100644 index 00000000000..fd9774b70aa --- /dev/null +++ b/packages/rspack-tracing/package.json @@ -0,0 +1,27 @@ +{ + "name": "@rspack/tracing", + "version": "1.0.12", + "private": true, + "type": "module", + "description": "Internal tracing package for rspack", + "homepage": "https://rspack.dev", + "bugs": "https://github.com/web-infra-dev/rspack/issues", + "repository": { + "type": "git", + "url": "https://github.com/web-infra-dev/rspack", + "directory": "packages/rspack-tracing" + }, + "license": "MIT", + "main": "./index.js", + "types": "./index.d.ts", + "scripts": { + "build": "tsc -b ./tsconfig.build.json" + }, + "dependencies": { + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/context-async-hooks": "^1.26.0", + "@opentelemetry/exporter-trace-otlp-proto": "^0.54.2", + "@opentelemetry/resources": "^1.26.0", + "@opentelemetry/sdk-node": "^0.54.2" + } +} \ No newline at end of file diff --git a/packages/rspack-tracing/tsconfig.build.json b/packages/rspack-tracing/tsconfig.build.json new file mode 100644 index 00000000000..cfa29a22fa1 --- /dev/null +++ b/packages/rspack-tracing/tsconfig.build.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "outDir": ".", + "emitDeclarationOnly": true, + "declaration": true + }, + "exclude": ["index.d.ts"] +} diff --git a/packages/rspack/package.json b/packages/rspack/package.json index f285a1041bb..f4ce3c5ae1b 100644 --- a/packages/rspack/package.json +++ b/packages/rspack/package.json @@ -72,6 +72,7 @@ "dependencies": { "@module-federation/runtime-tools": "0.5.1", "@rspack/binding": "workspace:*", + "@rspack/tracing": "workspace:*", "@rspack/lite-tapable": "1.0.1", "caniuse-lite": "^1.0.30001616" }, diff --git a/packages/rspack/src/exports.ts b/packages/rspack/src/exports.ts index cc406ecb2d9..13e5676e8db 100644 --- a/packages/rspack/src/exports.ts +++ b/packages/rspack/src/exports.ts @@ -292,16 +292,30 @@ export type { import { cleanupGlobalTrace, registerGlobalTrace } from "@rspack/binding"; interface Experiments { globalTrace: { - register: typeof registerGlobalTrace; - cleanup: typeof cleanupGlobalTrace; + register: ( + filter: string, + layer: "chrome" | "logger" | "console" | "otel", + output: string + ) => Promise; + cleanup: () => Promise; }; RemoveDuplicateModulesPlugin: typeof RemoveDuplicateModulesPlugin; } export const experiments: Experiments = { globalTrace: { - register: registerGlobalTrace, - cleanup: cleanupGlobalTrace + async register(filter, layer, output) { + registerGlobalTrace(filter, layer, output); + if (layer === "otel") { + const { initOpenTelemetry } = await import("@rspack/tracing"); + await initOpenTelemetry(); + } + }, + async cleanup() { + cleanupGlobalTrace(); + const { shutdownOpenTelemetry } = await import("@rspack/tracing"); + await shutdownOpenTelemetry(); + } }, RemoveDuplicateModulesPlugin }; diff --git a/packages/rspack/src/loader-runner/index.ts b/packages/rspack/src/loader-runner/index.ts index 942df724adf..692eed3178c 100644 --- a/packages/rspack/src/loader-runner/index.ts +++ b/packages/rspack/src/loader-runner/index.ts @@ -344,6 +344,17 @@ export async function runLoaders( compiler: Compiler, context: JsLoaderContext ): Promise { + const { + trace, + propagation, + context: tracingContext + } = await import("@rspack/tracing"); + const tracer = trace.getTracer("rspack-loader-runner"); + const activeContext = propagation.extract( + tracingContext.active(), + context.__internal__tracingCarrier + ); + const loaderState = context.loaderState; // @@ -831,12 +842,22 @@ export async function runLoaders( currentLoaderObject.pitchExecuted = true; if (!fn) continue; + const span = tracer.startSpan( + "LoaderRunner:pitch", + { + attributes: { + "loader.identifier": getCurrentLoader(loaderContext)?.request + } + }, + activeContext + ); const args = (await runSyncOrAsync(fn, loaderContext, [ loaderContext.remainingRequest, loaderContext.previousRequest, currentLoaderObject.data ])) || []; + span.end(); const hasArg = args.some(value => value !== undefined); @@ -872,8 +893,19 @@ export async function runLoaders( if (!fn) continue; const args = [content, sourceMap, additionalData]; convertArgs(args, !!currentLoaderObject.raw); + + const span = tracer.startSpan( + "LoaderRunner:normal", + { + attributes: { + "loader.identifier": getCurrentLoader(loaderContext)?.request + } + }, + activeContext + ); [content, sourceMap, additionalData] = (await runSyncOrAsync(fn, loaderContext, args)) || []; + span.end(); } context.content = isNil(content) ? null : toBuffer(content); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a858fb7583b..0b1c3d46ed3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -375,6 +375,9 @@ importers: '@rspack/lite-tapable': specifier: 1.0.1 version: 1.0.1 + '@rspack/tracing': + specifier: workspace:* + version: link:../rspack-tracing '@swc/helpers': specifier: '>=0.5.1' version: 0.5.13 @@ -448,6 +451,9 @@ importers: '@rspack/dev-server': specifier: 1.0.9 version: 1.0.9(@rspack/core@packages+rspack)(@types/express@4.17.21)(webpack-cli@5.1.4(webpack@5.94.0))(webpack@5.94.0(@swc/core@1.7.40(@swc/helpers@0.5.13))(webpack-cli@5.1.4(webpack@5.94.0))) + '@rspack/tracing': + specifier: workspace:* + version: link:../rspack-tracing colorette: specifier: 2.0.19 version: 2.0.19 @@ -739,6 +745,24 @@ importers: specifier: ^18.2.0 version: 18.3.1 + packages/rspack-tracing: + dependencies: + '@opentelemetry/api': + specifier: ^1.9.0 + version: 1.9.0 + '@opentelemetry/context-async-hooks': + specifier: ^1.26.0 + version: 1.26.0(@opentelemetry/api@1.9.0) + '@opentelemetry/exporter-trace-otlp-proto': + specifier: ^0.54.2 + version: 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/resources': + specifier: ^1.26.0 + version: 1.26.0(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-node': + specifier: ^0.54.2 + version: 0.54.2(@opentelemetry/api@1.9.0) + scripts: devDependencies: '@actions/core': @@ -1937,6 +1961,15 @@ packages: resolution: {integrity: sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==} engines: {node: '>=14'} + '@grpc/grpc-js@1.12.2': + resolution: {integrity: sha512-bgxdZmgTrJZX50OjyVwz3+mNEnCTNkh3cIqGPWVNeW9jX6bn1ZkU80uPd+67/ZpIJIjRQ9qaHCjhavyoWYxumg==} + engines: {node: '>=12.10.0'} + + '@grpc/proto-loader@0.7.13': + resolution: {integrity: sha512-AiXO/bfe9bmxBjxxtYxFAXGZvMaN5s8kO+jBHAJCON8rJoB5YS/D6X7ZNc6XQkuHNmyl4CYaMI1fJ/Gn27RGGw==} + engines: {node: '>=6'} + hasBin: true + '@gwhitney/detect-indent@7.0.1': resolution: {integrity: sha512-7bQW+gkKa2kKZPeJf6+c6gFK9ARxQfn+FKy9ScTBppyKRWH2KzsmweXUoklqeEiHiNVWaeP5csIdsNq6w7QhzA==} engines: {node: '>=12.20'} @@ -2127,6 +2160,9 @@ packages: '@jridgewell/trace-mapping@0.3.9': resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==} + '@js-sdsl/ordered-map@4.4.2': + resolution: {integrity: sha512-iUKgm52T8HOE/makSxjqoWhe95ZJA1/G1sYsGev2JDKUSS14KAgg1LHb+Ba+IPow0xflbnSkOsZcO08C7w1gYw==} + '@jsonjoy.com/base64@1.1.2': resolution: {integrity: sha512-q6XAnWQDIMA3+FTiOYajoYqySkO+JSat0ytXGSuRdq9uXE7o92gzuQwQM14xaCRlBLGq3v5miDGC4vkVTn54xA==} engines: {node: '>=10.0'} @@ -2600,6 +2636,162 @@ packages: '@octokit/types@13.6.1': resolution: {integrity: sha512-PHZE9Z+kWXb23Ndik8MKPirBPziOc0D2/3KH1P+6jK5nGWe96kadZuE4jev2/Jq7FvIfTlT2Ltg8Fv2x1v0a5g==} + '@opentelemetry/api-logs@0.54.2': + resolution: {integrity: sha512-4MTVwwmLgUh5QrJnZpYo6YRO5IBLAggf2h8gWDblwRagDStY13aEvt7gGk3jewrMaPlHiF83fENhIx0HO97/cQ==} + engines: {node: '>=14'} + + '@opentelemetry/api@1.9.0': + resolution: {integrity: sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==} + engines: {node: '>=8.0.0'} + + '@opentelemetry/context-async-hooks@1.26.0': + resolution: {integrity: sha512-HedpXXYzzbaoutw6DFLWLDket2FwLkLpil4hGCZ1xYEIMTcivdfwEOISgdbLEWyG3HW52gTq2V9mOVJrONgiwg==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.0.0 <1.10.0' + + '@opentelemetry/context-async-hooks@1.27.0': + resolution: {integrity: sha512-CdZ3qmHCwNhFAzjTgHqrDQ44Qxcpz43cVxZRhOs+Ns/79ug+Mr84Bkb626bkJLkA3+BLimA5YAEVRlJC6pFb7g==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.0.0 <1.10.0' + + '@opentelemetry/core@1.26.0': + resolution: {integrity: sha512-1iKxXXE8415Cdv0yjG3G6hQnB5eVEsJce3QaawX8SjDn0mAS0ZM8fAbZZJD4ajvhC15cePvosSCut404KrIIvQ==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.0.0 <1.10.0' + + '@opentelemetry/core@1.27.0': + resolution: {integrity: sha512-yQPKnK5e+76XuiqUH/gKyS8wv/7qITd5ln56QkBTf3uggr0VkXOXfcaAuG330UfdYu83wsyoBwqwxigpIG+Jkg==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.0.0 <1.10.0' + + '@opentelemetry/exporter-logs-otlp-grpc@0.54.2': + resolution: {integrity: sha512-MQNmV5r96+5n3axLFgNYtVy62x8Ru7VERZH3zgC50KDcIKWCiQT3vHOtzakhzd1Wq0HqOgu6bzKdwzneSoDrEQ==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': ^1.3.0 + + '@opentelemetry/exporter-logs-otlp-http@0.54.2': + resolution: {integrity: sha512-wYeCSbX2XWX2wFslnfQ/YFUolO0fj2nUiGI7oEQWpLKSg40Lc4xOOW14X/EXOkCCijhP7bigo6nvyEQlxEVLjA==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': ^1.3.0 + + '@opentelemetry/exporter-logs-otlp-proto@0.54.2': + resolution: {integrity: sha512-agrzFbSNmIy6dhkyg41ERlEDUDqkaUJj2n/tVRFp9Tl+6wyNVPsqmwU5RWJOXpyK+lYH/znv6A47VpTeJF0lrw==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': ^1.3.0 + + '@opentelemetry/exporter-trace-otlp-grpc@0.54.2': + resolution: {integrity: sha512-tmxiCYhQdPrzwlM6O7VQeNP9PBjKhaiOo54wFxQFZQcoVaDiOOES4+6PwHU1eW+43mDsgdQHN5AHSRHVLe9jDA==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': ^1.3.0 + + '@opentelemetry/exporter-trace-otlp-http@0.54.2': + resolution: {integrity: sha512-BgWKKyD/h2zpISdmYHN/sapwTjvt1P4p5yx4xeBV8XAEqh4OQUhOtSGFG80+nPQ1F8of3mKOT1DDoDbJp1u25w==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': ^1.3.0 + + '@opentelemetry/exporter-trace-otlp-proto@0.54.2': + resolution: {integrity: sha512-XSmm1N2wAhoWDXP1q/N6kpLebWaxl6VIADv4WA5QWKHLRpF3gLz5NAWNJBR8ygsvv8jQcrwnXgwfnJ18H3v1fg==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': ^1.3.0 + + '@opentelemetry/exporter-zipkin@1.27.0': + resolution: {integrity: sha512-eGMY3s4QprspFZojqsuQyQpWNFpo+oNVE/aosTbtvAlrJBAlvXcwwsOROOHOd8Y9lkU4i0FpQW482rcXkgwCSw==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': ^1.0.0 + + '@opentelemetry/instrumentation@0.54.2': + resolution: {integrity: sha512-go6zpOVoZVztT9r1aPd79Fr3OWiD4N24bCPJsIKkBses8oyFo12F/Ew3UBTdIu6hsW4HC4MVEJygG6TEyJI/lg==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': ^1.3.0 + + '@opentelemetry/otlp-exporter-base@0.54.2': + resolution: {integrity: sha512-NrNyxu6R/bGAwanhz1HI0aJWKR6xUED4TjCH4iWMlAfyRukGbI9Kt/Akd2sYLwRKNhfS+sKetKGCUQPMDyYYMA==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': ^1.3.0 + + '@opentelemetry/otlp-grpc-exporter-base@0.54.2': + resolution: {integrity: sha512-HZtACQuLhgDcgNa9arGnVVGV28sSGQ+iwRgICWikFKiVxUsoWffqBvTxPa6G3DUTg5R+up97j/zxubEyxSAOHg==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': ^1.3.0 + + '@opentelemetry/otlp-transformer@0.54.2': + resolution: {integrity: sha512-2tIjahJlMRRUz0A2SeE+qBkeBXBFkSjR0wqJ08kuOqaL8HNGan5iZf+A8cfrfmZzPUuMKCyY9I+okzFuFs6gKQ==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': ^1.3.0 + + '@opentelemetry/propagator-b3@1.27.0': + resolution: {integrity: sha512-pTsko3gnMioe3FeWcwTQR3omo5C35tYsKKwjgTCTVCgd3EOWL9BZrMfgLBmszrwXABDfUrlAEFN/0W0FfQGynQ==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.0.0 <1.10.0' + + '@opentelemetry/propagator-jaeger@1.27.0': + resolution: {integrity: sha512-EI1bbK0wn0yIuKlc2Qv2LKBRw6LiUWevrjCF80fn/rlaB+7StAi8Y5s8DBqAYNpY7v1q86+NjU18v7hj2ejU3A==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.0.0 <1.10.0' + + '@opentelemetry/resources@1.26.0': + resolution: {integrity: sha512-CPNYchBE7MBecCSVy0HKpUISEeJOniWqcHaAHpmasZ3j9o6V3AyBzhRc90jdmemq0HOxDr6ylhUbDhBqqPpeNw==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.0.0 <1.10.0' + + '@opentelemetry/resources@1.27.0': + resolution: {integrity: sha512-jOwt2VJ/lUD5BLc+PMNymDrUCpm5PKi1E9oSVYAvz01U/VdndGmrtV3DU1pG4AwlYhJRHbHfOUIlpBeXCPw6QQ==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.0.0 <1.10.0' + + '@opentelemetry/sdk-logs@0.54.2': + resolution: {integrity: sha512-yIbYqDLS/AtBbPjCjh6eSToGNRMqW2VR8RrKEy+G+J7dFG7pKoptTH5T+XlKPleP9NY8JZYIpgJBlI+Osi0rFw==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.4.0 <1.10.0' + + '@opentelemetry/sdk-metrics@1.27.0': + resolution: {integrity: sha512-JzWgzlutoXCydhHWIbLg+r76m+m3ncqvkCcsswXAQ4gqKS+LOHKhq+t6fx1zNytvLuaOUBur7EvWxECc4jPQKg==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.3.0 <1.10.0' + + '@opentelemetry/sdk-node@0.54.2': + resolution: {integrity: sha512-afn8GBpA7Gb55aU0LUxIQ+oe6QxLhsf+Te9iw12Non3ZAspzdoCcfz5+hqecwpuVpEDdnj5iSalF7VVaL2pDeg==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.3.0 <1.10.0' + + '@opentelemetry/sdk-trace-base@1.27.0': + resolution: {integrity: sha512-btz6XTQzwsyJjombpeqCX6LhiMQYpzt2pIYNPnw0IPO/3AhT6yjnf8Mnv3ZC2A4eRYOjqrg+bfaXg9XHDRJDWQ==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.0.0 <1.10.0' + + '@opentelemetry/sdk-trace-node@1.27.0': + resolution: {integrity: sha512-dWZp/dVGdUEfRBjBq2BgNuBlFqHCxyyMc8FsN0NX15X07mxSUO0SZRLyK/fdAVrde8nqFI/FEdMH4rgU9fqJfQ==} + engines: {node: '>=14'} + peerDependencies: + '@opentelemetry/api': '>=1.0.0 <1.10.0' + + '@opentelemetry/semantic-conventions@1.27.0': + resolution: {integrity: sha512-sAay1RrB+ONOem0OZanAR1ZI/k7yDpnOQSQmTMuGImUQb2y8EbSaCJ94FQluM74xoU03vlb2d2U90hZluL6nQg==} + engines: {node: '>=14'} + '@pkgjs/parseargs@0.11.0': resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} @@ -2761,6 +2953,36 @@ packages: '@prefresh/utils@1.2.0': resolution: {integrity: sha512-KtC/fZw+oqtwOLUFM9UtiitB0JsVX0zLKNyRTA332sqREqSALIIQQxdUCS1P3xR/jT1e2e8/5rwH6gdcMLEmsQ==} + '@protobufjs/aspromise@1.1.2': + resolution: {integrity: sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==} + + '@protobufjs/base64@1.1.2': + resolution: {integrity: sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==} + + '@protobufjs/codegen@2.0.4': + resolution: {integrity: sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==} + + '@protobufjs/eventemitter@1.1.0': + resolution: {integrity: sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==} + + '@protobufjs/fetch@1.1.0': + resolution: {integrity: sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==} + + '@protobufjs/float@1.0.2': + resolution: {integrity: sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==} + + '@protobufjs/inquire@1.1.0': + resolution: {integrity: sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==} + + '@protobufjs/path@1.1.2': + resolution: {integrity: sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==} + + '@protobufjs/pool@1.1.0': + resolution: {integrity: sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==} + + '@protobufjs/utf8@1.1.0': + resolution: {integrity: sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==} + '@rc-component/async-validator@5.0.4': resolution: {integrity: sha512-qgGdcVIF604M9EqjNF0hbUTz42bz/RDtxWdWuU5EQe3hi7M8ob54B6B35rOsvX5eSvIHIzT9iH1R3n+hk3CGfg==} engines: {node: '>=14.x'} @@ -3573,6 +3795,9 @@ packages: '@types/serve-static@1.15.7': resolution: {integrity: sha512-W8Ym+h8nhuRwaKPaDw34QUkwsGi6Rc4yYqvKFo5rm2FUEhCFbzVWrxXUxuKK8TASjWsysJY0nsmNCGhCOIsrOw==} + '@types/shimmer@1.2.0': + resolution: {integrity: sha512-UE7oxhQLLd9gub6JKIAhDq06T0F6FnztwMNRvYgjeQSBeMc1ZG/tA47EwfduvkuQS8apbkM/lpLpWsaCeYsXVg==} + '@types/sockjs@0.3.36': resolution: {integrity: sha512-MK9V6NzAS1+Ud7JV9lJLFqW85VbC9dq3LmwZCuBe4wBDgKC0Kj/jd8Xl+nSviU+Qc3+m7umHHyHg//2KSa0a0Q==} @@ -5990,6 +6215,9 @@ packages: resolution: {integrity: sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==} engines: {node: '>=6'} + import-in-the-middle@1.11.2: + resolution: {integrity: sha512-gK6Rr6EykBcc6cVWRSBR5TWf8nn6hZMYSRYqCcHa0l0d1fPK7JSYo6+Mlmck76jIX9aL/IZ71c06U2VpFwl1zA==} + import-lazy@4.0.0: resolution: {integrity: sha512-rKtvo6a868b5Hu3heneU+L4yEQ4jYKLtjpnPeUdK7h0yzXGmyBTypknlkCvHFBqfX9YlorEiMM6Dnq/5atfHkw==} engines: {node: '>=8'} @@ -6697,6 +6925,9 @@ packages: lodash-es@4.17.21: resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==} + lodash.camelcase@4.3.0: + resolution: {integrity: sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==} + lodash.clonedeep@4.5.0: resolution: {integrity: sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==} @@ -6719,6 +6950,9 @@ packages: resolution: {integrity: sha512-niTvB4gqvtof056rRIrTZvjNYE4rCUzO6X/X+kYjd7WFxXeJ0NwEFnRxX6ehkvv3jTwrXnNdtAak5XYZuIyPFw==} engines: {node: '>=18'} + long@5.2.3: + resolution: {integrity: sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==} + longest-streak@3.1.0: resolution: {integrity: sha512-9Ri+o0JYgehTaVBBDoMqIl8GXtbWg711O3srftcHhZ0dqnETqLaoIK0x17fUw9rFSlK/0NlsKe0Ahhyl5pXE2g==} @@ -7058,6 +7292,9 @@ packages: resolution: {integrity: sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==} hasBin: true + module-details-from-path@1.0.3: + resolution: {integrity: sha512-ySViT69/76t8VhE1xXHK6Ch4NcDd26gx0MzKXLO+F7NOtnqH68d9zF94nT8ZWSxXh8ELOERsnJO/sWt1xZYw5A==} + monaco-editor-webpack-plugin@7.1.0: resolution: {integrity: sha512-ZjnGINHN963JQkFqjjcBtn1XBtUATDZBMgNQhDQwd78w2ukRhFXAPNgWuacaQiDZsUr4h1rWv5Mv6eriKuOSzA==} peerDependencies: @@ -7714,6 +7951,10 @@ packages: proto-list@1.2.4: resolution: {integrity: sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==} + protobufjs@7.4.0: + resolution: {integrity: sha512-mRUWCc3KUU4w1jU8sGxICXH/gNS94DvI1gxqDvBzhj1JpcsimQkYiOJfwsPUykUI5ZaspFbSgmBLER8IrQ3tqw==} + engines: {node: '>=12.0.0'} + proxy-addr@2.0.7: resolution: {integrity: sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==} engines: {node: '>= 0.10'} @@ -8245,6 +8486,10 @@ packages: resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} engines: {node: '>=0.10.0'} + require-in-the-middle@7.4.0: + resolution: {integrity: sha512-X34iHADNbNDfr6OTStIAHWSAvvKQRYgLO6duASaVf7J2VA3lvmNYboAHOuLC2huav1IwgZJtyEcJCKVzFxOSMQ==} + engines: {node: '>=8.6.0'} + requires-port@1.0.0: resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==} @@ -8803,6 +9048,9 @@ packages: shell-quote@1.8.1: resolution: {integrity: sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==} + shimmer@1.2.1: + resolution: {integrity: sha512-sQTKC1Re/rM6XyFM6fIAGHRPVGvyXfgzIDvzoq608vM+jeyVD0Tu1E6Np0Kc2zAIFWIj963V2800iF/9LPieQw==} + side-channel@1.0.6: resolution: {integrity: sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==} engines: {node: '>= 0.4'} @@ -9893,6 +10141,10 @@ packages: resolution: {integrity: sha512-1/9UrdHjDZc0eOU0HxOHoS78C69UD3JRMvzlJ7S79S2nTaWRA/whGCTV8o9e/N/1Va9YIV7Q4sOxD8VV4pCWOw==} engines: {node: '>=12'} + yargs@17.7.2: + resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==} + engines: {node: '>=12'} + yargs@3.10.0: resolution: {integrity: sha512-QFzUah88GAGy9lyDKGBqZdkYApt63rCXYBGYnEP4xDJPXNqXXnBDACnbrXnViV6jRSqAePwrATi2i8mfYm4L1A==} @@ -10758,6 +11010,18 @@ snapshots: '@fastify/busboy@2.1.1': {} + '@grpc/grpc-js@1.12.2': + dependencies: + '@grpc/proto-loader': 0.7.13 + '@js-sdsl/ordered-map': 4.4.2 + + '@grpc/proto-loader@0.7.13': + dependencies: + lodash.camelcase: 4.3.0 + long: 5.2.3 + protobufjs: 7.4.0 + yargs: 17.7.2 + '@gwhitney/detect-indent@7.0.1': {} '@inquirer/checkbox@4.0.1(@types/node@20.12.7)': @@ -11078,6 +11342,8 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.0 + '@js-sdsl/ordered-map@4.4.2': {} + '@jsonjoy.com/base64@1.1.2(tslib@2.8.0)': dependencies: tslib: 2.8.0 @@ -11525,6 +11791,208 @@ snapshots: dependencies: '@octokit/openapi-types': 22.2.0 + '@opentelemetry/api-logs@0.54.2': + dependencies: + '@opentelemetry/api': 1.9.0 + + '@opentelemetry/api@1.9.0': {} + + '@opentelemetry/context-async-hooks@1.26.0(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + + '@opentelemetry/context-async-hooks@1.27.0(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + + '@opentelemetry/core@1.26.0(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/semantic-conventions': 1.27.0 + + '@opentelemetry/core@1.27.0(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/semantic-conventions': 1.27.0 + + '@opentelemetry/exporter-logs-otlp-grpc@0.54.2(@opentelemetry/api@1.9.0)': + dependencies: + '@grpc/grpc-js': 1.12.2 + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-grpc-exporter-base': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-transformer': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-logs': 0.54.2(@opentelemetry/api@1.9.0) + + '@opentelemetry/exporter-logs-otlp-http@0.54.2(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/api-logs': 0.54.2 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-exporter-base': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-transformer': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-logs': 0.54.2(@opentelemetry/api@1.9.0) + + '@opentelemetry/exporter-logs-otlp-proto@0.54.2(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/api-logs': 0.54.2 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-exporter-base': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-transformer': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/resources': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-logs': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-trace-base': 1.27.0(@opentelemetry/api@1.9.0) + + '@opentelemetry/exporter-trace-otlp-grpc@0.54.2(@opentelemetry/api@1.9.0)': + dependencies: + '@grpc/grpc-js': 1.12.2 + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-grpc-exporter-base': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-transformer': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/resources': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-trace-base': 1.27.0(@opentelemetry/api@1.9.0) + + '@opentelemetry/exporter-trace-otlp-http@0.54.2(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-exporter-base': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-transformer': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/resources': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-trace-base': 1.27.0(@opentelemetry/api@1.9.0) + + '@opentelemetry/exporter-trace-otlp-proto@0.54.2(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-exporter-base': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-transformer': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/resources': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-trace-base': 1.27.0(@opentelemetry/api@1.9.0) + + '@opentelemetry/exporter-zipkin@1.27.0(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/resources': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-trace-base': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/semantic-conventions': 1.27.0 + + '@opentelemetry/instrumentation@0.54.2(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/api-logs': 0.54.2 + '@types/shimmer': 1.2.0 + import-in-the-middle: 1.11.2 + require-in-the-middle: 7.4.0 + semver: 7.6.3 + shimmer: 1.2.1 + transitivePeerDependencies: + - supports-color + + '@opentelemetry/otlp-exporter-base@0.54.2(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-transformer': 0.54.2(@opentelemetry/api@1.9.0) + + '@opentelemetry/otlp-grpc-exporter-base@0.54.2(@opentelemetry/api@1.9.0)': + dependencies: + '@grpc/grpc-js': 1.12.2 + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-exporter-base': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/otlp-transformer': 0.54.2(@opentelemetry/api@1.9.0) + + '@opentelemetry/otlp-transformer@0.54.2(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/api-logs': 0.54.2 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/resources': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-logs': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-metrics': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-trace-base': 1.27.0(@opentelemetry/api@1.9.0) + protobufjs: 7.4.0 + + '@opentelemetry/propagator-b3@1.27.0(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + + '@opentelemetry/propagator-jaeger@1.27.0(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + + '@opentelemetry/resources@1.26.0(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.26.0(@opentelemetry/api@1.9.0) + '@opentelemetry/semantic-conventions': 1.27.0 + + '@opentelemetry/resources@1.27.0(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/semantic-conventions': 1.27.0 + + '@opentelemetry/sdk-logs@0.54.2(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/api-logs': 0.54.2 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/resources': 1.27.0(@opentelemetry/api@1.9.0) + + '@opentelemetry/sdk-metrics@1.27.0(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/resources': 1.27.0(@opentelemetry/api@1.9.0) + + '@opentelemetry/sdk-node@0.54.2(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/api-logs': 0.54.2 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/exporter-logs-otlp-grpc': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/exporter-logs-otlp-http': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/exporter-logs-otlp-proto': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/exporter-trace-otlp-grpc': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/exporter-trace-otlp-http': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/exporter-trace-otlp-proto': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/exporter-zipkin': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/instrumentation': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/resources': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-logs': 0.54.2(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-metrics': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-trace-base': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-trace-node': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/semantic-conventions': 1.27.0 + transitivePeerDependencies: + - supports-color + + '@opentelemetry/sdk-trace-base@1.27.0(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/resources': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/semantic-conventions': 1.27.0 + + '@opentelemetry/sdk-trace-node@1.27.0(@opentelemetry/api@1.9.0)': + dependencies: + '@opentelemetry/api': 1.9.0 + '@opentelemetry/context-async-hooks': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/core': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/propagator-b3': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/propagator-jaeger': 1.27.0(@opentelemetry/api@1.9.0) + '@opentelemetry/sdk-trace-base': 1.27.0(@opentelemetry/api@1.9.0) + semver: 7.6.3 + + '@opentelemetry/semantic-conventions@1.27.0': {} + '@pkgjs/parseargs@0.11.0': optional: true @@ -11774,6 +12242,29 @@ snapshots: '@prefresh/utils@1.2.0': {} + '@protobufjs/aspromise@1.1.2': {} + + '@protobufjs/base64@1.1.2': {} + + '@protobufjs/codegen@2.0.4': {} + + '@protobufjs/eventemitter@1.1.0': {} + + '@protobufjs/fetch@1.1.0': + dependencies: + '@protobufjs/aspromise': 1.1.2 + '@protobufjs/inquire': 1.1.0 + + '@protobufjs/float@1.0.2': {} + + '@protobufjs/inquire@1.1.0': {} + + '@protobufjs/path@1.1.2': {} + + '@protobufjs/pool@1.1.0': {} + + '@protobufjs/utf8@1.1.0': {} + '@rc-component/async-validator@5.0.4': dependencies: '@babel/runtime': 7.25.7 @@ -12651,6 +13142,8 @@ snapshots: '@types/node': 20.12.7 '@types/send': 0.17.4 + '@types/shimmer@1.2.0': {} + '@types/sockjs@0.3.36': dependencies: '@types/node': 20.12.7 @@ -15553,6 +16046,13 @@ snapshots: parent-module: 1.0.1 resolve-from: 4.0.0 + import-in-the-middle@1.11.2: + dependencies: + acorn: 8.11.3 + acorn-import-attributes: 1.9.5(acorn@8.11.3) + cjs-module-lexer: 1.2.3 + module-details-from-path: 1.0.3 + import-lazy@4.0.0: {} import-local@3.1.0: @@ -16441,6 +16941,8 @@ snapshots: lodash-es@4.17.21: {} + lodash.camelcase@4.3.0: {} + lodash.clonedeep@4.5.0: {} lodash.iserror@3.1.1: {} @@ -16461,6 +16963,8 @@ snapshots: strip-ansi: 7.1.0 wrap-ansi: 9.0.0 + long@5.2.3: {} + longest-streak@3.1.0: {} longest@1.0.1: {} @@ -17070,6 +17574,8 @@ snapshots: dependencies: minimist: 1.2.8 + module-details-from-path@1.0.3: {} + monaco-editor-webpack-plugin@7.1.0(monaco-editor@0.52.0)(webpack@5.94.0(@swc/core@1.7.40(@swc/helpers@0.5.13))(webpack-cli@5.1.4(webpack@5.94.0))): dependencies: loader-utils: 2.0.4 @@ -17680,6 +18186,21 @@ snapshots: proto-list@1.2.4: {} + protobufjs@7.4.0: + dependencies: + '@protobufjs/aspromise': 1.1.2 + '@protobufjs/base64': 1.1.2 + '@protobufjs/codegen': 2.0.4 + '@protobufjs/eventemitter': 1.1.0 + '@protobufjs/fetch': 1.1.0 + '@protobufjs/float': 1.0.2 + '@protobufjs/inquire': 1.1.0 + '@protobufjs/path': 1.1.2 + '@protobufjs/pool': 1.1.0 + '@protobufjs/utf8': 1.1.0 + '@types/node': 20.12.7 + long: 5.2.3 + proxy-addr@2.0.7: dependencies: forwarded: 0.2.0 @@ -18416,6 +18937,14 @@ snapshots: require-from-string@2.0.2: {} + require-in-the-middle@7.4.0: + dependencies: + debug: 4.3.7 + module-details-from-path: 1.0.3 + resolve: 1.22.8 + transitivePeerDependencies: + - supports-color + requires-port@1.0.0: {} resize-observer-polyfill@1.5.1: {} @@ -18932,6 +19461,8 @@ snapshots: shell-quote@1.8.1: {} + shimmer@1.2.1: {} + side-channel@1.0.6: dependencies: call-bind: 1.0.7 @@ -20283,6 +20814,16 @@ snapshots: y18n: 5.0.8 yargs-parser: 21.1.1 + yargs@17.7.2: + dependencies: + cliui: 8.0.1 + escalade: 3.2.0 + get-caller-file: 2.0.5 + require-directory: 2.1.1 + string-width: 4.2.3 + y18n: 5.0.8 + yargs-parser: 21.1.1 + yargs@3.10.0: dependencies: camelcase: 1.2.1