Experimental
Imperatively sets context as active for the current async execution chain
and operations spawned from it. Returns a ContextManagementToken whose dispose()
restores the previous context (see 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.
This API is experimental and may change in minor releases without prior notice.
Binds a the certain context or the active one to the target function and then returns the target
A context (span) to be bind to 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.
Disable context management
Enable context management
Get the current active context