Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enter/exit logs to napi_* calls #23995

Closed
bartlomieju opened this issue May 27, 2024 · 0 comments
Closed

Add enter/exit logs to napi_* calls #23995

bartlomieju opened this issue May 27, 2024 · 0 comments
Assignees
Labels
node compat node native extension related to the node-api (.node)

Comments

@bartlomieju
Copy link
Member

We need to have some basic mechanism to easily debug when a problem with package using Node-API occurs.

To do that I propose we add simple logging mechanism to napi_sym:

deno/cli/napi/sym/lib.rs

Lines 15 to 36 in 35e5159

pub fn napi_sym(_attr: TokenStream, item: TokenStream) -> TokenStream {
let func = syn::parse::<syn::ItemFn>(item).expect("expected a function");
let exports: SymbolExports =
serde_json::from_str(NAPI_EXPORTS).expect("failed to parse exports");
let name = &func.sig.ident;
assert!(
exports.symbols.contains(&name.to_string()),
"tools/napi/sym/symbol_exports.json is out of sync!"
);
let block = &func.block;
let inputs = &func.sig.inputs;
let generics = &func.sig.generics;
TokenStream::from(quote! {
// SAFETY: it's an NAPI function.
#[no_mangle]
pub unsafe extern "C" fn #name #generics (#inputs) -> napi_status {
#block
}
})
}

We should log when the function enters:
napi_<function_name>
and then when it exits:
napi_<function_name> - <napi_status>.

It's probably worth to add a simple counter so we can more easily trace threadsafe function calls.

To enable tracing I propose we add DENO_NAPI_TRACING=true env var.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node compat node native extension related to the node-api (.node)
Projects
None yet
Development

No branches or pull requests

2 participants