UNPKG

rollbar

Version:

Effortlessly track and debug errors in your JavaScript applications with Rollbar. This package includes advanced error tracking features and an intuitive interface to help you identify and fix issues more quickly.

37 lines (30 loc) 778 B
import { ROOT_CONTEXT } from './context.js'; export class ContextManager { constructor() { this.currentContext = ROOT_CONTEXT; } active() { return this.currentContext; } enterContext(context) { const previousContext = this.currentContext; this.currentContext = context || ROOT_CONTEXT; return previousContext; } exitContext(context) { this.currentContext = context; return this.currentContext; } with(context, fn, thisArg, ...args) { const previousContext = this.enterContext(context); try { return fn.call(thisArg, ...args); } finally { this.exitContext(previousContext); } } } export function createContextKey(key) { // Use Symbol for OpenTelemetry compatibility. return Symbol.for(key); }