Get the current active context
OptionalattachExperimental
Imperatively sets context as active, returning a ContextManagementToken whose
ContextManagementToken.dispose method restores the previous context.
This is a delicate, low-level API - prefer with/bind, which
restore context automatically. attach exists only to bridge callback
boundaries that with cannot wrap. The caller is responsible for disposing
the token via token.dispose() when the operation is complete. Support is
optional and best-effort; when omitted, ContextAPI.attach logs a
warning and returns a no-op token.
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.
The Context to attach
A ContextManagementToken whose dispose() restores the previous Context
Bind an object as the current context (or a specific one)
Optionalcontext: @opentelemetry/api.Context
Optionally specify the context which you want to assign
Any object to which a context need to be set
Disable context management
Enable context management
Run the fn callback with object set as the current active context
Any object to set as the current active context
A callback to be immediately run within a specific context
OptionalthisArg: ThisParameterType<F>
optional receiver to be used for calling fn
optional arguments forwarded to fn
Since
1.0.0