Commit 62ebcbe29e4 for nodejs

commit 62ebcbe29e4aec6e37022fdded34a7125f26f63b
Author: Matteo Collina <hello@matteocollina.com>
Date:   Wed Dec 2 17:39:01 2026 +0100

    async_hooks: runtime deprecate createHook()

    Emit DEP0215 when async_hooks.createHook() is called, as the first
    step before putting it behind a flag.

    The inspector and the node.async_hooks trace event category use an
    internal createHook() and do not emit the warning.

    Refs: https://github.com/nodejs/node/pull/61030
    Signed-off-by: Matteo Collina <hello@matteocollina.com>
    Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com>
    Assisted-by: OpenAI
    PR-URL: https://github.com/nodejs/node/pull/67271
    Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
    Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Paolo Insogna <paolo@cowtech.it>

diff --git a/doc/api/async_hooks.md b/doc/api/async_hooks.md
index ad566239cf1..bbf7aabc398 100644
--- a/doc/api/async_hooks.md
+++ b/doc/api/async_hooks.md
@@ -148,8 +148,16 @@ function promiseResolve(asyncId) { }

 <!-- YAML
 added: v8.1.0
+deprecated: REPLACEME
+changes:
+  - version: REPLACEME
+    pr-url: https://github.com/nodejs/node/pull/67271
+    description: Runtime deprecation (DEP0215).
 -->

+> Stability: 0 - Deprecated: Use [`AsyncLocalStorage`][] or
+> [Diagnostics Channel][] instead. See [DEP0215][].
+
 * `options` {Object} The [Hook Callbacks][] to register
   * `init` {Function} The [`init` callback][].
   * `before` {Function} The [`before` callback][].
@@ -960,6 +968,7 @@ The documentation for this class has moved [`AsyncResource`][].
 The documentation for this class has moved [`AsyncLocalStorage`][].

 [DEP0111]: deprecations.md#dep0111-processbinding
+[DEP0215]: deprecations.md#dep0215-async_hookscreatehook
 [Diagnostics Channel]: diagnostics_channel.md
 [Hook Callbacks]: #hook-callbacks
 [PromiseHooks]: https://docs.google.com/document/d/1rda3yKGHimKIhg5YeoAmCOtyURgsbTH_qaYR79FELlk/edit
diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md
index cd71dff0a01..a87b571a5f3 100644
--- a/doc/api/deprecations.md
+++ b/doc/api/deprecations.md
@@ -4963,6 +4963,30 @@ certificates added with [`--use-system-ca`][] or [`NODE_EXTRA_CA_CERTS`][].
 Use [`tls.getCACertificates('default')`][] to get the default CA certificates,
 or `tls.getCACertificates('bundled')` to get the bundled Mozilla CA store.

+### DEP0215: `async_hooks.createHook()`
+
+<!-- YAML
+changes:
+  - version: REPLACEME
+    pr-url: https://github.com/nodejs/node/pull/67271
+    description: Runtime deprecation.
+-->
+
+Type: Runtime
+
+[`async_hooks.createHook()`][] is deprecated. The callbacks it registers run for
+every asynchronous resource created in the process, which has a significant
+performance cost, and they expose internal implementation details that change
+between Node.js versions.
+
+Use [`AsyncLocalStorage`][] to propagate state across asynchronous operations,
+and [`diagnostics_channel`][] (in particular [`TracingChannel`][]) to observe
+operations for tracing and monitoring. [`process.getActiveResourcesInfo()`][]
+returns the types of the resources that keep the event loop alive.
+
+`async_hooks.createHook()` may be put behind a command-line flag or removed in
+a future version of Node.js.
+
 [DEP0142]: #dep0142-repl_builtinlibs
 [DEP0156]: #dep0156-aborted-property-and-abort-aborted-event-in-http
 [NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
@@ -4977,6 +5001,7 @@ or `tls.getCACertificates('bundled')` to get the bundled Mozilla CA store.
 [`--throw-deprecation`]: cli.md#--throw-deprecation
 [`--unhandled-rejections`]: cli.md#--unhandled-rejectionsmode
 [`--use-system-ca`]: cli.md#--use-system-ca
+[`AsyncLocalStorage`]: async_context.md#class-asynclocalstorage
 [`Buffer.allocUnsafeSlow(size)`]: buffer.md#static-method-bufferallocunsafeslowsize-alignment
 [`Buffer.from(array)`]: buffer.md#static-method-bufferfromarray
 [`Buffer.from(buffer)`]: buffer.md#static-method-bufferfrombuffer
@@ -4995,9 +5020,11 @@ or `tls.getCACertificates('bundled')` to get the bundled Mozilla CA store.
 [`Server.getConnections()`]: net.md#servergetconnectionscallback
 [`Server.listen({fd: <number>})`]: net.md#serverlistenhandle-backlog-callback
 [`String.prototype.toWellFormed`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toWellFormed
+[`TracingChannel`]: diagnostics_channel.md#class-tracingchannel
 [`WriteStream.open()`]: fs.md#class-fswritestream
 [`assert`]: assert.md
 [`asyncResource.runInAsyncScope()`]: async_context.md#asyncresourceruninasyncscopefn-thisarg-args
+[`async_hooks.createHook()`]: async_hooks.md#async_hookscreatehookoptions
 [`buffer.subarray`]: buffer.md#bufsubarraystart-end
 [`child_process.execFile`]: child_process.md#child_processexecfilefile-args-options-callback
 [`child_process.exec`]: child_process.md#child_processexeccommand-options-callback
@@ -5017,6 +5044,7 @@ or `tls.getCACertificates('bundled')` to get the bundled Mozilla CA store.
 [`crypto.scrypt()`]: crypto.md#cryptoscryptpassword-salt-keylen-options-callback
 [`decipher.final()`]: crypto.md#decipherfinaloutputencoding
 [`decipher.setAuthTag()`]: crypto.md#deciphersetauthtagbuffer-encoding
+[`diagnostics_channel`]: diagnostics_channel.md
 [`dirent.parentPath`]: fs.md#direntparentpath
 [`dns.lookup()`]: dns.md#dnslookuphostname-options-callback
 [`dnsPromises.lookup()`]: dns.md#dnspromiseslookuphostname-options
diff --git a/lib/async_hooks.js b/lib/async_hooks.js
index b0106020d64..4ddf38e8f55 100644
--- a/lib/async_hooks.js
+++ b/lib/async_hooks.js
@@ -22,6 +22,7 @@ const {
   ERR_INVALID_ARG_VALUE,
 } = require('internal/errors').codes;
 const {
+  deprecate,
   kEmptyObject,
 } = require('internal/util');
 const {
@@ -167,9 +168,14 @@ class AsyncHook {
 }


-function createHook(fns) {
-  return new AsyncHook(fns);
-}
+const createHook = deprecate(
+  function createHook(fns) {
+    return new AsyncHook(fns);
+  },
+  'async_hooks.createHook() is deprecated. Use AsyncLocalStorage for async ' +
+  'context tracking and diagnostics_channel for tracing instead.',
+  'DEP0215',
+);


 // Embedder API //
diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js
index eb403824edd..79354f84902 100644
--- a/lib/internal/async_hooks.js
+++ b/lib/internal/async_hooks.js
@@ -1,7 +1,11 @@
 'use strict';

 const {
+  ArrayPrototypeIncludes,
+  ArrayPrototypeIndexOf,
+  ArrayPrototypePush,
   ArrayPrototypeSlice,
+  ArrayPrototypeSplice,
   ErrorCaptureStackTrace,
   ObjectDefineProperty,
   ObjectPrototypeHasOwnProperty,
@@ -592,9 +596,63 @@ function triggerAsyncId() {

 const kNoPromiseHook = Symbol('kNoPromiseHook');

+// A minimal AsyncHook for the inspector and the node.async_hooks trace event
+// category, so that they do not go through the deprecated public
+// async_hooks.createHook(). It does not validate its arguments, does not
+// support promiseResolve, and expects init, before, after and destroy to all
+// be functions.
+class InternalAsyncHook {
+  constructor({ init, before, after, destroy, trackPromises = true }) {
+    this[init_symbol] = init;
+    this[before_symbol] = before;
+    this[after_symbol] = after;
+    this[destroy_symbol] = destroy;
+    this[kNoPromiseHook] = !trackPromises;
+  }
+
+  enable() {
+    const { 0: hooks_array, 1: hook_fields } = getHookArrays();
+    if (ArrayPrototypeIncludes(hooks_array, this))
+      return this;
+
+    const prev_kTotals = hook_fields[kTotals];
+    hook_fields[kTotals] = hook_fields[kInit] += 1;
+    hook_fields[kTotals] += hook_fields[kBefore] += 1;
+    hook_fields[kTotals] += hook_fields[kAfter] += 1;
+    hook_fields[kTotals] += hook_fields[kDestroy] += 1;
+    hook_fields[kTotals] += hook_fields[kPromiseResolve];
+    ArrayPrototypePush(hooks_array, this);
+
+    if (prev_kTotals === 0)
+      enableHooks();
+    if (!this[kNoPromiseHook])
+      updatePromiseHookMode();
+    return this;
+  }
+
+  disable() {
+    const { 0: hooks_array, 1: hook_fields } = getHookArrays();
+    const index = ArrayPrototypeIndexOf(hooks_array, this);
+    if (index === -1)
+      return this;
+
+    hook_fields[kTotals] = hook_fields[kInit] -= 1;
+    hook_fields[kTotals] += hook_fields[kBefore] -= 1;
+    hook_fields[kTotals] += hook_fields[kAfter] -= 1;
+    hook_fields[kTotals] += hook_fields[kDestroy] -= 1;
+    hook_fields[kTotals] += hook_fields[kPromiseResolve];
+    ArrayPrototypeSplice(hooks_array, index, 1);
+
+    if (hook_fields[kTotals] === 0)
+      disableHooks();
+    return this;
+  }
+}
+
 module.exports = {
   executionAsyncId,
   triggerAsyncId,
+  InternalAsyncHook,
   // Private API
   getHookArrays,
   symbols: {
diff --git a/lib/internal/inspector_async_hook.js b/lib/internal/inspector_async_hook.js
index 8ab833ea8ef..3b66ac683d2 100644
--- a/lib/internal/inspector_async_hook.js
+++ b/lib/internal/inspector_async_hook.js
@@ -5,10 +5,10 @@ let config;

 function lazyHookCreation() {
   const inspector = internalBinding('inspector');
-  const { createHook } = require('async_hooks');
+  const { InternalAsyncHook } = require('internal/async_hooks');
   config = internalBinding('config');

-  hook = createHook({
+  hook = new InternalAsyncHook({
     init(asyncId, type, triggerAsyncId, resource) {
     // It's difficult to tell which tasks will be recurring and which won't,
     // therefore we mark all tasks as recurring. Based on the discussion
diff --git a/lib/internal/trace_events_async_hooks.js b/lib/internal/trace_events_async_hooks.js
index 86de9e79647..8ddb9204fc9 100644
--- a/lib/internal/trace_events_async_hooks.js
+++ b/lib/internal/trace_events_async_hooks.js
@@ -16,7 +16,7 @@ const {
   kSyncEnd,
 } = require('internal/trace_events');
 const async_wrap = internalBinding('async_wrap');
-const async_hooks = require('async_hooks');
+const async_hooks = require('internal/async_hooks');

 const kTraceEventCategory = nodeTraceEventCategory('node.async_hooks');

@@ -38,7 +38,7 @@ function createHook() {
   // repeated. Since async_hooks doesn't expose the provider type in the
   // non-init events, use a map to manually map the asyncId to the type name.

-  const hook = async_hooks.createHook({
+  const hook = new async_hooks.InternalAsyncHook({
     init(asyncId, type, triggerAsyncId, resource) {
       if (nativeProviders.has(type)) return;

diff --git a/test/addons/async-resource/test.js b/test/addons/async-resource/test.js
index d7bc44a92be..8631cf69dfb 100644
--- a/test/addons/async-resource/test.js
+++ b/test/addons/async-resource/test.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../../common');
diff --git a/test/addons/callback-scope/test-async-hooks.js b/test/addons/callback-scope/test-async-hooks.js
index 2d1c8719b34..0165f3d84d7 100644
--- a/test/addons/callback-scope/test-async-hooks.js
+++ b/test/addons/callback-scope/test-async-hooks.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../../common');
diff --git a/test/async-hooks/test-async-await.js b/test/async-hooks/test-async-await.js
index 4fd698c8e98..3b6a921efa6 100644
--- a/test/async-hooks/test-async-await.js
+++ b/test/async-hooks/test-async-await.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 const common = require('../common');

diff --git a/test/async-hooks/test-async-local-storage-gcable.js b/test/async-hooks/test-async-local-storage-gcable.js
index 303442e60c8..535cfbab0d2 100644
--- a/test/async-hooks/test-async-local-storage-gcable.js
+++ b/test/async-hooks/test-async-local-storage-gcable.js
@@ -1,5 +1,5 @@
 'use strict';
-// Flags: --expose_gc
+// Flags: --expose_gc --no-deprecation

 // This test ensures that AsyncLocalStorage gets gced once it was disabled
 // and no strong references remain in userland.
diff --git a/test/async-hooks/test-crypto-pbkdf2.js b/test/async-hooks/test-crypto-pbkdf2.js
index c607adf7258..6519b28ffd8 100644
--- a/test/async-hooks/test-crypto-pbkdf2.js
+++ b/test/async-hooks/test-crypto-pbkdf2.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-crypto-randomBytes.js b/test/async-hooks/test-crypto-randomBytes.js
index 8ecc1c45a9a..222fc578139 100644
--- a/test/async-hooks/test-crypto-randomBytes.js
+++ b/test/async-hooks/test-crypto-randomBytes.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-disable-in-init.js b/test/async-hooks/test-disable-in-init.js
index f810dfca3b9..fbecc9ea888 100644
--- a/test/async-hooks/test-disable-in-init.js
+++ b/test/async-hooks/test-disable-in-init.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-embedder.api.async-resource-no-type.js b/test/async-hooks/test-embedder.api.async-resource-no-type.js
index e21c5458df8..5e4b002b370 100644
--- a/test/async-hooks/test-embedder.api.async-resource-no-type.js
+++ b/test/async-hooks/test-embedder.api.async-resource-no-type.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
@@ -25,7 +26,7 @@ if (process.argv[2] === 'child') {
   });

 } else {
-  const args = process.argv.slice(1).concat('child');
+  const args = [...process.execArgv, ...process.argv.slice(1), 'child'];
   spawn(process.execPath, args)
     .on('close', common.mustCall((code) => {
       // No error because the type was defaulted
diff --git a/test/async-hooks/test-embedder.api.async-resource.js b/test/async-hooks/test-embedder.api.async-resource.js
index d60c03fb87b..4474b3518a7 100644
--- a/test/async-hooks/test-embedder.api.async-resource.js
+++ b/test/async-hooks/test-embedder.api.async-resource.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-emit-init.js b/test/async-hooks/test-emit-init.js
index 8994943b472..709200531f0 100644
--- a/test/async-hooks/test-emit-init.js
+++ b/test/async-hooks/test-emit-init.js
@@ -1,5 +1,5 @@
 'use strict';
-// Flags: --expose-internals
+// Flags: --expose-internals --no-deprecation

 const common = require('../common');
 const assert = require('assert');
diff --git a/test/async-hooks/test-enable-disable.js b/test/async-hooks/test-enable-disable.js
index d408338e892..096ba377971 100644
--- a/test/async-hooks/test-enable-disable.js
+++ b/test/async-hooks/test-enable-disable.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 //  Test Steps Explained
 //  ====================
 //
diff --git a/test/async-hooks/test-enable-in-init.js b/test/async-hooks/test-enable-in-init.js
index e710657a340..d8674b9c527 100644
--- a/test/async-hooks/test-enable-in-init.js
+++ b/test/async-hooks/test-enable-in-init.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-filehandle-no-reuse.js b/test/async-hooks/test-filehandle-no-reuse.js
index f607a7a22e0..323c33402fd 100644
--- a/test/async-hooks/test-filehandle-no-reuse.js
+++ b/test/async-hooks/test-filehandle-no-reuse.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-fseventwrap.js b/test/async-hooks/test-fseventwrap.js
index a5e1a3b9d2f..a7ef4c8e787 100644
--- a/test/async-hooks/test-fseventwrap.js
+++ b/test/async-hooks/test-fseventwrap.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 const common = require('../common');

diff --git a/test/async-hooks/test-fsreqcallback-access.js b/test/async-hooks/test-fsreqcallback-access.js
index b1b75f56930..09d9b5964e3 100644
--- a/test/async-hooks/test-fsreqcallback-access.js
+++ b/test/async-hooks/test-fsreqcallback-access.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-fsreqcallback-readFile.js b/test/async-hooks/test-fsreqcallback-readFile.js
index fb84306cfa8..dda2790aaa3 100644
--- a/test/async-hooks/test-fsreqcallback-readFile.js
+++ b/test/async-hooks/test-fsreqcallback-readFile.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-getaddrinforeqwrap.js b/test/async-hooks/test-getaddrinforeqwrap.js
index a21557bcd56..82bd0dcd3ef 100644
--- a/test/async-hooks/test-getaddrinforeqwrap.js
+++ b/test/async-hooks/test-getaddrinforeqwrap.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-getnameinforeqwrap.js b/test/async-hooks/test-getnameinforeqwrap.js
index b00fa0d4d9d..39c35db98e6 100644
--- a/test/async-hooks/test-getnameinforeqwrap.js
+++ b/test/async-hooks/test-getnameinforeqwrap.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-graph.fsreq-readFile.js b/test/async-hooks/test-graph.fsreq-readFile.js
index 39435cdc489..a819fbb411a 100644
--- a/test/async-hooks/test-graph.fsreq-readFile.js
+++ b/test/async-hooks/test-graph.fsreq-readFile.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-graph.http.js b/test/async-hooks/test-graph.http.js
index 859000b14aa..9c47963b137 100644
--- a/test/async-hooks/test-graph.http.js
+++ b/test/async-hooks/test-graph.http.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-graph.intervals.js b/test/async-hooks/test-graph.intervals.js
index 9e626951a14..697ccc6b366 100644
--- a/test/async-hooks/test-graph.intervals.js
+++ b/test/async-hooks/test-graph.intervals.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-graph.pipe.js b/test/async-hooks/test-graph.pipe.js
index abf8a98ff00..ce8389c779f 100644
--- a/test/async-hooks/test-graph.pipe.js
+++ b/test/async-hooks/test-graph.pipe.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-graph.pipeconnect.js b/test/async-hooks/test-graph.pipeconnect.js
index db237ff6b2d..71e65224e8c 100644
--- a/test/async-hooks/test-graph.pipeconnect.js
+++ b/test/async-hooks/test-graph.pipeconnect.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-graph.shutdown.js b/test/async-hooks/test-graph.shutdown.js
index 0f633787e5e..736970a0e29 100644
--- a/test/async-hooks/test-graph.shutdown.js
+++ b/test/async-hooks/test-graph.shutdown.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-graph.signal.js b/test/async-hooks/test-graph.signal.js
index 351fb7550af..cb5d1fccfd7 100644
--- a/test/async-hooks/test-graph.signal.js
+++ b/test/async-hooks/test-graph.signal.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-graph.statwatcher.js b/test/async-hooks/test-graph.statwatcher.js
index f960ffebd3e..7e04ea7b85d 100644
--- a/test/async-hooks/test-graph.statwatcher.js
+++ b/test/async-hooks/test-graph.statwatcher.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 require('../common');
diff --git a/test/async-hooks/test-graph.tcp.js b/test/async-hooks/test-graph.tcp.js
index 6f8db20add6..2ccf3fdd0a2 100644
--- a/test/async-hooks/test-graph.tcp.js
+++ b/test/async-hooks/test-graph.tcp.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-graph.timeouts.js b/test/async-hooks/test-graph.timeouts.js
index 88350db2bae..cbaeea56b7d 100644
--- a/test/async-hooks/test-graph.timeouts.js
+++ b/test/async-hooks/test-graph.timeouts.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-graph.tls-write-12.js b/test/async-hooks/test-graph.tls-write-12.js
index 748234402c0..8dc433490c4 100644
--- a/test/async-hooks/test-graph.tls-write-12.js
+++ b/test/async-hooks/test-graph.tls-write-12.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-graph.tls-write.js b/test/async-hooks/test-graph.tls-write.js
index 243039e01d1..385f7547c74 100644
--- a/test/async-hooks/test-graph.tls-write.js
+++ b/test/async-hooks/test-graph.tls-write.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-http-agent-handle-reuse-parallel.js b/test/async-hooks/test-http-agent-handle-reuse-parallel.js
index 3827691cc8b..5ee2d168b7d 100644
--- a/test/async-hooks/test-http-agent-handle-reuse-parallel.js
+++ b/test/async-hooks/test-http-agent-handle-reuse-parallel.js
@@ -1,5 +1,5 @@
 'use strict';
-// Flags: --expose-internals
+// Flags: --expose-internals --no-deprecation
 const common = require('../common');
 const initHooks = require('./init-hooks');
 const { checkInvocations } = require('./hook-checks');
diff --git a/test/async-hooks/test-http-agent-handle-reuse-serial.js b/test/async-hooks/test-http-agent-handle-reuse-serial.js
index bae0698a0a6..948e90b79d3 100644
--- a/test/async-hooks/test-http-agent-handle-reuse-serial.js
+++ b/test/async-hooks/test-http-agent-handle-reuse-serial.js
@@ -1,5 +1,5 @@
 'use strict';
-// Flags: --expose-internals
+// Flags: --expose-internals --no-deprecation
 const common = require('../common');
 const initHooks = require('./init-hooks');
 const { checkInvocations } = require('./hook-checks');
diff --git a/test/async-hooks/test-httpparser.request.js b/test/async-hooks/test-httpparser.request.js
index 6379bf330d2..8799e33feea 100644
--- a/test/async-hooks/test-httpparser.request.js
+++ b/test/async-hooks/test-httpparser.request.js
@@ -1,4 +1,4 @@
-// Flags: --expose-internals --no-warnings
+// Flags: --expose-internals --no-warnings --no-deprecation

 'use strict';

diff --git a/test/async-hooks/test-httpparser.response.js b/test/async-hooks/test-httpparser.response.js
index 2e600b12747..569b8e95cb4 100644
--- a/test/async-hooks/test-httpparser.response.js
+++ b/test/async-hooks/test-httpparser.response.js
@@ -1,4 +1,4 @@
-// Flags: --expose-internals --no-warnings
+// Flags: --expose-internals --no-warnings --no-deprecation

 'use strict';

diff --git a/test/async-hooks/test-immediate.js b/test/async-hooks/test-immediate.js
index fa9475abaed..99388a8718f 100644
--- a/test/async-hooks/test-immediate.js
+++ b/test/async-hooks/test-immediate.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-nexttick-default-trigger.js b/test/async-hooks/test-nexttick-default-trigger.js
index fa1ad2c561c..c396def2e0d 100644
--- a/test/async-hooks/test-nexttick-default-trigger.js
+++ b/test/async-hooks/test-nexttick-default-trigger.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 const common = require('../common');

diff --git a/test/async-hooks/test-pipeconnectwrap.js b/test/async-hooks/test-pipeconnectwrap.js
index 36980f01859..c399f29a14c 100644
--- a/test/async-hooks/test-pipeconnectwrap.js
+++ b/test/async-hooks/test-pipeconnectwrap.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-pipewrap.js b/test/async-hooks/test-pipewrap.js
index 7ea5f38adc8..fd89d98db38 100644
--- a/test/async-hooks/test-pipewrap.js
+++ b/test/async-hooks/test-pipewrap.js
@@ -1,7 +1,7 @@
 // NOTE: this also covers process wrap as one is created along with the pipes
 // when we launch the sleep process
 'use strict';
-// Flags: --expose-gc
+// Flags: --expose-gc --no-deprecation

 const common = require('../common');
 const assert = require('assert');
diff --git a/test/async-hooks/test-promise.chain-promise-before-init-hooks.js b/test/async-hooks/test-promise.chain-promise-before-init-hooks.js
index f292c828657..2abb08748e7 100644
--- a/test/async-hooks/test-promise.chain-promise-before-init-hooks.js
+++ b/test/async-hooks/test-promise.chain-promise-before-init-hooks.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-promise.js b/test/async-hooks/test-promise.js
index 96be5e5efcb..17e1f49662e 100644
--- a/test/async-hooks/test-promise.js
+++ b/test/async-hooks/test-promise.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-querywrap.js b/test/async-hooks/test-querywrap.js
index 5ddb2fe700e..c39ee00c2cf 100644
--- a/test/async-hooks/test-querywrap.js
+++ b/test/async-hooks/test-querywrap.js
@@ -1,5 +1,5 @@
 'use strict';
-// Flags: --expose-gc
+// Flags: --expose-gc --no-deprecation

 const common = require('../common');
 const assert = require('assert');
diff --git a/test/async-hooks/test-queue-microtask.js b/test/async-hooks/test-queue-microtask.js
index 01200d45423..26ccf0c95cd 100644
--- a/test/async-hooks/test-queue-microtask.js
+++ b/test/async-hooks/test-queue-microtask.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 const common = require('../common');

diff --git a/test/async-hooks/test-shutdownwrap.js b/test/async-hooks/test-shutdownwrap.js
index fea4a3a166a..7af061b6f0e 100644
--- a/test/async-hooks/test-shutdownwrap.js
+++ b/test/async-hooks/test-shutdownwrap.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-signalwrap.js b/test/async-hooks/test-signalwrap.js
index 60adaedd476..2f6c302c14f 100644
--- a/test/async-hooks/test-signalwrap.js
+++ b/test/async-hooks/test-signalwrap.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 const common = require('../common');

diff --git a/test/async-hooks/test-statwatcher.js b/test/async-hooks/test-statwatcher.js
index d24aab58402..985abfc72be 100644
--- a/test/async-hooks/test-statwatcher.js
+++ b/test/async-hooks/test-statwatcher.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-tcpwrap.js b/test/async-hooks/test-tcpwrap.js
index 3f0987b9882..da42492e5d8 100644
--- a/test/async-hooks/test-tcpwrap.js
+++ b/test/async-hooks/test-tcpwrap.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 // Covers TCPWRAP and related TCPCONNECTWRAP
 'use strict';

diff --git a/test/async-hooks/test-timers.setInterval.js b/test/async-hooks/test-timers.setInterval.js
index 10b2bafb2a2..6d18b1f7eff 100644
--- a/test/async-hooks/test-timers.setInterval.js
+++ b/test/async-hooks/test-timers.setInterval.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-timers.setTimeout.js b/test/async-hooks/test-timers.setTimeout.js
index 540c88abade..9800bddef92 100644
--- a/test/async-hooks/test-timers.setTimeout.js
+++ b/test/async-hooks/test-timers.setTimeout.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-tlswrap.js b/test/async-hooks/test-tlswrap.js
index 6a8996e00f2..693671be7c3 100644
--- a/test/async-hooks/test-tlswrap.js
+++ b/test/async-hooks/test-tlswrap.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-track-promises-default.js b/test/async-hooks/test-track-promises-default.js
index 071f8faaecc..bc66878d402 100644
--- a/test/async-hooks/test-track-promises-default.js
+++ b/test/async-hooks/test-track-promises-default.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 // Test that trackPromises default to true.
 const common = require('../common');
diff --git a/test/async-hooks/test-track-promises-false.js b/test/async-hooks/test-track-promises-false.js
index 1a3b5eda2e2..7a9d35ad214 100644
--- a/test/async-hooks/test-track-promises-false.js
+++ b/test/async-hooks/test-track-promises-false.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 // Test that trackPromises: false works.
 const common = require('../common');
diff --git a/test/async-hooks/test-track-promises-true.js b/test/async-hooks/test-track-promises-true.js
index cc53f3a9c92..ca71629a381 100644
--- a/test/async-hooks/test-track-promises-true.js
+++ b/test/async-hooks/test-track-promises-true.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 // Test that trackPromises: true works.
 const common = require('../common');
diff --git a/test/async-hooks/test-udpsendwrap.js b/test/async-hooks/test-udpsendwrap.js
index f1403e3226a..885c1d8bedf 100644
--- a/test/async-hooks/test-udpsendwrap.js
+++ b/test/async-hooks/test-udpsendwrap.js
@@ -1,4 +1,4 @@
-// Flags: --test-udp-no-try-send
+// Flags: --test-udp-no-try-send --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-udpwrap.js b/test/async-hooks/test-udpwrap.js
index 0a0e03c5d51..1f57863b8bd 100644
--- a/test/async-hooks/test-udpwrap.js
+++ b/test/async-hooks/test-udpwrap.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-unhandled-exception-valid-ids.js b/test/async-hooks/test-unhandled-exception-valid-ids.js
index 09e5823452f..67e3f137945 100644
--- a/test/async-hooks/test-unhandled-exception-valid-ids.js
+++ b/test/async-hooks/test-unhandled-exception-valid-ids.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-unhandled-rejection-context.js b/test/async-hooks/test-unhandled-rejection-context.js
index 168b51a3331..1866cdfe0ce 100644
--- a/test/async-hooks/test-unhandled-rejection-context.js
+++ b/test/async-hooks/test-unhandled-rejection-context.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-writewrap.js b/test/async-hooks/test-writewrap.js
index 4f3455480ba..2ea5cb4ee54 100644
--- a/test/async-hooks/test-writewrap.js
+++ b/test/async-hooks/test-writewrap.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/async-hooks/test-zlib.zlib-binding.deflate.js b/test/async-hooks/test-zlib.zlib-binding.deflate.js
index 802f09eb306..c5a1b7f27fc 100644
--- a/test/async-hooks/test-zlib.zlib-binding.deflate.js
+++ b/test/async-hooks/test-zlib.zlib-binding.deflate.js
@@ -1,4 +1,4 @@
-// Flags: --expose-internals
+// Flags: --expose-internals --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/parallel/test-async-hooks-correctly-switch-promise-hook.js b/test/parallel/test-async-hooks-correctly-switch-promise-hook.js
index 73127f1ebaf..45c50a507f7 100644
--- a/test/parallel/test-async-hooks-correctly-switch-promise-hook.js
+++ b/test/parallel/test-async-hooks-correctly-switch-promise-hook.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 require('../common');
 const assert = require('assert');
diff --git a/test/parallel/test-async-hooks-create-hook-deprecation.js b/test/parallel/test-async-hooks-create-hook-deprecation.js
new file mode 100644
index 00000000000..8a2fd4c1d62
--- /dev/null
+++ b/test/parallel/test-async-hooks-create-hook-deprecation.js
@@ -0,0 +1,16 @@
+'use strict';
+
+// Calling async_hooks.createHook() emits the DEP0215 deprecation warning once.
+
+const common = require('../common');
+const { createHook } = require('async_hooks');
+
+common.expectWarning(
+  'DeprecationWarning',
+  'async_hooks.createHook() is deprecated. Use AsyncLocalStorage for async ' +
+  'context tracking and diagnostics_channel for tracing instead.',
+  'DEP0215',
+);
+
+createHook({ init() {} }).enable().disable();
+createHook({ destroy() {} });
diff --git a/test/parallel/test-async-hooks-disable-during-promise.js b/test/parallel/test-async-hooks-disable-during-promise.js
index a25dae51e1f..05c25a363f8 100644
--- a/test/parallel/test-async-hooks-disable-during-promise.js
+++ b/test/parallel/test-async-hooks-disable-during-promise.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 const common = require('../common');
 const async_hooks = require('async_hooks');
diff --git a/test/parallel/test-async-hooks-enable-before-promise-resolve.js b/test/parallel/test-async-hooks-enable-before-promise-resolve.js
index e6facfb6392..650579b5818 100644
--- a/test/parallel/test-async-hooks-enable-before-promise-resolve.js
+++ b/test/parallel/test-async-hooks-enable-before-promise-resolve.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 const common = require('../common');
 const assert = require('assert');
diff --git a/test/parallel/test-async-hooks-enable-during-promise.js b/test/parallel/test-async-hooks-enable-during-promise.js
index ce3253b01c1..37e8e992d56 100644
--- a/test/parallel/test-async-hooks-enable-during-promise.js
+++ b/test/parallel/test-async-hooks-enable-during-promise.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 const common = require('../common');
 const async_hooks = require('async_hooks');
diff --git a/test/parallel/test-async-hooks-enable-recursive.js b/test/parallel/test-async-hooks-enable-recursive.js
index 74caebbad22..d20c2594943 100644
--- a/test/parallel/test-async-hooks-enable-recursive.js
+++ b/test/parallel/test-async-hooks-enable-recursive.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 const common = require('../common');
diff --git a/test/parallel/test-async-hooks-fatal-error.js b/test/parallel/test-async-hooks-fatal-error.js
index 30ead86132f..25cb28bd079 100644
--- a/test/parallel/test-async-hooks-fatal-error.js
+++ b/test/parallel/test-async-hooks-fatal-error.js
@@ -41,7 +41,7 @@ function main() {
     for (const [valueType, expect] of valueTypes) {
       const cp = childProcess.spawnSync(
         process.execPath,
-        [ __filename, 'child', type, valueType ],
+        [ '--no-deprecation', __filename, 'child', type, valueType ],
         {
           encoding: 'utf8',
         });
diff --git a/test/parallel/test-async-hooks-promise-triggerid.js b/test/parallel/test-async-hooks-promise-triggerid.js
index 89e5bc1464f..dc627c9ace6 100644
--- a/test/parallel/test-async-hooks-promise-triggerid.js
+++ b/test/parallel/test-async-hooks-promise-triggerid.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 const common = require('../common');
 const assert = require('assert');
diff --git a/test/parallel/test-async-hooks-promise.js b/test/parallel/test-async-hooks-promise.js
index 74f72a18824..341648792e3 100644
--- a/test/parallel/test-async-hooks-promise.js
+++ b/test/parallel/test-async-hooks-promise.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 const common = require('../common');
 const assert = require('assert');
diff --git a/test/parallel/test-async-hooks-top-level-clearimmediate.js b/test/parallel/test-async-hooks-top-level-clearimmediate.js
index fd91fefa9c4..4f684c1200c 100644
--- a/test/parallel/test-async-hooks-top-level-clearimmediate.js
+++ b/test/parallel/test-async-hooks-top-level-clearimmediate.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 // Regression test for https://github.com/nodejs/node/issues/13262
diff --git a/test/parallel/test-async-wrap-promise-after-enabled.js b/test/parallel/test-async-wrap-promise-after-enabled.js
index fafb732c289..e28d4a059fe 100644
--- a/test/parallel/test-async-wrap-promise-after-enabled.js
+++ b/test/parallel/test-async-wrap-promise-after-enabled.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';

 // Regression test for https://github.com/nodejs/node/issues/13237
diff --git a/test/parallel/test-stream-writable-samecb-singletick.js b/test/parallel/test-stream-writable-samecb-singletick.js
index 9357a56535b..d4764f38d76 100644
--- a/test/parallel/test-stream-writable-samecb-singletick.js
+++ b/test/parallel/test-stream-writable-samecb-singletick.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 const common = require('../common');
 const { Console } = require('console');
diff --git a/test/parallel/test-v8-coverage.js b/test/parallel/test-v8-coverage.js
index 0306e07c6fd..4868b8de57c 100644
--- a/test/parallel/test-v8-coverage.js
+++ b/test/parallel/test-v8-coverage.js
@@ -153,6 +153,7 @@ function nextdir() {
 {
   const coverageDirectory = tmpdir.resolve(nextdir());
   const output = spawnSync(process.execPath, [
+    '--no-deprecation',
     require.resolve('../fixtures/v8-coverage/async-hooks'),
   ], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });
   if (output.status !== 0) {
diff --git a/test/parallel/test-worker-message-port-inspect-during-init-hook.js b/test/parallel/test-worker-message-port-inspect-during-init-hook.js
index d5784dceb71..445ae40620b 100644
--- a/test/parallel/test-worker-message-port-inspect-during-init-hook.js
+++ b/test/parallel/test-worker-message-port-inspect-during-init-hook.js
@@ -1,3 +1,4 @@
+// Flags: --no-deprecation
 'use strict';
 const common = require('../common');
 const util = require('util');
diff --git a/test/trace_events/test-trace-events-async-hooks.js b/test/trace_events/test-trace-events-async-hooks.js
index c404402594a..05177457c76 100644
--- a/test/trace_events/test-trace-events-async-hooks.js
+++ b/test/trace_events/test-trace-events-async-hooks.js
@@ -15,7 +15,8 @@ const {
 checkTraceProcessor();

 const CODE =
-  'setTimeout(() => { for (let i = 0; i < 100000; i++) { "test" + i } }, 1)';
+  'setTimeout(() => { for (let i = 0; i < 100000; i++) { "test" + i } }, 1);' +
+  'Promise.resolve().then(() => {});';

 const tmpdir = require('../common/tmpdir');
 tmpdir.refresh();
@@ -61,6 +62,18 @@ proc.once('exit', common.mustCall(() => {
     return true;
   }));

+  // Promises are not AsyncWrap resources, their trace events are generated
+  // from JavaScript as well.
+  assert(traces.some((trace) => {
+    if (trace.pid !== proc.pid)
+      return false;
+    if (trace.cat !== traceCategory('node.async_hooks'))
+      return false;
+    if (trace.name !== 'PROMISE')
+      return false;
+    return true;
+  }));
+
   // Check args in init events. Perfetto records the begin/end pair of an
   // async_hooks event as one complete event.
   const initPhase = common.hasPerfetto ? 'X' : 'b';