@embrace-io/web-sdk
Version:
44 lines (43 loc) • 1.66 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
//#region src/processors/utils/SignalBuffer.ts
const DEFAULT_MAX_AGE_MILLIS = 6e4;
const DEFAULT_MAX_ENTRIES = 4096;
/**
* A bounded, in-memory rolling buffer of span and log signals. Used to back-fill
* a span with the ids of signals that started within its window, since that
* span is built after its window has already closed.
*/
var SignalBuffer = class {
_maxAgeMillis;
_maxEntries;
_entries = [];
_latestStartTime = 0;
constructor({ maxAgeMillis = DEFAULT_MAX_AGE_MILLIS, maxEntries = DEFAULT_MAX_ENTRIES } = {}) {
this._maxAgeMillis = maxAgeMillis;
this._maxEntries = maxEntries;
}
record(entry) {
this._entries.push(entry);
if (entry.startTime > this._latestStartTime) this._latestStartTime = entry.startTime;
this._evict();
}
collectWindow(startTime, endTime) {
const matched = this._entries.filter((entry) => entry.startTime >= startTime && entry.startTime <= endTime);
const spans = matched.filter((entry) => entry.kind === "span");
const logs = matched.filter((entry) => entry.kind === "log");
return {
spanIds: spans.map((entry) => entry.id),
spanTypes: spans.map((entry) => entry.type ?? ""),
logIds: logs.map((entry) => entry.id),
logTypes: logs.map((entry) => entry.type ?? "")
};
}
_evict() {
const cutoff = this._latestStartTime - this._maxAgeMillis;
while (this._entries.length > 0 && this._entries[0].startTime < cutoff) this._entries.shift();
while (this._entries.length > this._maxEntries) this._entries.shift();
}
};
//#endregion
exports.SignalBuffer = SignalBuffer;
//# sourceMappingURL=SignalBuffer.cjs.map