UNPKG

@opentelemetry/api

Version:
62 lines (61 loc) • 1.64 kB
import { createContextKey } from "../context/context.mjs"; import { ContextAPI } from "../api/context.mjs"; import { NonRecordingSpan } from "./NonRecordingSpan.mjs"; //#region src/trace/context-utils.ts /** * span key */ const SPAN_KEY = createContextKey("OpenTelemetry Context Key SPAN"); /** * Return the span if one exists * * @param context context to get span from */ function getSpan(context) { return context.getValue(SPAN_KEY) || void 0; } /** * Gets the span from the current context, if one exists. */ function getActiveSpan() { return getSpan(ContextAPI.getInstance().active()); } /** * Set the span on a context * * @param context context to use as parent * @param span span to set active */ function setSpan(context, span) { return context.setValue(SPAN_KEY, span); } /** * Remove current span stored in the context * * @param context context to delete span from */ function deleteSpan(context) { return context.deleteValue(SPAN_KEY); } /** * Wrap span context in a NoopSpan and set as span in a new * context * * @param context context to set active span on * @param spanContext span context to be wrapped */ function setSpanContext(context, spanContext) { return setSpan(context, new NonRecordingSpan(spanContext)); } /** * Get the span context of the span if it exists. * * @param context context to get values from */ function getSpanContext(context) { var _getSpan; return (_getSpan = getSpan(context)) === null || _getSpan === void 0 ? void 0 : _getSpan.spanContext(); } //#endregion export { deleteSpan, getActiveSpan, getSpan, getSpanContext, setSpan, setSpanContext }; //# sourceMappingURL=context-utils.mjs.map