import { ContextManagementToken } from "./types.mjs"; import { Context, ContextManager } from "@opentelemetry/api"; //#region src/AsyncLocalStorageContextManager.d.ts declare class AsyncLocalStorageContextManager implements ContextManager { private readonly _kOtListeners; private _wrapped; private _asyncLocalStorage; constructor(); active(): Context; with ReturnType>(context: Context, fn: F, thisArg?: ThisParameterType, ...args: A): ReturnType; /** * Binds a the certain context or the active one to the target function and then returns the target * @param context A context (span) to be bind to target * @param target a function or event emitter. When target or one of its callbacks is called, * the provided context will be used as the active context for the duration of the call. */ bind(context: Context, target: T): T; private _bindFunction; /** * By default, EventEmitter call their callback with their context, which we do * not want, instead we will bind a specific context to all callbacks that * go through it. * @param context the context we want to bind * @param ee EventEmitter an instance of EventEmitter to patch */ private _bindEventEmitter; /** * Patch methods that remove a given listener so that we match the "patched" * version of that listener (the one that propagate context). * @param ee EventEmitter instance * @param original reference to the patched method */ private _patchRemoveListener; /** * Patch methods that remove all listeners so we remove our * internal references for a given event. * @param ee EventEmitter instance * @param original reference to the patched method */ private _patchRemoveAllListeners; /** * Patch methods on an event emitter instance that can add listeners so we * can force them to propagate a given context. * @param ee EventEmitter instance * @param original reference to the patched method * @param [context] context to propagate when calling listeners */ private _patchAddListener; private _createPatchMap; private _getPatchMap; enable(): this; disable(): this; /** * Imperatively sets `context` as active for the current async execution chain * and operations spawned from it. Returns a {@link ContextManagementToken} whose `dispose()` * restores the previous context (see {@link ContextManager.attach}). * * On Node.js 25.9+, delegates to `AsyncLocalStorage.withScope()` which returns * a native `RunScope`. On older Node.js versions, falls back to `enterWith()` with * a manual token. * * **Caveat for async functions:** Both `withScope()` and `enterWith()` affect the * entire current async execution chain. If `attach()` is called inside an async * function before the first `await`, the context change will leak into the caller's * context and remain active there until something else restores it. Prefer `with()` * for async code. * * @experimental This API is experimental and may change in minor releases without prior notice. */ attach(context: Context): ContextManagementToken; } //#endregion export { AsyncLocalStorageContextManager }; //# sourceMappingURL=AsyncLocalStorageContextManager.d.mts.map