Get the currently active context
Experimental
Imperatively sets context as active, returning a ContextManagementToken whose
ContextManagementToken.dispose restores the previous context.
This is a delicate, low-level API - prefer with/bind, which
restore context automatically. Use attach only to bridge callback
boundaries that with cannot wrap. Call token.dispose() when the
operation is done.
Caveat for async functions: If called inside an async function before
the first await, the context change may leak into the caller's context
and remain active there. Prefer with for async code.
Support is best-effort and varies by the active ContextManager (see
ContextManager.attach); if it does not implement attach, this logs
a warning and returns a no-op token.
The Context to attach
A ContextManagementToken whose dispose() restores the previous Context
Bind a context to a target function or event emitter
context to bind to the event emitter or function. Defaults to the currently active context
function or event emitter to bind
Disable and remove the global context manager
Set the current context manager.
true if the context manager was successfully registered, else false
Execute a function with an active context
context to be active during function execution
function to execute in a context
OptionalthisArg: ThisParameterType<F>
optional receiver to be used for calling fn
optional arguments forwarded to fn
Singleton object which represents the entry point to the OpenTelemetry Context API
Since
1.0.0