UNPKG

@dynatrace/js-runtime

Version:

This package provides the Dynatrace JavaScript runtime used by the [Dynatrace App Toolkit](https://www.npmjs.com/package/dt-app).

617 lines (615 loc) 31.8 kB
/** * This module is not supported by the Dynatrace JavaScript Runtime and only * exists for its referenced types. * See the `Node.js Compatibility` section for more information. * @see https://dt-url.net/runtime-apis */ // DT-disabled // /** // DT-disabled // * We strongly discourage the use of the `async_hooks` API. // DT-disabled // * Other APIs that can cover most of its use cases include: // DT-disabled // * // DT-disabled // * * [`AsyncLocalStorage`](https://nodejs.org/docs/latest-v22.x/api/async_context.html#class-asynclocalstorage) tracks async context // DT-disabled // * * [`process.getActiveResourcesInfo()`](https://nodejs.org/docs/latest-v22.x/api/process.html#processgetactiveresourcesinfo) tracks active resources // DT-disabled // * // DT-disabled // * The `node:async_hooks` module provides an API to track asynchronous resources. // DT-disabled // * It can be accessed using: // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * import async_hooks from 'node:async_hooks'; // DT-disabled // * ``` // DT-disabled // * @experimental // DT-disabled // * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/async_hooks.js) // DT-disabled // */ declare module "async_hooks" { // DT-disabled // /** // DT-disabled // * ```js // DT-disabled // * import { executionAsyncId } from 'node:async_hooks'; // DT-disabled // * import fs from 'node:fs'; // DT-disabled // * // DT-disabled // * console.log(executionAsyncId()); // 1 - bootstrap // DT-disabled // * const path = '.'; // DT-disabled // * fs.open(path, 'r', (err, fd) => { // DT-disabled // * console.log(executionAsyncId()); // 6 - open() // DT-disabled // * }); // DT-disabled // * ``` // DT-disabled // * // DT-disabled // * The ID returned from `executionAsyncId()` is related to execution timing, not // DT-disabled // * causality (which is covered by `triggerAsyncId()`): // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * const server = net.createServer((conn) => { // DT-disabled // * // Returns the ID of the server, not of the new connection, because the // DT-disabled // * // callback runs in the execution scope of the server's MakeCallback(). // DT-disabled // * async_hooks.executionAsyncId(); // DT-disabled // * // DT-disabled // * }).listen(port, () => { // DT-disabled // * // Returns the ID of a TickObject (process.nextTick()) because all // DT-disabled // * // callbacks passed to .listen() are wrapped in a nextTick(). // DT-disabled // * async_hooks.executionAsyncId(); // DT-disabled // * }); // DT-disabled // * ``` // DT-disabled // * // DT-disabled // * Promise contexts may not get precise `executionAsyncIds` by default. // DT-disabled // * See the section on [promise execution tracking](https://nodejs.org/docs/latest-v22.x/api/async_hooks.html#promise-execution-tracking). // DT-disabled // * @since v8.1.0 // DT-disabled // * @return The `asyncId` of the current execution context. Useful to track when something calls. // DT-disabled // */ // DT-disabled // function executionAsyncId(): number; // DT-disabled // /** // DT-disabled // * Resource objects returned by `executionAsyncResource()` are most often internal // DT-disabled // * Node.js handle objects with undocumented APIs. Using any functions or properties // DT-disabled // * on the object is likely to crash your application and should be avoided. // DT-disabled // * // DT-disabled // * Using `executionAsyncResource()` in the top-level execution context will // DT-disabled // * return an empty object as there is no handle or request object to use, // DT-disabled // * but having an object representing the top-level can be helpful. // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * import { open } from 'node:fs'; // DT-disabled // * import { executionAsyncId, executionAsyncResource } from 'node:async_hooks'; // DT-disabled // * // DT-disabled // * console.log(executionAsyncId(), executionAsyncResource()); // 1 {} // DT-disabled // * open(new URL(import.meta.url), 'r', (err, fd) => { // DT-disabled // * console.log(executionAsyncId(), executionAsyncResource()); // 7 FSReqWrap // DT-disabled // * }); // DT-disabled // * ``` // DT-disabled // * // DT-disabled // * This can be used to implement continuation local storage without the // DT-disabled // * use of a tracking `Map` to store the metadata: // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * import { createServer } from 'node:http'; // DT-disabled // * import { // DT-disabled // * executionAsyncId, // DT-disabled // * executionAsyncResource, // DT-disabled // * createHook, // DT-disabled // * } from 'node:async_hooks'; // DT-disabled // * const sym = Symbol('state'); // Private symbol to avoid pollution // DT-disabled // * // DT-disabled // * createHook({ // DT-disabled // * init(asyncId, type, triggerAsyncId, resource) { // DT-disabled // * const cr = executionAsyncResource(); // DT-disabled // * if (cr) { // DT-disabled // * resource[sym] = cr[sym]; // DT-disabled // * } // DT-disabled // * }, // DT-disabled // * }).enable(); // DT-disabled // * // DT-disabled // * const server = createServer((req, res) => { // DT-disabled // * executionAsyncResource()[sym] = { state: req.url }; // DT-disabled // * setTimeout(function() { // DT-disabled // * res.end(JSON.stringify(executionAsyncResource()[sym])); // DT-disabled // * }, 100); // DT-disabled // * }).listen(3000); // DT-disabled // * ``` // DT-disabled // * @since v13.9.0, v12.17.0 // DT-disabled // * @return The resource representing the current execution. Useful to store data within the resource. // DT-disabled // */ // DT-disabled // function executionAsyncResource(): object; // DT-disabled // /** // DT-disabled // * ```js // DT-disabled // * const server = net.createServer((conn) => { // DT-disabled // * // The resource that caused (or triggered) this callback to be called // DT-disabled // * // was that of the new connection. Thus the return value of triggerAsyncId() // DT-disabled // * // is the asyncId of "conn". // DT-disabled // * async_hooks.triggerAsyncId(); // DT-disabled // * // DT-disabled // * }).listen(port, () => { // DT-disabled // * // Even though all callbacks passed to .listen() are wrapped in a nextTick() // DT-disabled // * // the callback itself exists because the call to the server's .listen() // DT-disabled // * // was made. So the return value would be the ID of the server. // DT-disabled // * async_hooks.triggerAsyncId(); // DT-disabled // * }); // DT-disabled // * ``` // DT-disabled // * // DT-disabled // * Promise contexts may not get valid `triggerAsyncId`s by default. See // DT-disabled // * the section on [promise execution tracking](https://nodejs.org/docs/latest-v22.x/api/async_hooks.html#promise-execution-tracking). // DT-disabled // * @return The ID of the resource responsible for calling the callback that is currently being executed. // DT-disabled // */ // DT-disabled // function triggerAsyncId(): number; // DT-disabled // interface HookCallbacks { // DT-disabled // /** // DT-disabled // * Called when a class is constructed that has the possibility to emit an asynchronous event. // DT-disabled // * @param asyncId A unique ID for the async resource // DT-disabled // * @param type The type of the async resource // DT-disabled // * @param triggerAsyncId The unique ID of the async resource in whose execution context this async resource was created // DT-disabled // * @param resource Reference to the resource representing the async operation, needs to be released during destroy // DT-disabled // */ // DT-disabled // init?(asyncId: number, type: string, triggerAsyncId: number, resource: object): void; // DT-disabled // /** // DT-disabled // * When an asynchronous operation is initiated or completes a callback is called to notify the user. // DT-disabled // * The before callback is called just before said callback is executed. // DT-disabled // * @param asyncId the unique identifier assigned to the resource about to execute the callback. // DT-disabled // */ // DT-disabled // before?(asyncId: number): void; // DT-disabled // /** // DT-disabled // * Called immediately after the callback specified in `before` is completed. // DT-disabled // * // DT-disabled // * If an uncaught exception occurs during execution of the callback, then `after` will run after the `'uncaughtException'` event is emitted or a `domain`'s handler runs. // DT-disabled // * @param asyncId the unique identifier assigned to the resource which has executed the callback. // DT-disabled // */ // DT-disabled // after?(asyncId: number): void; // DT-disabled // /** // DT-disabled // * Called when a promise has resolve() called. This may not be in the same execution id // DT-disabled // * as the promise itself. // DT-disabled // * @param asyncId the unique id for the promise that was resolve()d. // DT-disabled // */ // DT-disabled // promiseResolve?(asyncId: number): void; // DT-disabled // /** // DT-disabled // * Called after the resource corresponding to asyncId is destroyed // DT-disabled // * @param asyncId a unique ID for the async resource // DT-disabled // */ // DT-disabled // destroy?(asyncId: number): void; // DT-disabled // } // DT-disabled // interface AsyncHook { // DT-disabled // /** // DT-disabled // * Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop. // DT-disabled // */ // DT-disabled // enable(): this; // DT-disabled // /** // DT-disabled // * Disable the callbacks for a given AsyncHook instance from the global pool of AsyncHook callbacks to be executed. Once a hook has been disabled it will not be called again until enabled. // DT-disabled // */ // DT-disabled // disable(): this; // DT-disabled // } // DT-disabled // /** // DT-disabled // * Registers functions to be called for different lifetime events of each async // DT-disabled // * operation. // DT-disabled // * // DT-disabled // * The callbacks `init()`/`before()`/`after()`/`destroy()` are called for the // DT-disabled // * respective asynchronous event during a resource's lifetime. // DT-disabled // * // DT-disabled // * All callbacks are optional. For example, if only resource cleanup needs to // DT-disabled // * be tracked, then only the `destroy` callback needs to be passed. The // DT-disabled // * specifics of all functions that can be passed to `callbacks` is in the `Hook Callbacks` section. // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * import { createHook } from 'node:async_hooks'; // DT-disabled // * // DT-disabled // * const asyncHook = createHook({ // DT-disabled // * init(asyncId, type, triggerAsyncId, resource) { }, // DT-disabled // * destroy(asyncId) { }, // DT-disabled // * }); // DT-disabled // * ``` // DT-disabled // * // DT-disabled // * The callbacks will be inherited via the prototype chain: // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * class MyAsyncCallbacks { // DT-disabled // * init(asyncId, type, triggerAsyncId, resource) { } // DT-disabled // * destroy(asyncId) {} // DT-disabled // * } // DT-disabled // * // DT-disabled // * class MyAddedCallbacks extends MyAsyncCallbacks { // DT-disabled // * before(asyncId) { } // DT-disabled // * after(asyncId) { } // DT-disabled // * } // DT-disabled // * // DT-disabled // * const asyncHook = async_hooks.createHook(new MyAddedCallbacks()); // DT-disabled // * ``` // DT-disabled // * // DT-disabled // * Because promises are asynchronous resources whose lifecycle is tracked // DT-disabled // * via the async hooks mechanism, the `init()`, `before()`, `after()`, and`destroy()` callbacks _must not_ be async functions that return promises. // DT-disabled // * @since v8.1.0 // DT-disabled // * @param callbacks The `Hook Callbacks` to register // DT-disabled // * @return Instance used for disabling and enabling hooks // DT-disabled // */ // DT-disabled // function createHook(callbacks: HookCallbacks): AsyncHook; interface AsyncResourceOptions { /** * The ID of the execution context that created this async event. * @default executionAsyncId() */ triggerAsyncId?: number | undefined; /** * Disables automatic `emitDestroy` when the object is garbage collected. * This usually does not need to be set (even if `emitDestroy` is called * manually), unless the resource's `asyncId` is retrieved and the * sensitive API's `emitDestroy` is called with it. * @default false */ requireManualDestroy?: boolean | undefined; } /** * The class `AsyncResource` is designed to be extended by the embedder's async * resources. Using this, users can easily trigger the lifetime events of their * own resources. * * The `init` hook will trigger when an `AsyncResource` is instantiated. * * The following is an overview of the `AsyncResource` API. * * ```js * import { AsyncResource, executionAsyncId } from 'node:async_hooks'; * * // AsyncResource() is meant to be extended. Instantiating a * // new AsyncResource() also triggers init. If triggerAsyncId is omitted then * // async_hook.executionAsyncId() is used. * const asyncResource = new AsyncResource( * type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false }, * ); * * // Run a function in the execution context of the resource. This will * // * establish the context of the resource * // * trigger the AsyncHooks before callbacks * // * call the provided function `fn` with the supplied arguments * // * trigger the AsyncHooks after callbacks * // * restore the original execution context * asyncResource.runInAsyncScope(fn, thisArg, ...args); * * // Call AsyncHooks destroy callbacks. * asyncResource.emitDestroy(); * * // Return the unique ID assigned to the AsyncResource instance. * asyncResource.asyncId(); * * // Return the trigger ID for the AsyncResource instance. * asyncResource.triggerAsyncId(); * ``` */ class AsyncResource { /** * AsyncResource() is meant to be extended. Instantiating a * new AsyncResource() also triggers init. If triggerAsyncId is omitted then * async_hook.executionAsyncId() is used. * @param type The type of async event. * @param triggerAsyncId The ID of the execution context that created * this async event (default: `executionAsyncId()`), or an * AsyncResourceOptions object (since v9.3.0) */ constructor(type: string, triggerAsyncId?: number | AsyncResourceOptions); /** * Binds the given function to the current execution context. * @since v14.8.0, v12.19.0 * @param fn The function to bind to the current execution context. * @param type An optional name to associate with the underlying `AsyncResource`. */ static bind<Func extends (this: ThisArg, ...args: any[]) => any, ThisArg>( fn: Func, type?: string, thisArg?: ThisArg, ): Func; /** * Binds the given function to execute to this `AsyncResource`'s scope. * @since v14.8.0, v12.19.0 * @param fn The function to bind to the current `AsyncResource`. */ bind<Func extends (...args: any[]) => any>(fn: Func): Func; /** * Call the provided function with the provided arguments in the execution context * of the async resource. This will establish the context, trigger the AsyncHooks * before callbacks, call the function, trigger the AsyncHooks after callbacks, and * then restore the original execution context. * @since v9.6.0 * @param fn The function to call in the execution context of this async resource. * @param thisArg The receiver to be used for the function call. * @param args Optional arguments to pass to the function. */ runInAsyncScope<This, Result>( fn: (this: This, ...args: any[]) => Result, thisArg?: This, ...args: any[] ): Result; /** * Call all `destroy` hooks. This should only ever be called once. An error will * be thrown if it is called more than once. This **must** be manually called. If * the resource is left to be collected by the GC then the `destroy` hooks will * never be called. * @return A reference to `asyncResource`. */ emitDestroy(): this; /** * @return The unique `asyncId` assigned to the resource. */ asyncId(): number; /** * @return The same `triggerAsyncId` that is passed to the `AsyncResource` constructor. */ triggerAsyncId(): number; } // DT-disabled // /** // DT-disabled // * This class creates stores that stay coherent through asynchronous operations. // DT-disabled // * // DT-disabled // * While you can create your own implementation on top of the `node:async_hooks` module, `AsyncLocalStorage` should be preferred as it is a performant and memory // DT-disabled // * safe implementation that involves significant optimizations that are non-obvious // DT-disabled // * to implement. // DT-disabled // * // DT-disabled // * The following example uses `AsyncLocalStorage` to build a simple logger // DT-disabled // * that assigns IDs to incoming HTTP requests and includes them in messages // DT-disabled // * logged within each request. // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * import http from 'node:http'; // DT-disabled // * import { AsyncLocalStorage } from 'node:async_hooks'; // DT-disabled // * // DT-disabled // * const asyncLocalStorage = new AsyncLocalStorage(); // DT-disabled // * // DT-disabled // * function logWithId(msg) { // DT-disabled // * const id = asyncLocalStorage.getStore(); // DT-disabled // * console.log(`${id !== undefined ? id : '-'}:`, msg); // DT-disabled // * } // DT-disabled // * // DT-disabled // * let idSeq = 0; // DT-disabled // * http.createServer((req, res) => { // DT-disabled // * asyncLocalStorage.run(idSeq++, () => { // DT-disabled // * logWithId('start'); // DT-disabled // * // Imagine any chain of async operations here // DT-disabled // * setImmediate(() => { // DT-disabled // * logWithId('finish'); // DT-disabled // * res.end(); // DT-disabled // * }); // DT-disabled // * }); // DT-disabled // * }).listen(8080); // DT-disabled // * // DT-disabled // * http.get('http://localhost:8080'); // DT-disabled // * http.get('http://localhost:8080'); // DT-disabled // * // Prints: // DT-disabled // * // 0: start // DT-disabled // * // 1: start // DT-disabled // * // 0: finish // DT-disabled // * // 1: finish // DT-disabled // * ``` // DT-disabled // * // DT-disabled // * Each instance of `AsyncLocalStorage` maintains an independent storage context. // DT-disabled // * Multiple instances can safely exist simultaneously without risk of interfering // DT-disabled // * with each other's data. // DT-disabled // * @since v13.10.0, v12.17.0 // DT-disabled // */ // DT-disabled // class AsyncLocalStorage<T> { // DT-disabled // /** // DT-disabled // * Binds the given function to the current execution context. // DT-disabled // * @since v19.8.0 // DT-disabled // * @param fn The function to bind to the current execution context. // DT-disabled // * @return A new function that calls `fn` within the captured execution context. // DT-disabled // */ // DT-disabled // static bind<Func extends (...args: any[]) => any>(fn: Func): Func; // DT-disabled // /** // DT-disabled // * Captures the current execution context and returns a function that accepts a // DT-disabled // * function as an argument. Whenever the returned function is called, it // DT-disabled // * calls the function passed to it within the captured context. // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * const asyncLocalStorage = new AsyncLocalStorage(); // DT-disabled // * const runInAsyncScope = asyncLocalStorage.run(123, () => AsyncLocalStorage.snapshot()); // DT-disabled // * const result = asyncLocalStorage.run(321, () => runInAsyncScope(() => asyncLocalStorage.getStore())); // DT-disabled // * console.log(result); // returns 123 // DT-disabled // * ``` // DT-disabled // * // DT-disabled // * AsyncLocalStorage.snapshot() can replace the use of AsyncResource for simple // DT-disabled // * async context tracking purposes, for example: // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * class Foo { // DT-disabled // * #runInAsyncScope = AsyncLocalStorage.snapshot(); // DT-disabled // * // DT-disabled // * get() { return this.#runInAsyncScope(() => asyncLocalStorage.getStore()); } // DT-disabled // * } // DT-disabled // * // DT-disabled // * const foo = asyncLocalStorage.run(123, () => new Foo()); // DT-disabled // * console.log(asyncLocalStorage.run(321, () => foo.get())); // returns 123 // DT-disabled // * ``` // DT-disabled // * @since v19.8.0 // DT-disabled // * @return A new function with the signature `(fn: (...args) : R, ...args) : R`. // DT-disabled // */ // DT-disabled // static snapshot(): <R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs) => R; // DT-disabled // /** // DT-disabled // * Disables the instance of `AsyncLocalStorage`. All subsequent calls // DT-disabled // * to `asyncLocalStorage.getStore()` will return `undefined` until `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again. // DT-disabled // * // DT-disabled // * When calling `asyncLocalStorage.disable()`, all current contexts linked to the // DT-disabled // * instance will be exited. // DT-disabled // * // DT-disabled // * Calling `asyncLocalStorage.disable()` is required before the `asyncLocalStorage` can be garbage collected. This does not apply to stores // DT-disabled // * provided by the `asyncLocalStorage`, as those objects are garbage collected // DT-disabled // * along with the corresponding async resources. // DT-disabled // * // DT-disabled // * Use this method when the `asyncLocalStorage` is not in use anymore // DT-disabled // * in the current process. // DT-disabled // * @since v13.10.0, v12.17.0 // DT-disabled // * @experimental // DT-disabled // */ // DT-disabled // disable(): void; // DT-disabled // /** // DT-disabled // * Returns the current store. // DT-disabled // * If called outside of an asynchronous context initialized by // DT-disabled // * calling `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()`, it // DT-disabled // * returns `undefined`. // DT-disabled // * @since v13.10.0, v12.17.0 // DT-disabled // */ // DT-disabled // getStore(): T | undefined; // DT-disabled // /** // DT-disabled // * Runs a function synchronously within a context and returns its // DT-disabled // * return value. The store is not accessible outside of the callback function. // DT-disabled // * The store is accessible to any asynchronous operations created within the // DT-disabled // * callback. // DT-disabled // * // DT-disabled // * The optional `args` are passed to the callback function. // DT-disabled // * // DT-disabled // * If the callback function throws an error, the error is thrown by `run()` too. // DT-disabled // * The stacktrace is not impacted by this call and the context is exited. // DT-disabled // * // DT-disabled // * Example: // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * const store = { id: 2 }; // DT-disabled // * try { // DT-disabled // * asyncLocalStorage.run(store, () => { // DT-disabled // * asyncLocalStorage.getStore(); // Returns the store object // DT-disabled // * setTimeout(() => { // DT-disabled // * asyncLocalStorage.getStore(); // Returns the store object // DT-disabled // * }, 200); // DT-disabled // * throw new Error(); // DT-disabled // * }); // DT-disabled // * } catch (e) { // DT-disabled // * asyncLocalStorage.getStore(); // Returns undefined // DT-disabled // * // The error will be caught here // DT-disabled // * } // DT-disabled // * ``` // DT-disabled // * @since v13.10.0, v12.17.0 // DT-disabled // */ // DT-disabled // run<R>(store: T, callback: () => R): R; // DT-disabled // run<R, TArgs extends any[]>(store: T, callback: (...args: TArgs) => R, ...args: TArgs): R; // DT-disabled // /** // DT-disabled // * Runs a function synchronously outside of a context and returns its // DT-disabled // * return value. The store is not accessible within the callback function or // DT-disabled // * the asynchronous operations created within the callback. Any `getStore()` call done within the callback function will always return `undefined`. // DT-disabled // * // DT-disabled // * The optional `args` are passed to the callback function. // DT-disabled // * // DT-disabled // * If the callback function throws an error, the error is thrown by `exit()` too. // DT-disabled // * The stacktrace is not impacted by this call and the context is re-entered. // DT-disabled // * // DT-disabled // * Example: // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * // Within a call to run // DT-disabled // * try { // DT-disabled // * asyncLocalStorage.getStore(); // Returns the store object or value // DT-disabled // * asyncLocalStorage.exit(() => { // DT-disabled // * asyncLocalStorage.getStore(); // Returns undefined // DT-disabled // * throw new Error(); // DT-disabled // * }); // DT-disabled // * } catch (e) { // DT-disabled // * asyncLocalStorage.getStore(); // Returns the same object or value // DT-disabled // * // The error will be caught here // DT-disabled // * } // DT-disabled // * ``` // DT-disabled // * @since v13.10.0, v12.17.0 // DT-disabled // * @experimental // DT-disabled // */ // DT-disabled // exit<R, TArgs extends any[]>(callback: (...args: TArgs) => R, ...args: TArgs): R; // DT-disabled // /** // DT-disabled // * Transitions into the context for the remainder of the current // DT-disabled // * synchronous execution and then persists the store through any following // DT-disabled // * asynchronous calls. // DT-disabled // * // DT-disabled // * Example: // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * const store = { id: 1 }; // DT-disabled // * // Replaces previous store with the given store object // DT-disabled // * asyncLocalStorage.enterWith(store); // DT-disabled // * asyncLocalStorage.getStore(); // Returns the store object // DT-disabled // * someAsyncOperation(() => { // DT-disabled // * asyncLocalStorage.getStore(); // Returns the same object // DT-disabled // * }); // DT-disabled // * ``` // DT-disabled // * // DT-disabled // * This transition will continue for the _entire_ synchronous execution. // DT-disabled // * This means that if, for example, the context is entered within an event // DT-disabled // * handler subsequent event handlers will also run within that context unless // DT-disabled // * specifically bound to another context with an `AsyncResource`. That is why `run()` should be preferred over `enterWith()` unless there are strong reasons // DT-disabled // * to use the latter method. // DT-disabled // * // DT-disabled // * ```js // DT-disabled // * const store = { id: 1 }; // DT-disabled // * // DT-disabled // * emitter.on('my-event', () => { // DT-disabled // * asyncLocalStorage.enterWith(store); // DT-disabled // * }); // DT-disabled // * emitter.on('my-event', () => { // DT-disabled // * asyncLocalStorage.getStore(); // Returns the same object // DT-disabled // * }); // DT-disabled // * // DT-disabled // * asyncLocalStorage.getStore(); // Returns undefined // DT-disabled // * emitter.emit('my-event'); // DT-disabled // * asyncLocalStorage.getStore(); // Returns the same object // DT-disabled // * ``` // DT-disabled // * @since v13.11.0, v12.17.0 // DT-disabled // * @experimental // DT-disabled // */ // DT-disabled // enterWith(store: T): void; // DT-disabled // } /** * @since v17.2.0, v16.14.0 * @return A map of provider types to the corresponding numeric id. * This map contains all the event types that might be emitted by the `async_hooks.init()` event. */ namespace asyncWrapProviders { const NONE: number; const DIRHANDLE: number; const DNSCHANNEL: number; const ELDHISTOGRAM: number; const FILEHANDLE: number; const FILEHANDLECLOSEREQ: number; const FIXEDSIZEBLOBCOPY: number; const FSEVENTWRAP: number; const FSREQCALLBACK: number; const FSREQPROMISE: number; const GETADDRINFOREQWRAP: number; const GETNAMEINFOREQWRAP: number; const HEAPSNAPSHOT: number; const HTTP2SESSION: number; const HTTP2STREAM: number; const HTTP2PING: number; const HTTP2SETTINGS: number; const HTTPINCOMINGMESSAGE: number; const HTTPCLIENTREQUEST: number; const JSSTREAM: number; const JSUDPWRAP: number; const MESSAGEPORT: number; const PIPECONNECTWRAP: number; const PIPESERVERWRAP: number; const PIPEWRAP: number; const PROCESSWRAP: number; const PROMISE: number; const QUERYWRAP: number; const SHUTDOWNWRAP: number; const SIGNALWRAP: number; const STATWATCHER: number; const STREAMPIPE: number; const TCPCONNECTWRAP: number; const TCPSERVERWRAP: number; const TCPWRAP: number; const TTYWRAP: number; const UDPSENDWRAP: number; const UDPWRAP: number; const SIGINTWATCHDOG: number; const WORKER: number; const WORKERHEAPSNAPSHOT: number; const WRITEWRAP: number; const ZLIB: number; const CHECKPRIMEREQUEST: number; const PBKDF2REQUEST: number; const KEYPAIRGENREQUEST: number; const KEYGENREQUEST: number; const KEYEXPORTREQUEST: number; const CIPHERREQUEST: number; const DERIVEBITSREQUEST: number; const HASHREQUEST: number; const RANDOMBYTESREQUEST: number; const RANDOMPRIMEREQUEST: number; const SCRYPTREQUEST: number; const SIGNREQUEST: number; const TLSWRAP: number; const VERIFYREQUEST: number; } } /** * This module is not supported by the Dynatrace JavaScript Runtime and only * exists for its referenced types. * See the `Node.js Compatibility` section for more information. * @see https://dt-url.net/runtime-apis */ declare module "node:async_hooks" { export * from "async_hooks"; }