UNPKG

1.65 kBTypeScriptView Raw
1import { Context, ContextManager } from '../context/types';
2/**
3 * Singleton object which represents the entry point to the OpenTelemetry Context API
4 */
5export declare class ContextAPI {
6 private static _instance?;
7 /** Empty private constructor prevents end users from constructing a new instance of the API */
8 private constructor();
9 /** Get the singleton instance of the Context API */
10 static getInstance(): ContextAPI;
11 /**
12 * Set the current context manager.
13 *
14 * @returns true if the context manager was successfully registered, else false
15 */
16 setGlobalContextManager(contextManager: ContextManager): boolean;
17 /**
18 * Get the currently active context
19 */
20 active(): Context;
21 /**
22 * Execute a function with an active context
23 *
24 * @param context context to be active during function execution
25 * @param fn function to execute in a context
26 * @param thisArg optional receiver to be used for calling fn
27 * @param args optional arguments forwarded to fn
28 */
29 with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: Context, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
30 /**
31 * Bind a context to a target function or event emitter
32 *
33 * @param context context to bind to the event emitter or function. Defaults to the currently active context
34 * @param target function or event emitter to bind
35 */
36 bind<T>(context: Context, target: T): T;
37 private _getContextManager;
38 /** Disable and remove the global context manager */
39 disable(): void;
40}
41//# sourceMappingURL=context.d.ts.map
\No newline at end of file