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
83 lines • 2.17 kB
JavaScript
/**
* @since 2.0.0
*/
import * as Context from "../Context.js";
/** @internal */
export const TracerTypeId = /*#__PURE__*/Symbol.for("effect/Tracer");
/** @internal */
export const make = options => ({
[TracerTypeId]: TracerTypeId,
...options
});
/** @internal */
export const tracerTag = /*#__PURE__*/Context.GenericTag("effect/Tracer");
/** @internal */
export const 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 */
export 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 */
export const nativeTracer = /*#__PURE__*/make({
span: (name, parent, context, links, startTime) => new NativeSpan(name, parent, context, links, startTime),
context: f => f()
});
/** @internal */
export const externalSpan = options => ({
_tag: "ExternalSpan",
spanId: options.spanId,
traceId: options.traceId,
sampled: options.sampled ?? true,
context: options.context ?? Context.empty()
});
//# sourceMappingURL=tracer.js.map