Skip to content

Commit b7c82df

Browse files
branchseerclaude
andcommitted
feat: add tracing to callbacks, NAPI entry, and JS startup
Instrument vite-plus callback implementations (handle_command, load_user_config_file, resolve), NAPI bridge (run, JS resolvers, vite config resolver), and JS startup timing for performance measurement. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ba6f596 commit b7c82df

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

packages/cli/binding/src/cli.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ impl SubcommandResolver {
277277
}
278278

279279
/// Resolve a synthesizable subcommand to a concrete program, args, cache config, and envs.
280+
#[tracing::instrument(level = "debug", skip_all)]
280281
async fn resolve(
281282
&mut self,
282283
subcommand: SynthesizableSubcommand,
@@ -602,6 +603,7 @@ impl CommandHandler for VitePlusCommandHandler {
602603
&mut self,
603604
command: &mut ScriptCommand,
604605
) -> anyhow::Result<HandledCommand> {
606+
let _span = tracing::debug_span!("handle_command").entered();
605607
// Intercept both "vp" and "vite" commands in task scripts.
606608
// "vp" is the conventional alias used in vite-plus task configs.
607609
// "vite" must also be intercepted so that `vite test`, `vite build`, etc.
@@ -655,6 +657,8 @@ impl UserConfigLoader for VitePlusConfigLoader {
655657
&self,
656658
package_path: &AbsolutePath,
657659
) -> anyhow::Result<Option<UserRunConfig>> {
660+
let _span = tracing::debug_span!("load_user_config_file").entered();
661+
658662
// Try static config extraction first (no JS runtime needed)
659663
if let Some(static_fields) = vite_static_config::resolve_static_config(package_path) {
660664
match static_fields.get("run") {
@@ -701,6 +705,7 @@ impl UserConfigLoader for VitePlusConfigLoader {
701705
}
702706

703707
/// Resolve a single subcommand and execute it, returning its exit status.
708+
#[tracing::instrument(level = "debug", skip_all)]
704709
async fn resolve_and_execute(
705710
resolver: &mut SubcommandResolver,
706711
subcommand: SynthesizableSubcommand,
@@ -742,6 +747,7 @@ async fn resolve_and_execute(
742747

743748
/// Execute a synthesizable subcommand directly (not through vite-task Session).
744749
/// No caching, no task graph, no dependency resolution.
750+
#[tracing::instrument(level = "debug", skip_all)]
745751
async fn execute_direct_subcommand(
746752
subcommand: SynthesizableSubcommand,
747753
cwd: &AbsolutePathBuf,
@@ -865,6 +871,7 @@ async fn execute_direct_subcommand(
865871
}
866872

867873
/// Execute a vite-task command (run, cache) through Session.
874+
#[tracing::instrument(level = "debug", skip_all)]
868875
async fn execute_vite_task_command(
869876
command: Command,
870877
cwd: AbsolutePathBuf,

packages/cli/binding/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ fn create_resolver(
7575
Box::new(move || {
7676
let tsf = tsf.clone();
7777
Box::pin(async move {
78+
let _span = tracing::debug_span!("js_resolver", resolver = error_message).entered();
7879
// Call JS function - map napi::Error to anyhow::Error
7980
let promise: Promise<JsCommandResolvedResult> = tsf
8081
.call_async(Ok(()))
@@ -97,6 +98,7 @@ fn create_vite_config_resolver(
9798
Arc::new(move |package_path: String| {
9899
let tsf = tsf.clone();
99100
Box::pin(async move {
101+
let _span = tracing::debug_span!("js_resolve_vite_config").entered();
100102
let promise: Promise<String> = tsf
101103
.call_async(Ok(package_path))
102104
.await
@@ -118,6 +120,7 @@ fn create_vite_config_resolver(
118120
/// and process JavaScript callbacks (via ThreadsafeFunction).
119121
#[napi]
120122
pub async fn run(options: CliOptions) -> Result<i32> {
123+
let _span = tracing::debug_span!("napi_run").entered();
121124
// Use provided cwd or current directory
122125
let mut cwd = current_dir()?;
123126
if let Some(options_cwd) = options.cwd {

packages/cli/src/bin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* If no local installation is found, this global dist/bin.js is used as fallback.
1111
*/
1212

13+
const jsStartTime = performance.now();
14+
1315
import { run } from '../binding/index.js';
1416
import { doc } from './resolve-doc.js';
1517
import { fmt } from './resolve-fmt.js';
@@ -43,6 +45,11 @@ if (command === 'create') {
4345
await import('./global/version.js');
4446
} else {
4547
// All other commands — delegate to Rust core via NAPI binding
48+
if (process.env.VITE_LOG) {
49+
console.log(
50+
`[vite-plus] JS startup: ${(performance.now() - jsStartTime).toFixed(2)}ms`,
51+
);
52+
}
4653
run({
4754
lint,
4855
pack,

0 commit comments

Comments
 (0)