OpenTelemetry SDK
    Preparing search index...

    Implements

    • ContextManager
    Index
    • 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.

      Parameters

      • context: Context

      Returns ContextManagementToken

    • Binds a the certain context or the active one to the target function and then returns the target

      Type Parameters

      • T

      Parameters

      • context: Context

        A context (span) to be bind to target

      • target: T

        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.

      Returns T

    • Run the fn callback with object set as the current active context

      Type Parameters

      • A extends unknown[]
      • F extends (...args: A) => ReturnType<F>

      Parameters

      • context: Context

        Any object to set as the current active context

      • fn: F

        A callback to be immediately run within a specific context

      • OptionalthisArg: ThisParameterType<F>

        optional receiver to be used for calling fn

      • ...args: A

        optional arguments forwarded to fn

      Returns ReturnType<F>