Skip to content

Commit 43de1ac

Browse files
authored
fix: Updated visit_mut_fn_decl to return true to allow walking a function to identify nested functions (#17)
1 parent a08febf commit 43de1ac

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

src/instrumentation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl Instrumentation {
226226
self.insert_tracing(body);
227227
}
228228
}
229-
false
229+
true
230230
}
231231

232232
pub fn visit_mut_var_decl(&mut self, node: &mut VarDecl) -> bool {

tests/instrumentor_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ mod index_cjs;
1717
mod injection_failure;
1818
mod multiple_class_method_cjs;
1919
mod multiple_load_cjs;
20+
mod nested_functions;
2021
mod object_method_cjs;
2122
mod polyfill_cjs;
2223
mod polyfill_mjs;

tests/nested_functions/mod.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2025 Datadog, Inc.
4+
**/
5+
6+
function fastify() {
7+
const fastify = {
8+
addHook
9+
}
10+
11+
function addHook() {
12+
return 'Hook added';
13+
}
14+
15+
return fastify
16+
}
17+
18+
module.exports = fastify;

tests/nested_functions/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use crate::common::*;
2+
use orchestrion_js::*;
3+
4+
#[test]
5+
fn nested_fn() {
6+
transpile_and_test(
7+
file!(),
8+
false,
9+
Config::new_single(InstrumentationConfig::new(
10+
"nested_fn",
11+
test_module_matcher(),
12+
FunctionQuery::function_declaration("addHook", FunctionKind::Sync),
13+
)),
14+
);
15+
}

tests/nested_functions/test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2025 Datadog, Inc.
4+
**/
5+
const fastify = require('./instrumented.js');
6+
const { assert, getContext } = require('../common/preamble.js');
7+
const context = getContext('orchestrion:undici:nested_fn');
8+
(async () => {
9+
const f = fastify()
10+
const result = f.addHook()
11+
assert.strictEqual(result, 'Hook added');
12+
assert.deepStrictEqual(context, {
13+
start: true,
14+
end: true,
15+
});
16+
})();

0 commit comments

Comments
 (0)