Skip to content

Comments

feat(napi-derive): add tracing feature for debug logging NAPI function calls#3041

Merged
Brooooooklyn merged 3 commits intomainfrom
copilot/add-tracing-feature-napi-derive
Dec 2, 2025
Merged

feat(napi-derive): add tracing feature for debug logging NAPI function calls#3041
Brooooooklyn merged 3 commits intomainfrom
copilot/add-tracing-feature-napi-derive

Conversation

Copy link
Contributor

Copilot AI commented Dec 1, 2025

  • Add tracing feature to napi-derive crate's Cargo.toml
  • Pass the tracing feature to napi-derive-backend crate
  • Add tracing feature to napi-derive-backend crate's Cargo.toml
  • Add tracing feature to napi crate's Cargo.toml and re-export from bindgen_prelude
  • Modify the code generation in fn.rs to emit tracing::debug! logs with function names when the feature is enabled
  • Add tracing for class methods in struct.rs (getters, setters, constructor)
  • Test the feature works correctly with macro expansion
  • Run code review and address feedback
  • Fix: Use JavaScript class name consistently in tracing output (added parent_js_name field to NapiFn)

Security Summary

The changes were manually reviewed and no security vulnerabilities were found. The implementation:

  • Only logs constant strings (function names) determined at compile time
  • Uses the well-established tracing crate
  • No user input is logged, preventing injection attacks
  • Feature is opt-in and doesn't affect existing behavior when disabled
Original prompt

Add a tracing featrue into napi-derive crate and logs the all NAPI function call with debug level log (omit params , only function names).


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Note

Adds an opt-in tracing feature that emits debug logs for NAPI function/class call entry points and wires the feature across crates.

  • Codegen (backend)
    • Emit tracing::debug! at NAPI function entry points and error-thunk wrappers; includes class context via parent_js_name.
    • Class support: log constructor, getters, and setters.
    • Add NapiFn.parent_js_name and plumb it from parser for accurate JS names.
  • Features
    • Add tracing feature to napi-derive-backend, napi-derive, and napi crates; guarded code paths when disabled.
    • napi re-exports tracing from bindgen_prelude and adds optional tracing dependency.

Written by Cursor Bugbot for commit 23a25d4. This will update automatically on new commits. Configure here.

@graphite-app
Copy link

graphite-app bot commented Dec 1, 2025

How to use the Graphite Merge Queue

Add the label ready-to-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@coderabbitai
Copy link

coderabbitai bot commented Dec 1, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI changed the title [WIP] Add tracing feature to log NAPI function calls feat(napi-derive): add tracing feature for debug logging NAPI function calls Dec 1, 2025
Copilot AI requested a review from Brooooooklyn December 1, 2025 11:37
@Brooooooklyn Brooooooklyn marked this pull request as ready for review December 2, 2025 03:42
@Brooooooklyn
Copy link
Member

cursor review

@Brooooooklyn
Copy link
Member

Bug: Inconsistent class name in tracing output for methods
The gen_tracing_debug function in fn.rs uses the Rust Ident for the parent class name (via self.parent), while the equivalent function in struct.rs uses the JavaScript class name (self.js_name). This causes inconsistent tracing output: methods will log RustStructName::jsMethodName while constructors/getters/setters log JSClassName::constructor. For structs with custom JS names like #[napi(js_name = "MyJSClass")] struct MyRustStruct, the tracing output will be mixed. The PR description indicates the JavaScript name should be used consistently.

@copilot

Copy link
Contributor Author

Copilot AI commented Dec 2, 2025

Bug: Inconsistent class name in tracing output for methods
The gen_tracing_debug function in fn.rs uses the Rust Ident for the parent class name (via self.parent), while the equivalent function ...

Fixed in 23a25d4. Added parent_js_name: Option<String> field to NapiFn and updated the tracing code to use it instead of the Rust Ident. Now methods will consistently use the JavaScript class name (e.g., MyJSClass::myMethod instead of MyRustStruct::myMethod).

@Brooooooklyn
Copy link
Member

cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no bugs!


@Brooooooklyn Brooooooklyn merged commit a673471 into main Dec 2, 2025
75 of 134 checks passed
@Brooooooklyn Brooooooklyn deleted the copilot/add-tracing-feature-napi-derive branch December 2, 2025 06:20
@github-actions github-actions bot mentioned this pull request Dec 2, 2025
graphite-app bot pushed a commit to rolldown/rolldown that referenced this pull request Dec 3, 2025
close #7287
refs #7317, napi-rs/napi-rs#3041

With this change, I get the tracing output:

```
$env:RD_LOG="napi=trace"; pnpm build

> @example/typescript@ build D:\documents\GitHub\rolldown\examples\basic-typescript
> rolldown --config ./rolldown.config.js

  2025-12-03T03:05:29.770480Z DEBUG napi: BindingBundler::constructor
    at crates\rolldown_binding\src\binding_bundler.rs:26

  2025-12-03T03:05:29.772016Z DEBUG napi: BindingBundler::write
    at crates\rolldown_binding\src\binding_bundler.rs:26

  2025-12-03T03:05:29.786956Z DEBUG napi: BindingRenderedChunkMeta::chunks
    at crates\rolldown_binding\src\options\plugin\types\binding_render_chunk_meta_chunks.rs:15

  2025-12-03T03:05:29.788489Z DEBUG napi: BindingBundler::close
    at crates\rolldown_binding\src\binding_bundler.rs:26

  2025-12-03T03:05:29.788696Z DEBUG napi: shutdownAsyncRuntime
    at crates\rolldown_binding\src\lib.rs:79

  2025-12-03T03:05:29.788905Z DEBUG napi: BindingOutputChunk::getFileName
    at crates\rolldown_binding\src\types\binding_output_chunk.rs:17

  2025-12-03T03:05:29.789008Z DEBUG napi: BindingOutputChunk::getCode
    at crates\rolldown_binding\src\types\binding_output_chunk.rs:17

<DIR>/entry.js  chunk │ size: 0.23 kB

✔ rolldown v1.0.0-beta.52 Finished in 21.24 ms
```
(note: I had to comment out `debug` option, otherwise I got `failed to set global default subscriber: SetGlobalDefaultError("a global default trace dispatcher has already been set")` error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants