Skip to content

Commit b241e19

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 1b43995 commit b241e19

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

packages/cli/binding/src/cli.rs

Lines changed: 6 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,7 @@ 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();
658661
let package_path_str = package_path
659662
.as_path()
660663
.to_str()
@@ -675,6 +678,7 @@ impl UserConfigLoader for VitePlusConfigLoader {
675678
}
676679

677680
/// Resolve a single subcommand and execute it, returning its exit status.
681+
#[tracing::instrument(level = "debug", skip_all)]
678682
async fn resolve_and_execute(
679683
resolver: &mut SubcommandResolver,
680684
subcommand: SynthesizableSubcommand,
@@ -716,6 +720,7 @@ async fn resolve_and_execute(
716720

717721
/// Execute a synthesizable subcommand directly (not through vite-task Session).
718722
/// No caching, no task graph, no dependency resolution.
723+
#[tracing::instrument(level = "debug", skip_all)]
719724
async fn execute_direct_subcommand(
720725
subcommand: SynthesizableSubcommand,
721726
cwd: &AbsolutePathBuf,
@@ -839,6 +844,7 @@ async fn execute_direct_subcommand(
839844
}
840845

841846
/// Execute a vite-task command (run, cache) through Session.
847+
#[tracing::instrument(level = "debug", skip_all)]
842848
async fn execute_vite_task_command(
843849
command: Command,
844850
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)