@rasputin-ai/node 0.11.4 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/execution-recorder/adaptive-recording-options.d.ts +2 -2
- package/dist/execution-recorder/adaptive-recording-options.d.ts.map +1 -1
- package/dist/execution-recorder/bind-adaptive-recorder.d.ts.map +1 -1
- package/dist/execution-recorder/dynamic-duration-sampling.d.ts +16 -0
- package/dist/execution-recorder/dynamic-duration-sampling.d.ts.map +1 -0
- package/dist/execution-recorder/execution-journal.d.ts +7 -4
- package/dist/execution-recorder/execution-journal.d.ts.map +1 -1
- package/dist/execution-recorder/execution-recorder-types.d.ts +19 -9
- package/dist/execution-recorder/execution-recorder-types.d.ts.map +1 -1
- package/dist/execution-recorder/execution-recorder.d.ts.map +1 -1
- package/dist/execution-recorder/publish-runtime-state.d.ts +8 -0
- package/dist/execution-recorder/publish-runtime-state.d.ts.map +1 -0
- package/dist/execution-recorder/runtime-state-size-budget.d.ts.map +1 -1
- package/dist/index.js +349 -111
- package/dist/instrument/bun.js +1 -1
- package/dist/instrument/node.js +1 -1
- package/dist/internal.js +347 -110
- package/dist/rasputin-init.d.ts.map +1 -1
- package/dist/sdk-meta.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -674,9 +674,6 @@ import {
|
|
|
674
674
|
var DEFAULT_FULL_CAPTURE_DURATION_MS = 24 * 60 * 60 * 1e3;
|
|
675
675
|
var MIN_FULL_CAPTURE_DURATION_MS = 1e3;
|
|
676
676
|
var MAX_FULL_CAPTURE_DURATION_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
677
|
-
var sanitizeRecorderMode = (mode) => {
|
|
678
|
-
return mode === "adaptive" ? "adaptive" : "full";
|
|
679
|
-
};
|
|
680
677
|
var sanitizeFullCaptureDurationMs = (value) => {
|
|
681
678
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
682
679
|
return DEFAULT_FULL_CAPTURE_DURATION_MS;
|
|
@@ -686,6 +683,68 @@ var sanitizeFullCaptureDurationMs = (value) => {
|
|
|
686
683
|
Math.max(MIN_FULL_CAPTURE_DURATION_MS, Math.floor(value))
|
|
687
684
|
);
|
|
688
685
|
};
|
|
686
|
+
var sanitizeDynamicDurationSampling = (value) => value === true;
|
|
687
|
+
|
|
688
|
+
// src/execution-recorder/dynamic-duration-sampling.ts
|
|
689
|
+
var DYNAMIC_DURATION_SAMPLE_STAGES = [
|
|
690
|
+
{ below: 10, divisor: 1 },
|
|
691
|
+
{ below: 30, divisor: 2 },
|
|
692
|
+
{ below: 100, divisor: 3 },
|
|
693
|
+
{ below: 500, divisor: 11 },
|
|
694
|
+
{ below: 1e3, divisor: 23 },
|
|
695
|
+
{ below: 5e3, divisor: 53 }
|
|
696
|
+
];
|
|
697
|
+
var DYNAMIC_DURATION_SAMPLE_TAIL_AFTER = 5e3;
|
|
698
|
+
var DYNAMIC_DURATION_SAMPLE_TAIL_DIVISOR = 100;
|
|
699
|
+
var DYNAMIC_DURATION_SAMPLE_RESET_MS = 60 * 60 * 1e3;
|
|
700
|
+
var MAX_DYNAMIC_DURATION_SAMPLE_BUCKETS = 4096;
|
|
701
|
+
var dynamicDurationSampleDivisor = (index) => {
|
|
702
|
+
for (const stage of DYNAMIC_DURATION_SAMPLE_STAGES) {
|
|
703
|
+
if (index < stage.below) return stage.divisor;
|
|
704
|
+
}
|
|
705
|
+
return DYNAMIC_DURATION_SAMPLE_TAIL_DIVISOR;
|
|
706
|
+
};
|
|
707
|
+
var shouldSampleDynamicDuration = (index) => {
|
|
708
|
+
return index % dynamicDurationSampleDivisor(index) === 0;
|
|
709
|
+
};
|
|
710
|
+
var nextDurationSampleIndex = (index) => {
|
|
711
|
+
if (index < Number.MAX_SAFE_INTEGER) return index + 1;
|
|
712
|
+
return DYNAMIC_DURATION_SAMPLE_TAIL_AFTER + (index - DYNAMIC_DURATION_SAMPLE_TAIL_AFTER + 1) % DYNAMIC_DURATION_SAMPLE_TAIL_DIVISOR;
|
|
713
|
+
};
|
|
714
|
+
var createDynamicDurationSampleBuckets = (options) => {
|
|
715
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
716
|
+
const maxBuckets = options.maxBuckets ?? MAX_DYNAMIC_DURATION_SAMPLE_BUCKETS;
|
|
717
|
+
const resetMs = options.resetMs ?? DYNAMIC_DURATION_SAMPLE_RESET_MS;
|
|
718
|
+
let lastResetAtMs = options.nowMs();
|
|
719
|
+
const reset = () => {
|
|
720
|
+
buckets.clear();
|
|
721
|
+
lastResetAtMs = options.nowMs();
|
|
722
|
+
};
|
|
723
|
+
const resetTimer = setInterval(reset, resetMs);
|
|
724
|
+
resetTimer.unref?.();
|
|
725
|
+
return {
|
|
726
|
+
take: (executionType, callerFunctionId, functionId) => {
|
|
727
|
+
if (options.nowMs() - lastResetAtMs >= resetMs) reset();
|
|
728
|
+
const key = `${executionType}\0${callerFunctionId}\0${functionId}`;
|
|
729
|
+
const existing = buckets.get(key);
|
|
730
|
+
if (existing !== void 0) {
|
|
731
|
+
buckets.delete(key);
|
|
732
|
+
buckets.set(key, nextDurationSampleIndex(existing));
|
|
733
|
+
return shouldSampleDynamicDuration(existing);
|
|
734
|
+
}
|
|
735
|
+
while (buckets.size >= maxBuckets) {
|
|
736
|
+
const oldest = buckets.keys().next().value;
|
|
737
|
+
if (oldest === void 0) break;
|
|
738
|
+
buckets.delete(oldest);
|
|
739
|
+
}
|
|
740
|
+
buckets.set(key, nextDurationSampleIndex(0));
|
|
741
|
+
return shouldSampleDynamicDuration(0);
|
|
742
|
+
},
|
|
743
|
+
stop: () => {
|
|
744
|
+
clearInterval(resetTimer);
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
};
|
|
689
748
|
|
|
690
749
|
// src/execution-recorder/error-observation.ts
|
|
691
750
|
var bindings = /* @__PURE__ */ new WeakMap();
|
|
@@ -734,15 +793,17 @@ var KIND_SUPPRESSED = 4;
|
|
|
734
793
|
var ARGS_OMITTED = Symbol("rasputin.argsOmitted");
|
|
735
794
|
var NO_PARENT = 4294967295;
|
|
736
795
|
var NO_SUPPRESSION = 4294967295;
|
|
796
|
+
var TIMING_UNAVAILABLE = -1n;
|
|
737
797
|
var MAX_POOLED_JOURNALS = 8;
|
|
738
798
|
var MAX_POOLED_JOURNAL_CAPACITY = 4096;
|
|
739
799
|
var INITIAL_JOURNAL_STORAGE = 32;
|
|
740
800
|
var BYTES_PER_EVENT = Uint8Array.BYTES_PER_ELEMENT + Uint32Array.BYTES_PER_ELEMENT * 4 + BigInt64Array.BYTES_PER_ELEMENT * 2;
|
|
741
|
-
var DEFAULT_MAX_EVENTS_PER_EXECUTION =
|
|
801
|
+
var DEFAULT_MAX_EVENTS_PER_EXECUTION = 1500;
|
|
742
802
|
var MAX_JOURNAL_EVENTS = 16384;
|
|
743
803
|
var elapsedMs = (startedAtNs, endedAtNs) => Number(endedAtNs - startedAtNs) / 1e6;
|
|
744
804
|
var roundedMilliseconds = (nanoseconds) => Math.round(Number(nanoseconds) / 1e6 * 1e4) / 1e4;
|
|
745
805
|
var relativeMs = (relativeNs) => Number(relativeNs) / 1e6;
|
|
806
|
+
var measuredRelativeMs = (relativeNs) => relativeNs === TIMING_UNAVAILABLE ? void 0 : relativeMs(relativeNs);
|
|
746
807
|
var sanitizeJournalCapacity = (value) => {
|
|
747
808
|
const requested = value ?? DEFAULT_MAX_EVENTS_PER_EXECUTION;
|
|
748
809
|
if (!Number.isFinite(requested)) return DEFAULT_MAX_EVENTS_PER_EXECUTION;
|
|
@@ -924,44 +985,53 @@ var ExecutionJournal = class {
|
|
|
924
985
|
if (!functionId) return void 0;
|
|
925
986
|
const parentCallId = this.parentCallId[index] ?? NO_PARENT;
|
|
926
987
|
const payload = this.payloads[index];
|
|
988
|
+
const timestampMs = measuredRelativeMs(this.timestampNs[index] ?? TIMING_UNAVAILABLE);
|
|
927
989
|
return {
|
|
928
990
|
type: "function_enter",
|
|
929
991
|
callId: this.callId[index] ?? 0,
|
|
930
992
|
functionId,
|
|
931
|
-
timestampMs:
|
|
993
|
+
...timestampMs === void 0 ? {} : { timestampMs },
|
|
932
994
|
...payload === ARGS_OMITTED ? { argsOmitted: true } : { args: Array.isArray(payload) ? payload : [] },
|
|
933
995
|
...parentCallId === NO_PARENT ? {} : { parentCallId }
|
|
934
996
|
};
|
|
935
997
|
}
|
|
936
998
|
if (kind === KIND_EXIT) {
|
|
937
999
|
const payload = this.payloads[index];
|
|
1000
|
+
const timestampMs = measuredRelativeMs(this.timestampNs[index] ?? TIMING_UNAVAILABLE);
|
|
1001
|
+
const durationMs = measuredRelativeMs(this.durationNs[index] ?? TIMING_UNAVAILABLE);
|
|
938
1002
|
return {
|
|
939
1003
|
type: "function_exit",
|
|
940
1004
|
callId: this.callId[index] ?? 0,
|
|
941
|
-
timestampMs:
|
|
942
|
-
durationMs:
|
|
1005
|
+
...timestampMs === void 0 ? {} : { timestampMs },
|
|
1006
|
+
...durationMs === void 0 ? {} : { durationMs },
|
|
943
1007
|
...payload === ARGS_OMITTED ? {} : { returnValue: payload }
|
|
944
1008
|
};
|
|
945
1009
|
}
|
|
946
1010
|
if (kind === KIND_THROW) {
|
|
1011
|
+
const timestampMs = measuredRelativeMs(this.timestampNs[index] ?? TIMING_UNAVAILABLE);
|
|
1012
|
+
const durationMs = measuredRelativeMs(this.durationNs[index] ?? TIMING_UNAVAILABLE);
|
|
947
1013
|
return {
|
|
948
1014
|
type: "function_throw",
|
|
949
1015
|
callId: this.callId[index] ?? 0,
|
|
950
|
-
timestampMs:
|
|
951
|
-
durationMs:
|
|
1016
|
+
...timestampMs === void 0 ? {} : { timestampMs },
|
|
1017
|
+
...durationMs === void 0 ? {} : { durationMs },
|
|
952
1018
|
error: this.payloads[index]
|
|
953
1019
|
};
|
|
954
1020
|
}
|
|
955
1021
|
if (kind === KIND_SUPPRESSED) {
|
|
956
1022
|
const group = this.suppressions[this.suppressionIndex[index] ?? 0];
|
|
957
1023
|
if (!group) return void 0;
|
|
1024
|
+
const sampledDurationCount = group.sampledDurationCount;
|
|
1025
|
+
const allTimed = sampledDurationCount === group.count && group.count > 0;
|
|
958
1026
|
return {
|
|
959
1027
|
type: "function_calls_suppressed",
|
|
960
1028
|
functionId: group.functionId,
|
|
961
|
-
timestampMs: elapsedMs(executionStartedAtNs, group.firstTimestampNs),
|
|
962
|
-
lastTimestampMs: elapsedMs(executionStartedAtNs, group.lastTimestampNs),
|
|
963
1029
|
suppressedCallCount: group.count,
|
|
964
|
-
|
|
1030
|
+
sampledDurationCount,
|
|
1031
|
+
...group.firstTimed ? { timestampMs: elapsedMs(executionStartedAtNs, group.firstTimestampNs) } : {},
|
|
1032
|
+
...group.lastTimed ? { lastTimestampMs: elapsedMs(executionStartedAtNs, group.lastTimestampNs) } : {},
|
|
1033
|
+
...allTimed ? { totalDurationMs: roundedMilliseconds(group.sampledDurationNs) } : {},
|
|
1034
|
+
...sampledDurationCount > 0 ? { sampledDurationMs: roundedMilliseconds(group.sampledDurationNs) } : {},
|
|
965
1035
|
...group.parentCallId === void 0 ? {} : { parentCallId: group.parentCallId }
|
|
966
1036
|
};
|
|
967
1037
|
}
|
|
@@ -1118,6 +1188,69 @@ var ExecutionJournalPool = class {
|
|
|
1118
1188
|
var EVENT_PAIR_BASE_ESTIMATED_BYTES = 512;
|
|
1119
1189
|
var estimatedCallBytesFor = (functionId) => EVENT_PAIR_BASE_ESTIMATED_BYTES + Buffer.byteLength(functionId, "utf8") * 2;
|
|
1120
1190
|
|
|
1191
|
+
// src/execution-recorder/publish-runtime-state.ts
|
|
1192
|
+
var measured = (value) => typeof value === "number";
|
|
1193
|
+
var eventsAreFullyTimed = (events) => {
|
|
1194
|
+
for (const event of events) {
|
|
1195
|
+
if (event.type === "function_enter" || event.type === "awaited" || event.type === "expression_observed") {
|
|
1196
|
+
if (!measured(event.timestampMs)) return false;
|
|
1197
|
+
continue;
|
|
1198
|
+
}
|
|
1199
|
+
if (event.type === "function_exit" || event.type === "function_throw") {
|
|
1200
|
+
if (!measured(event.timestampMs) || !measured(event.durationMs)) return false;
|
|
1201
|
+
continue;
|
|
1202
|
+
}
|
|
1203
|
+
const sampled = event.sampledDurationCount ?? (measured(event.totalDurationMs) ? event.suppressedCallCount : 0);
|
|
1204
|
+
if (!measured(event.timestampMs) || !measured(event.totalDurationMs) || sampled !== event.suppressedCallCount) {
|
|
1205
|
+
return false;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
return true;
|
|
1209
|
+
};
|
|
1210
|
+
var retainedTimingsCoverage = (events) => {
|
|
1211
|
+
let sawMeasured = false;
|
|
1212
|
+
let sawMissing = false;
|
|
1213
|
+
const mark = (complete) => {
|
|
1214
|
+
if (complete) sawMeasured = true;
|
|
1215
|
+
else sawMissing = true;
|
|
1216
|
+
};
|
|
1217
|
+
for (const event of events) {
|
|
1218
|
+
if (event.type === "function_enter" || event.type === "awaited" || event.type === "expression_observed") {
|
|
1219
|
+
mark(measured(event.timestampMs));
|
|
1220
|
+
continue;
|
|
1221
|
+
}
|
|
1222
|
+
if (event.type === "function_exit" || event.type === "function_throw") {
|
|
1223
|
+
const stamped = measured(event.timestampMs);
|
|
1224
|
+
const timed = measured(event.durationMs);
|
|
1225
|
+
if (stamped && timed) mark(true);
|
|
1226
|
+
else if (!stamped && !timed) mark(false);
|
|
1227
|
+
else {
|
|
1228
|
+
sawMeasured = true;
|
|
1229
|
+
sawMissing = true;
|
|
1230
|
+
}
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
const sampled = event.sampledDurationCount ?? (measured(event.totalDurationMs) ? event.suppressedCallCount : 0);
|
|
1234
|
+
if (sampled > 0) sawMeasured = true;
|
|
1235
|
+
if (sampled < event.suppressedCallCount || !measured(event.timestampMs)) sawMissing = true;
|
|
1236
|
+
}
|
|
1237
|
+
if (sawMeasured && sawMissing) return "partial";
|
|
1238
|
+
if (sawMeasured) return "full";
|
|
1239
|
+
return "none";
|
|
1240
|
+
};
|
|
1241
|
+
var asFullyTimedEvents = (events) => events.map((event) => {
|
|
1242
|
+
if (event.type !== "function_calls_suppressed") return event;
|
|
1243
|
+
return {
|
|
1244
|
+
type: "function_calls_suppressed",
|
|
1245
|
+
functionId: event.functionId,
|
|
1246
|
+
suppressedCallCount: event.suppressedCallCount,
|
|
1247
|
+
...event.parentCallId === void 0 ? {} : { parentCallId: event.parentCallId },
|
|
1248
|
+
...event.timestampMs === void 0 ? {} : { timestampMs: event.timestampMs },
|
|
1249
|
+
...event.lastTimestampMs === void 0 ? {} : { lastTimestampMs: event.lastTimestampMs },
|
|
1250
|
+
...event.totalDurationMs === void 0 ? {} : { totalDurationMs: event.totalDurationMs }
|
|
1251
|
+
};
|
|
1252
|
+
});
|
|
1253
|
+
|
|
1121
1254
|
// src/execution-recorder/recorder-memory-budget.ts
|
|
1122
1255
|
var EXECUTION_BASE_ESTIMATED_BYTES = 1024;
|
|
1123
1256
|
var SUMMARY_EVENT_BASE_ESTIMATED_BYTES = 256;
|
|
@@ -1301,7 +1434,7 @@ var dropEventValues = (events) => {
|
|
|
1301
1434
|
const marker = () => rasputinUnavailable(VALUE_OMITTED_REASON);
|
|
1302
1435
|
const bounded2 = events.map((event) => {
|
|
1303
1436
|
if (event.type === "function_enter") {
|
|
1304
|
-
if (event.args === void 0) return
|
|
1437
|
+
if (event.args === void 0) return event;
|
|
1305
1438
|
dropped += event.args.length;
|
|
1306
1439
|
return { ...event, args: event.args.map(marker) };
|
|
1307
1440
|
}
|
|
@@ -1313,7 +1446,7 @@ var dropEventValues = (events) => {
|
|
|
1313
1446
|
dropped++;
|
|
1314
1447
|
return { ...event, error: marker() };
|
|
1315
1448
|
}
|
|
1316
|
-
return
|
|
1449
|
+
return event;
|
|
1317
1450
|
});
|
|
1318
1451
|
return { events: bounded2, dropped };
|
|
1319
1452
|
};
|
|
@@ -1354,7 +1487,7 @@ var minimalState = (state, size) => {
|
|
|
1354
1487
|
startedAt: truncateUtf8(state.startedAt, 128) ?? "",
|
|
1355
1488
|
durationMs: Number.isFinite(state.durationMs) ? state.durationMs : 0,
|
|
1356
1489
|
recorder: {
|
|
1357
|
-
inlineWallTimeMs: Number.isFinite(state.recorder
|
|
1490
|
+
inlineWallTimeMs: state.recorder && Number.isFinite(state.recorder.inlineWallTimeMs) ? state.recorder.inlineWallTimeMs : 0
|
|
1358
1491
|
},
|
|
1359
1492
|
execution,
|
|
1360
1493
|
functions: [],
|
|
@@ -1372,20 +1505,14 @@ var enforceRuntimeStateSizeBudget = (input) => {
|
|
|
1372
1505
|
const originalBytes = existingSize?.originalBytes ?? initialBytes;
|
|
1373
1506
|
const size = sizeMetadata(originalBytes);
|
|
1374
1507
|
let state = input;
|
|
1508
|
+
const captureProfile = {
|
|
1509
|
+
...state.captureProfile,
|
|
1510
|
+
functionValues: state.captureProfile.functionValues === "none" ? "none" : "selective"
|
|
1511
|
+
};
|
|
1375
1512
|
const stripped = dropEventValues(state.events);
|
|
1376
1513
|
size.eventValuesDropped += stripped.dropped;
|
|
1377
1514
|
state = settleFinalBytes(
|
|
1378
|
-
withSizeMetadata(
|
|
1379
|
-
{
|
|
1380
|
-
...state,
|
|
1381
|
-
captureProfile: {
|
|
1382
|
-
...state.captureProfile,
|
|
1383
|
-
functionValues: state.captureProfile.functionValues === "none" ? "none" : "selective"
|
|
1384
|
-
},
|
|
1385
|
-
events: stripped.events
|
|
1386
|
-
},
|
|
1387
|
-
size
|
|
1388
|
-
)
|
|
1515
|
+
withSizeMetadata({ ...state, captureProfile, events: stripped.events }, size)
|
|
1389
1516
|
);
|
|
1390
1517
|
if (encodedBytes(state) <= MAX_RUNTIME_STATE_BYTES) return state;
|
|
1391
1518
|
size.eventsDropped += state.events.length;
|
|
@@ -2543,6 +2670,7 @@ var warnIfMissingAsyncContextFrame = () => {
|
|
|
2543
2670
|
|
|
2544
2671
|
// src/execution-recorder/execution-recorder.ts
|
|
2545
2672
|
var DEFAULT_MAX_ACTIVE_MEMORY_BYTES = 64 * 1024 * 1024;
|
|
2673
|
+
var DEFAULT_MAX_CAPTURED_CALLS_PER_FUNCTION = 1;
|
|
2546
2674
|
var DEFAULT_MAX_EXECUTION_HOLD_MS = 6e4;
|
|
2547
2675
|
var DEFAULT_MAX_RETAINED_ERROR_RECORDINGS = 32;
|
|
2548
2676
|
var EMPTY_ARGS = [];
|
|
@@ -2660,7 +2788,9 @@ var noOpExecution = {
|
|
|
2660
2788
|
resume: (value) => value
|
|
2661
2789
|
}),
|
|
2662
2790
|
trace: (_functionId, fn) => fn,
|
|
2663
|
-
getStats: () => ({ ...emptyStats })
|
|
2791
|
+
getStats: () => ({ ...emptyStats }),
|
|
2792
|
+
close: () => {
|
|
2793
|
+
}
|
|
2664
2794
|
};
|
|
2665
2795
|
var mergeExecutionMetadata = (target, metadata) => {
|
|
2666
2796
|
if (metadata.kind) target.kind = metadata.kind;
|
|
@@ -2672,35 +2802,44 @@ var newRepeatedGroup = (plan) => ({
|
|
|
2672
2802
|
functionId: plan.functionId,
|
|
2673
2803
|
runtimePlanId: plan.runtimePlanId
|
|
2674
2804
|
});
|
|
2675
|
-
var newSuppression = (group, parentCallId, startedAtNs, endedAtNs) =>
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2805
|
+
var newSuppression = (group, parentCallId, startedAtNs, endedAtNs, timed) => {
|
|
2806
|
+
const durationNs = timed ? endedAtNs - startedAtNs : 0n;
|
|
2807
|
+
return {
|
|
2808
|
+
count: 1,
|
|
2809
|
+
firstTimestampNs: timed ? startedAtNs : 0n,
|
|
2810
|
+
lastTimestampNs: timed ? endedAtNs : 0n,
|
|
2811
|
+
sampledDurationNs: durationNs,
|
|
2812
|
+
sampledDurationCount: timed ? 1 : 0,
|
|
2813
|
+
firstTimed: timed,
|
|
2814
|
+
lastTimed: timed,
|
|
2815
|
+
functionId: group.functionId,
|
|
2816
|
+
runtimePlanId: group.runtimePlanId,
|
|
2817
|
+
...parentCallId === void 0 ? {} : { parentCallId },
|
|
2818
|
+
storageIndex: -1,
|
|
2819
|
+
retainedIndex: -1
|
|
2820
|
+
};
|
|
2821
|
+
};
|
|
2686
2822
|
var EMPTY_POLICY_SNAPSHOT = /* @__PURE__ */ new Map();
|
|
2687
2823
|
var EMPTY_SESSION_SNAPSHOT = /* @__PURE__ */ new Map();
|
|
2688
2824
|
var createExecutionRecorder = (options, hooks = {}) => {
|
|
2689
2825
|
if (!options?.enabled) return noOpExecution;
|
|
2690
2826
|
warnIfMissingAsyncContextFrame();
|
|
2691
|
-
const
|
|
2827
|
+
const adaptiveEnabled = options.adaptive?.enabled === true;
|
|
2692
2828
|
const fullCaptureDurationMs = sanitizeFullCaptureDurationMs(
|
|
2693
2829
|
options.adaptive?.fullCaptureDurationMs
|
|
2694
2830
|
);
|
|
2695
|
-
const
|
|
2831
|
+
const durationSamplingEnabled = adaptiveEnabled && sanitizeDynamicDurationSampling(options.adaptive?.dynamicDurationSampling);
|
|
2832
|
+
const readCallClock = () => process.hrtime.bigint();
|
|
2696
2833
|
const nowMs = () => hooks.nowMs?.() ?? Date.now();
|
|
2834
|
+
const durationSamples = durationSamplingEnabled ? createDynamicDurationSampleBuckets({ nowMs }) : void 0;
|
|
2835
|
+
const localActivations = /* @__PURE__ */ new Map();
|
|
2697
2836
|
const policySnapshotFor = () => hooks.policySnapshot?.() ?? localActivations;
|
|
2698
2837
|
const keyIsActive = (snapshot, key, atMs) => {
|
|
2699
2838
|
const expiresAt = snapshot.get(key);
|
|
2700
2839
|
return expiresAt !== void 0 && expiresAt > atMs;
|
|
2701
2840
|
};
|
|
2702
2841
|
const captureValuesFor = (metadata, snapshot, atMs) => {
|
|
2703
|
-
if (
|
|
2842
|
+
if (!adaptiveEnabled) return true;
|
|
2704
2843
|
const key = executionTypeKey(metadata);
|
|
2705
2844
|
if (!key) return false;
|
|
2706
2845
|
return keyIsActive(snapshot, key, atMs);
|
|
@@ -2742,7 +2881,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2742
2881
|
const maxEventsPerExecution = sanitizeJournalCapacity(options.maxEventsPerExecution);
|
|
2743
2882
|
const maxCapturedCallsPerFunction = Math.max(
|
|
2744
2883
|
1,
|
|
2745
|
-
Math.floor(options.maxCapturedCallsPerFunction ??
|
|
2884
|
+
Math.floor(options.maxCapturedCallsPerFunction ?? DEFAULT_MAX_CAPTURED_CALLS_PER_FUNCTION)
|
|
2746
2885
|
);
|
|
2747
2886
|
const maxActiveMemoryBytes = Math.max(
|
|
2748
2887
|
0,
|
|
@@ -2852,7 +2991,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2852
2991
|
return captureValue(recording, value);
|
|
2853
2992
|
};
|
|
2854
2993
|
const admitSession = (recording, session) => {
|
|
2855
|
-
const wasLight =
|
|
2994
|
+
const wasLight = adaptiveEnabled && !recording.captureValues;
|
|
2856
2995
|
recording.retainSuccess = true;
|
|
2857
2996
|
recording.sessionId = session.sessionId;
|
|
2858
2997
|
recording.captureValues = true;
|
|
@@ -2877,6 +3016,21 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2877
3016
|
}
|
|
2878
3017
|
};
|
|
2879
3018
|
const skipCapture = (store, plan) => store.suppressCapture || plan.excluded || Boolean(store.recording.sessionExcludes?.(plan.definition));
|
|
3019
|
+
const durationSamplingApplies = (recording) => durationSamplingEnabled && recording.identityResolved === true && !recording.captureValues && !recording.retainSuccess;
|
|
3020
|
+
const callStoreFor = (store, functionId, callId) => {
|
|
3021
|
+
const next = { ...store, currentCallId: callId };
|
|
3022
|
+
if (durationSamplingEnabled) next.currentFunctionId = functionId;
|
|
3023
|
+
return next;
|
|
3024
|
+
};
|
|
3025
|
+
const samplingStore = (store, functionId) => {
|
|
3026
|
+
return durationSamplingEnabled ? { ...store, currentFunctionId: functionId } : store;
|
|
3027
|
+
};
|
|
3028
|
+
const decideCallTiming = (recording, plan, callerFunctionId) => {
|
|
3029
|
+
if (!durationSamplingApplies(recording) || !durationSamples) return true;
|
|
3030
|
+
const typeKey = executionTypeKey(recording.execution);
|
|
3031
|
+
if (!typeKey) return true;
|
|
3032
|
+
return durationSamples.take(typeKey, callerFunctionId ?? "", plan.functionId);
|
|
3033
|
+
};
|
|
2880
3034
|
const capturedCallLimitFor = (recording) => recording.sessionMaxCapturedCalls ?? maxCapturedCallsPerFunction;
|
|
2881
3035
|
const tryAdmitLiveSession = (recording) => {
|
|
2882
3036
|
if (recording.retainSuccess || recording.finished) return;
|
|
@@ -2902,7 +3056,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2902
3056
|
if (!key) return;
|
|
2903
3057
|
recording.identityResolved = true;
|
|
2904
3058
|
tryAdmitFromStartSnapshot(recording);
|
|
2905
|
-
if (recording.captureValues ||
|
|
3059
|
+
if (recording.captureValues || !adaptiveEnabled) return;
|
|
2906
3060
|
if (keyIsActive(recording.policySnapshot, key, recording.startedAtMs)) {
|
|
2907
3061
|
recording.captureValues = true;
|
|
2908
3062
|
stats.adaptiveLightExecutions = Math.max(0, stats.adaptiveLightExecutions - 1);
|
|
@@ -2910,7 +3064,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2910
3064
|
}
|
|
2911
3065
|
};
|
|
2912
3066
|
const maybeActivateAdaptive = (recording) => {
|
|
2913
|
-
if (
|
|
3067
|
+
if (!adaptiveEnabled || recording.adaptiveActivated) return;
|
|
2914
3068
|
if (isHttpClientErrorStatus(recording.execution.request?.status)) return;
|
|
2915
3069
|
const key = executionTypeKey(recording.execution);
|
|
2916
3070
|
if (!key) return;
|
|
@@ -3011,11 +3165,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3011
3165
|
};
|
|
3012
3166
|
}
|
|
3013
3167
|
const droppedEvents = Boolean(truncated?.eventsDropped || capture?.eventsDropped);
|
|
3168
|
+
const evidence = retainedTimingsCoverage(events);
|
|
3014
3169
|
return {
|
|
3015
3170
|
source,
|
|
3016
3171
|
functionBoundaries: droppedEvents ? "partial" : "full",
|
|
3017
3172
|
functionValues: recording.captureValues ? eventsHaveOmittedValues(events) ? "selective" : "full" : "none",
|
|
3018
|
-
timings: droppedEvents ? "partial" :
|
|
3173
|
+
timings: droppedEvents && evidence === "full" ? "partial" : evidence
|
|
3019
3174
|
};
|
|
3020
3175
|
};
|
|
3021
3176
|
const stateFrom = (recording, endedAtNs = process.hrtime.bigint()) => {
|
|
@@ -3069,9 +3224,11 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3069
3224
|
recording.journal = void 0;
|
|
3070
3225
|
}
|
|
3071
3226
|
}
|
|
3227
|
+
const captureProfile = resolveCaptureProfile(recording, events, truncated, capture);
|
|
3228
|
+
const fullyTimed = eventsAreFullyTimed(events);
|
|
3072
3229
|
const state = {
|
|
3073
3230
|
version: 4,
|
|
3074
|
-
captureProfile
|
|
3231
|
+
captureProfile,
|
|
3075
3232
|
executionId: recording.executionId,
|
|
3076
3233
|
startedAt: new Date(recording.startedAtMs).toISOString(),
|
|
3077
3234
|
durationMs: elapsedMs2(recording.startedAtNs, endedAtNs),
|
|
@@ -3081,7 +3238,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3081
3238
|
...recording.execution.request ? { request: { ...recording.execution.request } } : {}
|
|
3082
3239
|
},
|
|
3083
3240
|
functions: functions.slice(),
|
|
3084
|
-
events: events.slice(),
|
|
3241
|
+
events: fullyTimed ? asFullyTimedEvents(events) : events.slice(),
|
|
3242
|
+
...fullyTimed || !durationSamplingEnabled ? {} : { durationSampling: { policy: "progressive" } },
|
|
3085
3243
|
...truncated ? { truncated: { ...truncated } } : {},
|
|
3086
3244
|
...capture ? { capture: { ...capture } } : {}
|
|
3087
3245
|
};
|
|
@@ -3351,7 +3509,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3351
3509
|
}
|
|
3352
3510
|
};
|
|
3353
3511
|
};
|
|
3354
|
-
const captureCompletedThrow = (recording, plan, args, parentCallId, startedAtNs, error, capturedArgs) => {
|
|
3512
|
+
const captureCompletedThrow = (recording, plan, args, parentCallId, startedAtNs, error, timed, capturedArgs) => {
|
|
3355
3513
|
if (!recording.journal) {
|
|
3356
3514
|
return;
|
|
3357
3515
|
}
|
|
@@ -3361,17 +3519,17 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3361
3519
|
const callId = ++recording.nextCallId;
|
|
3362
3520
|
const capturedError = serializedError(recording, error, callId);
|
|
3363
3521
|
const recordedArgs = capturedArgs ?? (recording.captureValues ? mapArrayLike(args, (argument) => captureValue(recording, argument)) : ARGS_OMITTED);
|
|
3364
|
-
const endedAtNs =
|
|
3522
|
+
const endedAtNs = readCallClock();
|
|
3365
3523
|
const droppedBefore = recording.journal.dropped;
|
|
3366
3524
|
const retained = recording.journal.forceCompletedCall(
|
|
3367
3525
|
plan.runtimePlanId,
|
|
3368
3526
|
callId,
|
|
3369
3527
|
parentCallId,
|
|
3370
|
-
startedAtNs - recording.startedAtNs,
|
|
3528
|
+
timed ? startedAtNs - recording.startedAtNs : TIMING_UNAVAILABLE,
|
|
3371
3529
|
recordedArgs,
|
|
3372
3530
|
KIND_THROW,
|
|
3373
3531
|
endedAtNs - recording.startedAtNs,
|
|
3374
|
-
endedAtNs - startedAtNs,
|
|
3532
|
+
timed ? endedAtNs - startedAtNs : TIMING_UNAVAILABLE,
|
|
3375
3533
|
capturedError.value
|
|
3376
3534
|
);
|
|
3377
3535
|
if (retained) {
|
|
@@ -3382,17 +3540,23 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3382
3540
|
}
|
|
3383
3541
|
countDroppedEvents(recording, droppedBefore);
|
|
3384
3542
|
};
|
|
3385
|
-
const recordSuppressedCall = (recording, group, parentCallId, startedAtNs, endedAtNs) => {
|
|
3543
|
+
const recordSuppressedCall = (recording, group, parentCallId, startedAtNs, endedAtNs, timed) => {
|
|
3386
3544
|
stats.repeatedCallsSuppressed++;
|
|
3387
3545
|
if (!group.suppressed) {
|
|
3388
|
-
group.suppressed = newSuppression(group, parentCallId, startedAtNs, endedAtNs);
|
|
3546
|
+
group.suppressed = newSuppression(group, parentCallId, startedAtNs, endedAtNs, timed);
|
|
3389
3547
|
appendSuppressedPlaceholder(recording, group.suppressed);
|
|
3390
3548
|
return;
|
|
3391
3549
|
}
|
|
3392
3550
|
const suppressed = group.suppressed;
|
|
3393
3551
|
suppressed.count++;
|
|
3394
|
-
|
|
3395
|
-
|
|
3552
|
+
if (timed) {
|
|
3553
|
+
suppressed.lastTimestampNs = endedAtNs;
|
|
3554
|
+
suppressed.lastTimed = true;
|
|
3555
|
+
suppressed.sampledDurationCount++;
|
|
3556
|
+
suppressed.sampledDurationNs += endedAtNs - startedAtNs;
|
|
3557
|
+
} else {
|
|
3558
|
+
suppressed.lastTimed = false;
|
|
3559
|
+
}
|
|
3396
3560
|
if (suppressed.retainedIndex < 0) {
|
|
3397
3561
|
appendSuppressedPlaceholder(recording, suppressed);
|
|
3398
3562
|
}
|
|
@@ -3505,10 +3669,10 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3505
3669
|
};
|
|
3506
3670
|
const identityComplete = executionTypeKey(execution) !== void 0;
|
|
3507
3671
|
const captureValues = captureValuesFor(execution, livePolicy, startedAtMs);
|
|
3508
|
-
const policySnapshot =
|
|
3672
|
+
const policySnapshot = adaptiveEnabled && !identityComplete ? new Map(livePolicy) : EMPTY_POLICY_SNAPSHOT;
|
|
3509
3673
|
const liveSessions = hooks.sessionCaptureSnapshot?.() ?? EMPTY_SESSION_SNAPSHOT;
|
|
3510
3674
|
const sessionCaptureSnapshot = identityComplete ? EMPTY_SESSION_SNAPSHOT : new Map(liveSessions);
|
|
3511
|
-
if (
|
|
3675
|
+
if (adaptiveEnabled) {
|
|
3512
3676
|
if (captureValues) stats.adaptiveFullExecutions++;
|
|
3513
3677
|
else stats.adaptiveLightExecutions++;
|
|
3514
3678
|
}
|
|
@@ -3655,25 +3819,36 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3655
3819
|
if (group.observedCalls === 1) journal?.notePlan(plan.runtimePlanId);
|
|
3656
3820
|
} catch {
|
|
3657
3821
|
}
|
|
3822
|
+
const timed = durationSamplingEnabled ? decideCallTiming(recording, plan, store.currentFunctionId) : true;
|
|
3658
3823
|
if (group.observedCalls > capturedCallLimitFor(recording)) {
|
|
3659
|
-
const startedAtNs2 =
|
|
3824
|
+
const startedAtNs2 = timed ? readCallClock() : 0n;
|
|
3660
3825
|
try {
|
|
3661
|
-
const result = runStore(
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3826
|
+
const result = runStore(
|
|
3827
|
+
samplingStore(store, plan.functionId),
|
|
3828
|
+
function __rasputinHandleRun__5() {
|
|
3829
|
+
return callback();
|
|
3830
|
+
}
|
|
3831
|
+
);
|
|
3832
|
+
recordSuppressedCall(
|
|
3833
|
+
recording,
|
|
3834
|
+
group,
|
|
3835
|
+
parentCallId,
|
|
3836
|
+
startedAtNs2,
|
|
3837
|
+
timed ? readCallClock() : 0n,
|
|
3838
|
+
timed
|
|
3839
|
+
);
|
|
3665
3840
|
settleInFlight(recording);
|
|
3666
3841
|
return result;
|
|
3667
3842
|
} catch (error) {
|
|
3668
|
-
captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs2, error);
|
|
3843
|
+
captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs2, error, timed);
|
|
3669
3844
|
settleInFlight(recording);
|
|
3670
3845
|
throw error;
|
|
3671
3846
|
}
|
|
3672
3847
|
}
|
|
3673
|
-
const startedAtNs =
|
|
3848
|
+
const startedAtNs = timed ? readCallClock() : 0n;
|
|
3674
3849
|
if (!journal) {
|
|
3675
3850
|
memoryBudget.reserveCall(recording.memory, plan.estimatedCallBytes);
|
|
3676
|
-
return runStore(store, function __rasputinHandleRun__5() {
|
|
3851
|
+
return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
|
|
3677
3852
|
return observeRecordedCallback(
|
|
3678
3853
|
recording,
|
|
3679
3854
|
recorderStartedAtNs,
|
|
@@ -3692,38 +3867,40 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3692
3867
|
countDroppedEvents(recording, droppedBefore);
|
|
3693
3868
|
settleInFlight(recording);
|
|
3694
3869
|
};
|
|
3695
|
-
return runStore(store, function __rasputinHandleRun__5() {
|
|
3870
|
+
return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
|
|
3696
3871
|
return observeRecordedCallback(
|
|
3697
3872
|
recording,
|
|
3698
3873
|
recorderStartedAtNs,
|
|
3699
3874
|
callback,
|
|
3700
3875
|
captureSuccess,
|
|
3701
3876
|
(error) => {
|
|
3702
|
-
captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs, error);
|
|
3877
|
+
captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs, error, timed);
|
|
3703
3878
|
settleInFlight(recording);
|
|
3704
3879
|
}
|
|
3705
3880
|
);
|
|
3706
3881
|
});
|
|
3707
3882
|
}
|
|
3708
3883
|
if (!memoryBudget.reserveCall(recording.memory, plan.estimatedCallBytes)) {
|
|
3709
|
-
return
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3884
|
+
return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
|
|
3885
|
+
return observeRecordedCallback(
|
|
3886
|
+
recording,
|
|
3887
|
+
recorderStartedAtNs,
|
|
3888
|
+
callback,
|
|
3889
|
+
() => settleInFlight(recording),
|
|
3890
|
+
(_error) => {
|
|
3891
|
+
settleInFlight(recording);
|
|
3892
|
+
}
|
|
3893
|
+
);
|
|
3894
|
+
});
|
|
3718
3895
|
}
|
|
3719
3896
|
const callId = ++recording.nextCallId;
|
|
3720
|
-
const enterTimestampNs =
|
|
3897
|
+
const enterTimestampNs = timed ? readCallClock() - recording.startedAtNs : TIMING_UNAVAILABLE;
|
|
3721
3898
|
const capturedArgs = enterPayload(recording, omitCallValues, args);
|
|
3722
3899
|
try {
|
|
3723
3900
|
journal.startCall(plan.runtimePlanId, callId, parentCallId, enterTimestampNs, capturedArgs);
|
|
3724
3901
|
} catch {
|
|
3725
3902
|
journal.dropCall();
|
|
3726
|
-
return runStore(store, function __rasputinHandleRun__5() {
|
|
3903
|
+
return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
|
|
3727
3904
|
return observeRecordedCallback(
|
|
3728
3905
|
recording,
|
|
3729
3906
|
recorderStartedAtNs,
|
|
@@ -3735,7 +3912,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3735
3912
|
);
|
|
3736
3913
|
});
|
|
3737
3914
|
}
|
|
3738
|
-
const callStore =
|
|
3915
|
+
const callStore = callStoreFor(store, plan.functionId, callId);
|
|
3739
3916
|
return runStore(callStore, function __rasputinHandleRun__5() {
|
|
3740
3917
|
return observeRecordedCallback(
|
|
3741
3918
|
recording,
|
|
@@ -3743,15 +3920,25 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3743
3920
|
callback,
|
|
3744
3921
|
(value) => {
|
|
3745
3922
|
if (recording.journal) {
|
|
3746
|
-
const endedAtNs =
|
|
3923
|
+
const endedAtNs = timed ? readCallClock() : void 0;
|
|
3747
3924
|
const returnValue = exitPayload(recording, omitCallValues, value);
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3925
|
+
if (endedAtNs !== void 0) {
|
|
3926
|
+
recording.journal.finishCall(
|
|
3927
|
+
KIND_EXIT,
|
|
3928
|
+
callId,
|
|
3929
|
+
endedAtNs - recording.startedAtNs,
|
|
3930
|
+
endedAtNs - startedAtNs,
|
|
3931
|
+
returnValue
|
|
3932
|
+
);
|
|
3933
|
+
} else {
|
|
3934
|
+
recording.journal.finishCall(
|
|
3935
|
+
KIND_EXIT,
|
|
3936
|
+
callId,
|
|
3937
|
+
TIMING_UNAVAILABLE,
|
|
3938
|
+
TIMING_UNAVAILABLE,
|
|
3939
|
+
returnValue
|
|
3940
|
+
);
|
|
3941
|
+
}
|
|
3755
3942
|
stats.functionCallsCaptured++;
|
|
3756
3943
|
}
|
|
3757
3944
|
settleInFlight(recording);
|
|
@@ -3762,12 +3949,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3762
3949
|
return;
|
|
3763
3950
|
}
|
|
3764
3951
|
const capturedError = serializedError(recording, error, callId);
|
|
3765
|
-
const endedAtNs =
|
|
3952
|
+
const endedAtNs = readCallClock();
|
|
3766
3953
|
recording.journal.finishCall(
|
|
3767
3954
|
KIND_THROW,
|
|
3768
3955
|
callId,
|
|
3769
3956
|
endedAtNs - recording.startedAtNs,
|
|
3770
|
-
endedAtNs - startedAtNs,
|
|
3957
|
+
timed ? endedAtNs - startedAtNs : TIMING_UNAVAILABLE,
|
|
3771
3958
|
capturedError.value
|
|
3772
3959
|
);
|
|
3773
3960
|
stats.functionCallsCaptured++;
|
|
@@ -3779,23 +3966,43 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3779
3966
|
};
|
|
3780
3967
|
const noopHandle2 = passthroughHandle();
|
|
3781
3968
|
class CallFrame {
|
|
3782
|
-
constructor(mode, recording, parentStore, activeStore, plan, args, omitCallValues, parentCallId, startedAtNs, callId, group, captureDroppedThrow) {
|
|
3969
|
+
constructor(mode, recording, parentStore, activeStore, plan, args, omitCallValues, parentCallId, startedAtNs, timed, callId, group, captureDroppedThrow) {
|
|
3783
3970
|
this.mode = mode;
|
|
3784
3971
|
this.status = "open";
|
|
3785
3972
|
this.pendingReturn = void 0;
|
|
3786
3973
|
this.ended = false;
|
|
3787
3974
|
this.suspended = false;
|
|
3788
3975
|
this.startedAtNs = startedAtNs;
|
|
3976
|
+
this.timed = timed;
|
|
3789
3977
|
this.callId = callId;
|
|
3790
3978
|
this.recording = recording;
|
|
3791
3979
|
this.plan = plan;
|
|
3792
3980
|
this.args = args;
|
|
3793
3981
|
this.omitCallValues = omitCallValues;
|
|
3794
3982
|
this.parentCallId = parentCallId;
|
|
3795
|
-
this.parentStore = parentStore;
|
|
3796
3983
|
this.activeStore = activeStore;
|
|
3984
|
+
this.parentStore = parentStore;
|
|
3797
3985
|
this.group = group;
|
|
3798
3986
|
this.captureDroppedThrow = captureDroppedThrow;
|
|
3987
|
+
this.callerClaimed = false;
|
|
3988
|
+
}
|
|
3989
|
+
claimCaller() {
|
|
3990
|
+
if (this.callerClaimed || !durationSamplingEnabled || !this.plan) return;
|
|
3991
|
+
if (this.activeStore !== this.parentStore) return;
|
|
3992
|
+
this.previousFunctionId = this.parentStore.currentFunctionId;
|
|
3993
|
+
this.parentStore.currentFunctionId = this.plan.functionId;
|
|
3994
|
+
this.callerClaimed = true;
|
|
3995
|
+
}
|
|
3996
|
+
reclaimCaller() {
|
|
3997
|
+
if (!durationSamplingEnabled || !this.plan || this.activeStore !== this.parentStore) return;
|
|
3998
|
+
this.parentStore.currentFunctionId = this.plan.functionId;
|
|
3999
|
+
this.callerClaimed = true;
|
|
4000
|
+
}
|
|
4001
|
+
releaseCaller() {
|
|
4002
|
+
if (!this.callerClaimed) return;
|
|
4003
|
+
this.callerClaimed = false;
|
|
4004
|
+
if (this.previousFunctionId === void 0) delete this.parentStore.currentFunctionId;
|
|
4005
|
+
else this.parentStore.currentFunctionId = this.previousFunctionId;
|
|
3799
4006
|
}
|
|
3800
4007
|
leave(value) {
|
|
3801
4008
|
try {
|
|
@@ -3821,6 +4028,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3821
4028
|
this.parentCallId,
|
|
3822
4029
|
this.startedAtNs,
|
|
3823
4030
|
error,
|
|
4031
|
+
this.timed,
|
|
3824
4032
|
this.recording.captureValues ? void 0 : ARGS_OMITTED
|
|
3825
4033
|
);
|
|
3826
4034
|
} else if (this.mode === "dropped" && this.captureDroppedThrow && this.plan) {
|
|
@@ -3831,6 +4039,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3831
4039
|
this.parentCallId,
|
|
3832
4040
|
this.startedAtNs,
|
|
3833
4041
|
error,
|
|
4042
|
+
this.timed,
|
|
3834
4043
|
this.recording.captureValues ? void 0 : ARGS_OMITTED
|
|
3835
4044
|
);
|
|
3836
4045
|
}
|
|
@@ -3849,7 +4058,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3849
4058
|
this.group,
|
|
3850
4059
|
this.parentCallId,
|
|
3851
4060
|
this.startedAtNs,
|
|
3852
|
-
|
|
4061
|
+
this.timed ? readCallClock() : 0n,
|
|
4062
|
+
this.timed
|
|
3853
4063
|
);
|
|
3854
4064
|
} else if (this.mode === "dropped") {
|
|
3855
4065
|
const droppedBefore = this.recording.journal?.dropped ?? 0;
|
|
@@ -3862,6 +4072,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3862
4072
|
try {
|
|
3863
4073
|
if (this.ended) return;
|
|
3864
4074
|
this.ended = true;
|
|
4075
|
+
this.releaseCaller();
|
|
3865
4076
|
if (this.mode !== "excluded") settleInFlight(this.recording);
|
|
3866
4077
|
expectStore(this, this.activeStore);
|
|
3867
4078
|
enterStore(this, this.parentStore);
|
|
@@ -3885,6 +4096,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3885
4096
|
try {
|
|
3886
4097
|
expectStore(this, this.activeStore);
|
|
3887
4098
|
this.suspended = true;
|
|
4099
|
+
this.releaseCaller();
|
|
3888
4100
|
enterStore(this, this.parentStore);
|
|
3889
4101
|
return value;
|
|
3890
4102
|
} catch {
|
|
@@ -3898,6 +4110,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3898
4110
|
expectStore(this, this.parentStore);
|
|
3899
4111
|
this.suspended = false;
|
|
3900
4112
|
enterStore(this, this.activeStore);
|
|
4113
|
+
this.reclaimCaller();
|
|
3901
4114
|
} else {
|
|
3902
4115
|
expectStore(this, this.activeStore);
|
|
3903
4116
|
}
|
|
@@ -3920,32 +4133,42 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3920
4133
|
};
|
|
3921
4134
|
const writeCapturedExit = (frame, value) => {
|
|
3922
4135
|
if (!frame.recording.journal) return;
|
|
3923
|
-
const endedAtNs =
|
|
4136
|
+
const endedAtNs = frame.timed ? readCallClock() : void 0;
|
|
3924
4137
|
const returnValue = exitPayload(frame.recording, frame.omitCallValues, value);
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
4138
|
+
if (endedAtNs !== void 0) {
|
|
4139
|
+
frame.recording.journal.finishCall(
|
|
4140
|
+
KIND_EXIT,
|
|
4141
|
+
frame.callId,
|
|
4142
|
+
endedAtNs - frame.recording.startedAtNs,
|
|
4143
|
+
endedAtNs - frame.startedAtNs,
|
|
4144
|
+
returnValue
|
|
4145
|
+
);
|
|
4146
|
+
} else {
|
|
4147
|
+
frame.recording.journal.finishCall(
|
|
4148
|
+
KIND_EXIT,
|
|
4149
|
+
frame.callId,
|
|
4150
|
+
TIMING_UNAVAILABLE,
|
|
4151
|
+
TIMING_UNAVAILABLE,
|
|
4152
|
+
returnValue
|
|
4153
|
+
);
|
|
4154
|
+
}
|
|
3932
4155
|
stats.functionCallsCaptured++;
|
|
3933
4156
|
};
|
|
3934
4157
|
const writeCapturedThrow = (frame, error) => {
|
|
3935
4158
|
if (!frame.recording.journal) return;
|
|
3936
|
-
const endedAtNs =
|
|
4159
|
+
const endedAtNs = readCallClock();
|
|
3937
4160
|
const capturedError = serializedError(frame.recording, error, frame.callId);
|
|
3938
4161
|
frame.recording.journal.finishCall(
|
|
3939
4162
|
KIND_THROW,
|
|
3940
4163
|
frame.callId,
|
|
3941
4164
|
endedAtNs - frame.recording.startedAtNs,
|
|
3942
|
-
endedAtNs - frame.startedAtNs,
|
|
4165
|
+
frame.timed ? endedAtNs - frame.startedAtNs : TIMING_UNAVAILABLE,
|
|
3943
4166
|
capturedError.value
|
|
3944
4167
|
);
|
|
3945
4168
|
stats.functionCallsCaptured++;
|
|
3946
4169
|
capturedError.commit();
|
|
3947
4170
|
};
|
|
3948
|
-
const activateUncaptured = (mode, recording, parentStore, plan, args, omitCallValues, parentCallId, startedAtNs, group, captureDroppedThrow) => {
|
|
4171
|
+
const activateUncaptured = (mode, recording, parentStore, plan, args, omitCallValues, parentCallId, startedAtNs, timed, group, captureDroppedThrow) => {
|
|
3949
4172
|
const frame = new CallFrame(
|
|
3950
4173
|
mode,
|
|
3951
4174
|
recording,
|
|
@@ -3956,10 +4179,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3956
4179
|
omitCallValues,
|
|
3957
4180
|
parentCallId,
|
|
3958
4181
|
startedAtNs,
|
|
4182
|
+
timed,
|
|
3959
4183
|
0,
|
|
3960
4184
|
group,
|
|
3961
4185
|
captureDroppedThrow
|
|
3962
4186
|
);
|
|
4187
|
+
frame.claimCaller();
|
|
3963
4188
|
enterStore(frame, parentStore);
|
|
3964
4189
|
return frame;
|
|
3965
4190
|
};
|
|
@@ -3982,6 +4207,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3982
4207
|
false,
|
|
3983
4208
|
void 0,
|
|
3984
4209
|
0n,
|
|
4210
|
+
true,
|
|
3985
4211
|
0,
|
|
3986
4212
|
void 0,
|
|
3987
4213
|
false
|
|
@@ -4004,6 +4230,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4004
4230
|
false,
|
|
4005
4231
|
void 0,
|
|
4006
4232
|
0n,
|
|
4233
|
+
true,
|
|
4007
4234
|
0,
|
|
4008
4235
|
void 0,
|
|
4009
4236
|
false
|
|
@@ -4019,7 +4246,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4019
4246
|
if (group.observedCalls === 1) journal?.notePlan(plan.runtimePlanId);
|
|
4020
4247
|
} catch {
|
|
4021
4248
|
}
|
|
4022
|
-
const
|
|
4249
|
+
const timed = durationSamplingEnabled ? decideCallTiming(recording, plan, store.currentFunctionId) : true;
|
|
4250
|
+
const startedAtNs = timed ? readCallClock() : 0n;
|
|
4023
4251
|
const parentStore = store;
|
|
4024
4252
|
const retainedArgs = recording.captureValues ? args : EMPTY_ARGS;
|
|
4025
4253
|
if (group.observedCalls > capturedCallLimitFor(recording)) {
|
|
@@ -4032,6 +4260,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4032
4260
|
omitCallValues,
|
|
4033
4261
|
parentCallId,
|
|
4034
4262
|
startedAtNs,
|
|
4263
|
+
timed,
|
|
4035
4264
|
group,
|
|
4036
4265
|
false
|
|
4037
4266
|
);
|
|
@@ -4047,6 +4276,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4047
4276
|
omitCallValues,
|
|
4048
4277
|
parentCallId,
|
|
4049
4278
|
startedAtNs,
|
|
4279
|
+
timed,
|
|
4050
4280
|
group,
|
|
4051
4281
|
false
|
|
4052
4282
|
);
|
|
@@ -4061,6 +4291,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4061
4291
|
omitCallValues,
|
|
4062
4292
|
parentCallId,
|
|
4063
4293
|
startedAtNs,
|
|
4294
|
+
timed,
|
|
4064
4295
|
group,
|
|
4065
4296
|
true
|
|
4066
4297
|
);
|
|
@@ -4075,12 +4306,13 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4075
4306
|
omitCallValues,
|
|
4076
4307
|
parentCallId,
|
|
4077
4308
|
startedAtNs,
|
|
4309
|
+
timed,
|
|
4078
4310
|
group,
|
|
4079
4311
|
false
|
|
4080
4312
|
);
|
|
4081
4313
|
}
|
|
4082
4314
|
const callId = ++recording.nextCallId;
|
|
4083
|
-
const enterTimestampNs =
|
|
4315
|
+
const enterTimestampNs = timed ? readCallClock() - recording.startedAtNs : TIMING_UNAVAILABLE;
|
|
4084
4316
|
const capturedArgs = enterPayload(recording, omitCallValues, args);
|
|
4085
4317
|
try {
|
|
4086
4318
|
journal.startCall(plan.runtimePlanId, callId, parentCallId, enterTimestampNs, capturedArgs);
|
|
@@ -4095,11 +4327,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4095
4327
|
omitCallValues,
|
|
4096
4328
|
parentCallId,
|
|
4097
4329
|
startedAtNs,
|
|
4330
|
+
timed,
|
|
4098
4331
|
group,
|
|
4099
4332
|
false
|
|
4100
4333
|
);
|
|
4101
4334
|
}
|
|
4102
|
-
const callStore =
|
|
4335
|
+
const callStore = callStoreFor(store, plan.functionId, callId);
|
|
4103
4336
|
const captured = new CallFrame(
|
|
4104
4337
|
"captured",
|
|
4105
4338
|
recording,
|
|
@@ -4110,6 +4343,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4110
4343
|
omitCallValues,
|
|
4111
4344
|
parentCallId,
|
|
4112
4345
|
startedAtNs,
|
|
4346
|
+
timed,
|
|
4113
4347
|
callId,
|
|
4114
4348
|
group,
|
|
4115
4349
|
false
|
|
@@ -4178,6 +4412,9 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4178
4412
|
runPreparedFunction,
|
|
4179
4413
|
enterPreparedFunction,
|
|
4180
4414
|
trace,
|
|
4415
|
+
close: () => {
|
|
4416
|
+
durationSamples?.stop();
|
|
4417
|
+
},
|
|
4181
4418
|
getStats: () => ({
|
|
4182
4419
|
...stats,
|
|
4183
4420
|
...memoryBudget.getStats(),
|
|
@@ -5079,7 +5316,7 @@ var createExecutionRecordingCoordinator = (options) => {
|
|
|
5079
5316
|
// src/execution-recorder/bind-adaptive-recorder.ts
|
|
5080
5317
|
var bindAdaptiveRecorder = (input) => {
|
|
5081
5318
|
const options = input.executionRecorder;
|
|
5082
|
-
const
|
|
5319
|
+
const adaptiveEnabled = options?.adaptive?.enabled === true;
|
|
5083
5320
|
const activation = resolveClientActivation({
|
|
5084
5321
|
enabled: input.enabled,
|
|
5085
5322
|
dsn: input.dsn,
|
|
@@ -5098,14 +5335,14 @@ var bindAdaptiveRecorder = (input) => {
|
|
|
5098
5335
|
release: activation.release,
|
|
5099
5336
|
recorderOptions: options,
|
|
5100
5337
|
scrubPII: input.scrubPII,
|
|
5101
|
-
mode,
|
|
5338
|
+
mode: adaptiveEnabled ? "adaptive" : "full",
|
|
5102
5339
|
fetch: input.fetch
|
|
5103
5340
|
}) : void 0;
|
|
5104
5341
|
const runtime = createExecutionRecorder(
|
|
5105
5342
|
{ ...options, enabled: input.recorderEnabled },
|
|
5106
5343
|
coordinator ? {
|
|
5107
5344
|
policySnapshot: coordinator.peek,
|
|
5108
|
-
onQualifyingFailure:
|
|
5345
|
+
onQualifyingFailure: adaptiveEnabled ? coordinator.activate : void 0,
|
|
5109
5346
|
getStats: coordinator.getStats,
|
|
5110
5347
|
sessionCaptureSnapshot: coordinator.peekSessions,
|
|
5111
5348
|
consumeSession: coordinator.consumeSession,
|
|
@@ -5254,7 +5491,7 @@ var installGlobalHandlers = (client, options = {}) => {
|
|
|
5254
5491
|
|
|
5255
5492
|
// src/sdk-meta.ts
|
|
5256
5493
|
var SDK_NAME = "@rasputin-ai/node";
|
|
5257
|
-
var SDK_VERSION = "0.
|
|
5494
|
+
var SDK_VERSION = "0.12.1";
|
|
5258
5495
|
|
|
5259
5496
|
// src/rasputin-init.ts
|
|
5260
5497
|
var publicExecution = (runtime) => ({
|
|
@@ -5299,6 +5536,7 @@ var withExecution = (client, runtime, installRuntime, manifest, uninstallHandler
|
|
|
5299
5536
|
close: async () => {
|
|
5300
5537
|
uninstallHandlers();
|
|
5301
5538
|
uninstallRuntime();
|
|
5539
|
+
runtime.close();
|
|
5302
5540
|
manifestUpload.disconnect();
|
|
5303
5541
|
const startedAt = Date.now();
|
|
5304
5542
|
await policy?.close();
|