veffect
Version:
powerful TypeScript validation library built on the robust foundation of Effect combining exceptional type safety, high performance, and developer experience. Taking inspiration from Effect's functional principles, VEffect delivers a balanced approach tha
118 lines (116 loc) • 3.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.tracerTag = exports.spanTag = exports.nativeTracer = exports.make = exports.externalSpan = exports.TracerTypeId = exports.NativeSpan = void 0;
var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../Context.js"));
function _getRequireWildcardCache(e) {
if ("function" != typeof WeakMap) return null;
var r = new WeakMap(),
t = new WeakMap();
return (_getRequireWildcardCache = function (e) {
return e ? t : r;
})(e);
}
function _interopRequireWildcard(e, r) {
if (!r && e && e.__esModule) return e;
if (null === e || "object" != typeof e && "function" != typeof e) return {
default: e
};
var t = _getRequireWildcardCache(r);
if (t && t.has(e)) return t.get(e);
var n = {
__proto__: null
},
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
}
return n.default = e, t && t.set(e, n), n;
}
/**
* @since 2.0.0
*/
/** @internal */
const TracerTypeId = exports.TracerTypeId = /*#__PURE__*/Symbol.for("effect/Tracer");
/** @internal */
const make = options => ({
[TracerTypeId]: TracerTypeId,
...options
});
/** @internal */
exports.make = make;
const tracerTag = exports.tracerTag = /*#__PURE__*/Context.GenericTag("effect/Tracer");
/** @internal */
const spanTag = exports.spanTag = /*#__PURE__*/Context.GenericTag("effect/ParentSpan");
const randomHexString = /*#__PURE__*/function () {
const characters = "abcdef0123456789";
const charactersLength = characters.length;
return function (length) {
let result = "";
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
};
}();
/** @internal */
class NativeSpan {
name;
parent;
context;
links;
startTime;
_tag = "Span";
spanId;
traceId = "native";
sampled = true;
status;
attributes;
events = [];
constructor(name, parent, context, links, startTime) {
this.name = name;
this.parent = parent;
this.context = context;
this.links = links;
this.startTime = startTime;
this.status = {
_tag: "Started",
startTime
};
this.attributes = new Map();
this.traceId = parent._tag === "Some" ? parent.value.traceId : randomHexString(32);
this.spanId = randomHexString(16);
}
end(endTime, exit) {
this.status = {
_tag: "Ended",
endTime,
exit,
startTime: this.status.startTime
};
}
attribute(key, value) {
this.attributes.set(key, value);
}
event(name, startTime, attributes) {
this.events.push([name, startTime, attributes ?? {}]);
}
}
/** @internal */
exports.NativeSpan = NativeSpan;
const nativeTracer = exports.nativeTracer = /*#__PURE__*/make({
span: (name, parent, context, links, startTime) => new NativeSpan(name, parent, context, links, startTime),
context: f => f()
});
/** @internal */
const externalSpan = options => ({
_tag: "ExternalSpan",
spanId: options.spanId,
traceId: options.traceId,
sampled: options.sampled ?? true,
context: options.context ?? Context.empty()
});
exports.externalSpan = externalSpan;
//# sourceMappingURL=tracer.js.map