Scope manager enables manual context propagation. It tracks which span is currently active and allows you to activate spans across async boundaries.
In most cases you do not need to interact with the scope manager directly — tracer.trace() and tracer.wrap() handle scope management automatically. Use the scope manager directly only for edge cases such as internal queues or timer-based callbacks where the async context is lost.
Methods
active()
Returns the currently active span, or null if there is no active span.
The active
Span in the current async context, or null if none.activate(span, fn)
Activates the provided span in the scope of a function. Any asynchronous context created from within the function will also have the same scope.
The span to activate.
The function to execute with the span activated on its scope.
The return value of
fn.bind(target, span?)
Binds a function or Promise to the provided span. When the bound target is called or resolved, the given span will be the active span in that context.
The function or
Promise to bind.The span to bind to. If omitted, the currently active span at the time
bind() is called is used. Explicitly passing null binds to no span.The bound target, with the same type as the input.
Explicitly passing
null as the span binds to no span. The bound function will see scope.active() return null when called.