@opentelemetry/api
Version:
Public API for OpenTelemetry
41 lines (40 loc) • 1.16 kB
JavaScript
//#region src/context/context.ts
/**
* Get a key to uniquely identify a context value
*
* @since 1.0.0
*/
function createContextKey(description) {
return Symbol.for(description);
}
/**
* The root context is used as the default parent context when there is no active context
*
* @since 1.0.0
*/
const ROOT_CONTEXT = new class BaseContext {
/**
* Construct a new context which inherits values from an optional parent context.
*
* @param parentContext a context from which to inherit values
*/
constructor(parentContext) {
const self = this;
self._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
self.getValue = (key) => self._currentContext.get(key);
self.setValue = (key, value) => {
const context = new BaseContext(self._currentContext);
context._currentContext.set(key, value);
return context;
};
self.deleteValue = (key) => {
const context = new BaseContext(self._currentContext);
context._currentContext.delete(key);
return context;
};
}
}();
//#endregion
exports.ROOT_CONTEXT = ROOT_CONTEXT;
exports.createContextKey = createContextKey;
//# sourceMappingURL=context.cjs.map