fix(instrumentations): preserve asyncEnd wait with code-transformer 0.16#9256
Conversation
Code-transformer 0.16 changes the generated native-Promise fulfillment handler to return `__apm$ctx.result` instead of the local `result`, so `waitForAsyncEnd` — which located the return by matching an identifier named `result` — stopped matching and silently skipped injecting the `asyncEndPromise` wait. Playwright RUM `Page.goto` tagging that relies on that wait would then miss tags when a page closes immediately. The transform now reuses the fulfillment handler's actual return argument, so it keeps injecting across the shape change and resolves to the value a subscriber may reassign on `__apm$ctx.result` in `asyncEnd`. Bump the vendored @apm-js-collab/code-transformer from 0.15.0 to 0.16.0. Refs: nodejs/orchestrion-js#85
Overall package sizeSelf size: 6.65 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.1 | 122.62 kB | 437.94 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
|
BenchmarksBenchmark execution time: 2026-07-08 10:28:42 Comparing candidate commit b0cbedc in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2305 metrics, 53 unstable metrics.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9256 +/- ##
==========================================
- Coverage 96.54% 96.12% -0.43%
==========================================
Files 915 915
Lines 121018 121032 +14
Branches 20693 20931 +238
==========================================
- Hits 116837 116342 -495
- Misses 4181 4690 +509
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Keep the `findIndex` result instead of re-scanning `statements` with `indexOf` for the same node, and deep-clone the reused return argument with the vendored `rfdc` (the repo's standard clone) rather than `structuredClone`.
…ling The `tracePromise` fulfillment handler the transform splices into always ends in a value-returning statement, so the early-return-on-miss branch was unreachable defensive code the tests could not exercise. Assert the invariant instead: a miss can only mean the upstream code-transformer template changed, and the assertion surfaces that loudly through the caller's try/catch (which falls back to the unwrapped source) rather than throwing an opaque TypeError from the splice.
….16 (#9256) Code-transformer 0.16 changes the generated native-Promise fulfillment handler to return `__apm$ctx.result` instead of the local `result`, so `waitForAsyncEnd` — which located the return by matching an identifier named `result` — stopped matching and silently skipped injecting the `asyncEndPromise` wait. Playwright RUM `Page.goto` tagging that relies on that wait would then miss tags when a page closes immediately. The transform now reuses the fulfillment handler's actual return argument, so it keeps injecting across the shape change and resolves to the value a subscriber may reassign on `__apm$ctx.result` in `asyncEnd`. Bump the vendored @apm-js-collab/code-transformer from 0.15.0 to 0.16.0. Refs: nodejs/orchestrion-js#85
….16 (#9256) Code-transformer 0.16 changes the generated native-Promise fulfillment handler to return `__apm$ctx.result` instead of the local `result`, so `waitForAsyncEnd` — which located the return by matching an identifier named `result` — stopped matching and silently skipped injecting the `asyncEndPromise` wait. Playwright RUM `Page.goto` tagging that relies on that wait would then miss tags when a page closes immediately. The transform now reuses the fulfillment handler's actual return argument, so it keeps injecting across the shape change and resolves to the value a subscriber may reassign on `__apm$ctx.result` in `asyncEnd`. Bump the vendored @apm-js-collab/code-transformer from 0.15.0 to 0.16.0. Refs: nodejs/orchestrion-js#85
Summary
Code-transformer 0.16 changes the generated native-Promise fulfillment handler to return
__apm$ctx.resultinstead of the localresult.waitForAsyncEndlocated the return by matching an identifier namedresult, so on 0.16 it stops matching and silently skips injecting theasyncEndPromisewait — the Playwright RUMPage.gototagging that depends on it then misses tags when a page closes immediately, and theshould wait for an asyncEnd promise when configuredrewriter spec fails.waitForAsyncEndnow reuses the fulfillment handler's actual return argument instead of a hard-codedresultidentifier, so it keeps injecting across the shape change and resolves to the value a subscriber may reassign on__apm$ctx.resultinasyncEnd.@apm-js-collab/code-transformerfrom 0.15.0 to 0.16.0.Refs: nodejs/orchestrion-js#85