@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/internal.js
CHANGED
|
@@ -644,9 +644,6 @@ import {
|
|
|
644
644
|
var DEFAULT_FULL_CAPTURE_DURATION_MS = 24 * 60 * 60 * 1e3;
|
|
645
645
|
var MIN_FULL_CAPTURE_DURATION_MS = 1e3;
|
|
646
646
|
var MAX_FULL_CAPTURE_DURATION_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
647
|
-
var sanitizeRecorderMode = (mode) => {
|
|
648
|
-
return mode === "adaptive" ? "adaptive" : "full";
|
|
649
|
-
};
|
|
650
647
|
var sanitizeFullCaptureDurationMs = (value) => {
|
|
651
648
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
652
649
|
return DEFAULT_FULL_CAPTURE_DURATION_MS;
|
|
@@ -656,6 +653,68 @@ var sanitizeFullCaptureDurationMs = (value) => {
|
|
|
656
653
|
Math.max(MIN_FULL_CAPTURE_DURATION_MS, Math.floor(value))
|
|
657
654
|
);
|
|
658
655
|
};
|
|
656
|
+
var sanitizeDynamicDurationSampling = (value) => value === true;
|
|
657
|
+
|
|
658
|
+
// src/execution-recorder/dynamic-duration-sampling.ts
|
|
659
|
+
var DYNAMIC_DURATION_SAMPLE_STAGES = [
|
|
660
|
+
{ below: 10, divisor: 1 },
|
|
661
|
+
{ below: 30, divisor: 2 },
|
|
662
|
+
{ below: 100, divisor: 3 },
|
|
663
|
+
{ below: 500, divisor: 11 },
|
|
664
|
+
{ below: 1e3, divisor: 23 },
|
|
665
|
+
{ below: 5e3, divisor: 53 }
|
|
666
|
+
];
|
|
667
|
+
var DYNAMIC_DURATION_SAMPLE_TAIL_AFTER = 5e3;
|
|
668
|
+
var DYNAMIC_DURATION_SAMPLE_TAIL_DIVISOR = 100;
|
|
669
|
+
var DYNAMIC_DURATION_SAMPLE_RESET_MS = 60 * 60 * 1e3;
|
|
670
|
+
var MAX_DYNAMIC_DURATION_SAMPLE_BUCKETS = 4096;
|
|
671
|
+
var dynamicDurationSampleDivisor = (index) => {
|
|
672
|
+
for (const stage of DYNAMIC_DURATION_SAMPLE_STAGES) {
|
|
673
|
+
if (index < stage.below) return stage.divisor;
|
|
674
|
+
}
|
|
675
|
+
return DYNAMIC_DURATION_SAMPLE_TAIL_DIVISOR;
|
|
676
|
+
};
|
|
677
|
+
var shouldSampleDynamicDuration = (index) => {
|
|
678
|
+
return index % dynamicDurationSampleDivisor(index) === 0;
|
|
679
|
+
};
|
|
680
|
+
var nextDurationSampleIndex = (index) => {
|
|
681
|
+
if (index < Number.MAX_SAFE_INTEGER) return index + 1;
|
|
682
|
+
return DYNAMIC_DURATION_SAMPLE_TAIL_AFTER + (index - DYNAMIC_DURATION_SAMPLE_TAIL_AFTER + 1) % DYNAMIC_DURATION_SAMPLE_TAIL_DIVISOR;
|
|
683
|
+
};
|
|
684
|
+
var createDynamicDurationSampleBuckets = (options) => {
|
|
685
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
686
|
+
const maxBuckets = options.maxBuckets ?? MAX_DYNAMIC_DURATION_SAMPLE_BUCKETS;
|
|
687
|
+
const resetMs = options.resetMs ?? DYNAMIC_DURATION_SAMPLE_RESET_MS;
|
|
688
|
+
let lastResetAtMs = options.nowMs();
|
|
689
|
+
const reset = () => {
|
|
690
|
+
buckets.clear();
|
|
691
|
+
lastResetAtMs = options.nowMs();
|
|
692
|
+
};
|
|
693
|
+
const resetTimer = setInterval(reset, resetMs);
|
|
694
|
+
resetTimer.unref?.();
|
|
695
|
+
return {
|
|
696
|
+
take: (executionType, callerFunctionId, functionId) => {
|
|
697
|
+
if (options.nowMs() - lastResetAtMs >= resetMs) reset();
|
|
698
|
+
const key = `${executionType}\0${callerFunctionId}\0${functionId}`;
|
|
699
|
+
const existing = buckets.get(key);
|
|
700
|
+
if (existing !== void 0) {
|
|
701
|
+
buckets.delete(key);
|
|
702
|
+
buckets.set(key, nextDurationSampleIndex(existing));
|
|
703
|
+
return shouldSampleDynamicDuration(existing);
|
|
704
|
+
}
|
|
705
|
+
while (buckets.size >= maxBuckets) {
|
|
706
|
+
const oldest = buckets.keys().next().value;
|
|
707
|
+
if (oldest === void 0) break;
|
|
708
|
+
buckets.delete(oldest);
|
|
709
|
+
}
|
|
710
|
+
buckets.set(key, nextDurationSampleIndex(0));
|
|
711
|
+
return shouldSampleDynamicDuration(0);
|
|
712
|
+
},
|
|
713
|
+
stop: () => {
|
|
714
|
+
clearInterval(resetTimer);
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
};
|
|
659
718
|
|
|
660
719
|
// src/execution-recorder/error-observation.ts
|
|
661
720
|
var bindings = /* @__PURE__ */ new WeakMap();
|
|
@@ -704,15 +763,17 @@ var KIND_SUPPRESSED = 4;
|
|
|
704
763
|
var ARGS_OMITTED = Symbol("rasputin.argsOmitted");
|
|
705
764
|
var NO_PARENT = 4294967295;
|
|
706
765
|
var NO_SUPPRESSION = 4294967295;
|
|
766
|
+
var TIMING_UNAVAILABLE = -1n;
|
|
707
767
|
var MAX_POOLED_JOURNALS = 8;
|
|
708
768
|
var MAX_POOLED_JOURNAL_CAPACITY = 4096;
|
|
709
769
|
var INITIAL_JOURNAL_STORAGE = 32;
|
|
710
770
|
var BYTES_PER_EVENT = Uint8Array.BYTES_PER_ELEMENT + Uint32Array.BYTES_PER_ELEMENT * 4 + BigInt64Array.BYTES_PER_ELEMENT * 2;
|
|
711
|
-
var DEFAULT_MAX_EVENTS_PER_EXECUTION =
|
|
771
|
+
var DEFAULT_MAX_EVENTS_PER_EXECUTION = 1500;
|
|
712
772
|
var MAX_JOURNAL_EVENTS = 16384;
|
|
713
773
|
var elapsedMs = (startedAtNs, endedAtNs) => Number(endedAtNs - startedAtNs) / 1e6;
|
|
714
774
|
var roundedMilliseconds = (nanoseconds) => Math.round(Number(nanoseconds) / 1e6 * 1e4) / 1e4;
|
|
715
775
|
var relativeMs = (relativeNs) => Number(relativeNs) / 1e6;
|
|
776
|
+
var measuredRelativeMs = (relativeNs) => relativeNs === TIMING_UNAVAILABLE ? void 0 : relativeMs(relativeNs);
|
|
716
777
|
var sanitizeJournalCapacity = (value) => {
|
|
717
778
|
const requested = value ?? DEFAULT_MAX_EVENTS_PER_EXECUTION;
|
|
718
779
|
if (!Number.isFinite(requested)) return DEFAULT_MAX_EVENTS_PER_EXECUTION;
|
|
@@ -894,44 +955,53 @@ var ExecutionJournal = class {
|
|
|
894
955
|
if (!functionId) return void 0;
|
|
895
956
|
const parentCallId = this.parentCallId[index] ?? NO_PARENT;
|
|
896
957
|
const payload = this.payloads[index];
|
|
958
|
+
const timestampMs = measuredRelativeMs(this.timestampNs[index] ?? TIMING_UNAVAILABLE);
|
|
897
959
|
return {
|
|
898
960
|
type: "function_enter",
|
|
899
961
|
callId: this.callId[index] ?? 0,
|
|
900
962
|
functionId,
|
|
901
|
-
timestampMs:
|
|
963
|
+
...timestampMs === void 0 ? {} : { timestampMs },
|
|
902
964
|
...payload === ARGS_OMITTED ? { argsOmitted: true } : { args: Array.isArray(payload) ? payload : [] },
|
|
903
965
|
...parentCallId === NO_PARENT ? {} : { parentCallId }
|
|
904
966
|
};
|
|
905
967
|
}
|
|
906
968
|
if (kind === KIND_EXIT) {
|
|
907
969
|
const payload = this.payloads[index];
|
|
970
|
+
const timestampMs = measuredRelativeMs(this.timestampNs[index] ?? TIMING_UNAVAILABLE);
|
|
971
|
+
const durationMs = measuredRelativeMs(this.durationNs[index] ?? TIMING_UNAVAILABLE);
|
|
908
972
|
return {
|
|
909
973
|
type: "function_exit",
|
|
910
974
|
callId: this.callId[index] ?? 0,
|
|
911
|
-
timestampMs:
|
|
912
|
-
durationMs:
|
|
975
|
+
...timestampMs === void 0 ? {} : { timestampMs },
|
|
976
|
+
...durationMs === void 0 ? {} : { durationMs },
|
|
913
977
|
...payload === ARGS_OMITTED ? {} : { returnValue: payload }
|
|
914
978
|
};
|
|
915
979
|
}
|
|
916
980
|
if (kind === KIND_THROW) {
|
|
981
|
+
const timestampMs = measuredRelativeMs(this.timestampNs[index] ?? TIMING_UNAVAILABLE);
|
|
982
|
+
const durationMs = measuredRelativeMs(this.durationNs[index] ?? TIMING_UNAVAILABLE);
|
|
917
983
|
return {
|
|
918
984
|
type: "function_throw",
|
|
919
985
|
callId: this.callId[index] ?? 0,
|
|
920
|
-
timestampMs:
|
|
921
|
-
durationMs:
|
|
986
|
+
...timestampMs === void 0 ? {} : { timestampMs },
|
|
987
|
+
...durationMs === void 0 ? {} : { durationMs },
|
|
922
988
|
error: this.payloads[index]
|
|
923
989
|
};
|
|
924
990
|
}
|
|
925
991
|
if (kind === KIND_SUPPRESSED) {
|
|
926
992
|
const group = this.suppressions[this.suppressionIndex[index] ?? 0];
|
|
927
993
|
if (!group) return void 0;
|
|
994
|
+
const sampledDurationCount = group.sampledDurationCount;
|
|
995
|
+
const allTimed = sampledDurationCount === group.count && group.count > 0;
|
|
928
996
|
return {
|
|
929
997
|
type: "function_calls_suppressed",
|
|
930
998
|
functionId: group.functionId,
|
|
931
|
-
timestampMs: elapsedMs(executionStartedAtNs, group.firstTimestampNs),
|
|
932
|
-
lastTimestampMs: elapsedMs(executionStartedAtNs, group.lastTimestampNs),
|
|
933
999
|
suppressedCallCount: group.count,
|
|
934
|
-
|
|
1000
|
+
sampledDurationCount,
|
|
1001
|
+
...group.firstTimed ? { timestampMs: elapsedMs(executionStartedAtNs, group.firstTimestampNs) } : {},
|
|
1002
|
+
...group.lastTimed ? { lastTimestampMs: elapsedMs(executionStartedAtNs, group.lastTimestampNs) } : {},
|
|
1003
|
+
...allTimed ? { totalDurationMs: roundedMilliseconds(group.sampledDurationNs) } : {},
|
|
1004
|
+
...sampledDurationCount > 0 ? { sampledDurationMs: roundedMilliseconds(group.sampledDurationNs) } : {},
|
|
935
1005
|
...group.parentCallId === void 0 ? {} : { parentCallId: group.parentCallId }
|
|
936
1006
|
};
|
|
937
1007
|
}
|
|
@@ -1088,6 +1158,69 @@ var ExecutionJournalPool = class {
|
|
|
1088
1158
|
var EVENT_PAIR_BASE_ESTIMATED_BYTES = 512;
|
|
1089
1159
|
var estimatedCallBytesFor = (functionId) => EVENT_PAIR_BASE_ESTIMATED_BYTES + Buffer.byteLength(functionId, "utf8") * 2;
|
|
1090
1160
|
|
|
1161
|
+
// src/execution-recorder/publish-runtime-state.ts
|
|
1162
|
+
var measured = (value) => typeof value === "number";
|
|
1163
|
+
var eventsAreFullyTimed = (events) => {
|
|
1164
|
+
for (const event of events) {
|
|
1165
|
+
if (event.type === "function_enter" || event.type === "awaited" || event.type === "expression_observed") {
|
|
1166
|
+
if (!measured(event.timestampMs)) return false;
|
|
1167
|
+
continue;
|
|
1168
|
+
}
|
|
1169
|
+
if (event.type === "function_exit" || event.type === "function_throw") {
|
|
1170
|
+
if (!measured(event.timestampMs) || !measured(event.durationMs)) return false;
|
|
1171
|
+
continue;
|
|
1172
|
+
}
|
|
1173
|
+
const sampled = event.sampledDurationCount ?? (measured(event.totalDurationMs) ? event.suppressedCallCount : 0);
|
|
1174
|
+
if (!measured(event.timestampMs) || !measured(event.totalDurationMs) || sampled !== event.suppressedCallCount) {
|
|
1175
|
+
return false;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
return true;
|
|
1179
|
+
};
|
|
1180
|
+
var retainedTimingsCoverage = (events) => {
|
|
1181
|
+
let sawMeasured = false;
|
|
1182
|
+
let sawMissing = false;
|
|
1183
|
+
const mark = (complete) => {
|
|
1184
|
+
if (complete) sawMeasured = true;
|
|
1185
|
+
else sawMissing = true;
|
|
1186
|
+
};
|
|
1187
|
+
for (const event of events) {
|
|
1188
|
+
if (event.type === "function_enter" || event.type === "awaited" || event.type === "expression_observed") {
|
|
1189
|
+
mark(measured(event.timestampMs));
|
|
1190
|
+
continue;
|
|
1191
|
+
}
|
|
1192
|
+
if (event.type === "function_exit" || event.type === "function_throw") {
|
|
1193
|
+
const stamped = measured(event.timestampMs);
|
|
1194
|
+
const timed = measured(event.durationMs);
|
|
1195
|
+
if (stamped && timed) mark(true);
|
|
1196
|
+
else if (!stamped && !timed) mark(false);
|
|
1197
|
+
else {
|
|
1198
|
+
sawMeasured = true;
|
|
1199
|
+
sawMissing = true;
|
|
1200
|
+
}
|
|
1201
|
+
continue;
|
|
1202
|
+
}
|
|
1203
|
+
const sampled = event.sampledDurationCount ?? (measured(event.totalDurationMs) ? event.suppressedCallCount : 0);
|
|
1204
|
+
if (sampled > 0) sawMeasured = true;
|
|
1205
|
+
if (sampled < event.suppressedCallCount || !measured(event.timestampMs)) sawMissing = true;
|
|
1206
|
+
}
|
|
1207
|
+
if (sawMeasured && sawMissing) return "partial";
|
|
1208
|
+
if (sawMeasured) return "full";
|
|
1209
|
+
return "none";
|
|
1210
|
+
};
|
|
1211
|
+
var asFullyTimedEvents = (events) => events.map((event) => {
|
|
1212
|
+
if (event.type !== "function_calls_suppressed") return event;
|
|
1213
|
+
return {
|
|
1214
|
+
type: "function_calls_suppressed",
|
|
1215
|
+
functionId: event.functionId,
|
|
1216
|
+
suppressedCallCount: event.suppressedCallCount,
|
|
1217
|
+
...event.parentCallId === void 0 ? {} : { parentCallId: event.parentCallId },
|
|
1218
|
+
...event.timestampMs === void 0 ? {} : { timestampMs: event.timestampMs },
|
|
1219
|
+
...event.lastTimestampMs === void 0 ? {} : { lastTimestampMs: event.lastTimestampMs },
|
|
1220
|
+
...event.totalDurationMs === void 0 ? {} : { totalDurationMs: event.totalDurationMs }
|
|
1221
|
+
};
|
|
1222
|
+
});
|
|
1223
|
+
|
|
1091
1224
|
// src/execution-recorder/recorder-memory-budget.ts
|
|
1092
1225
|
var EXECUTION_BASE_ESTIMATED_BYTES = 1024;
|
|
1093
1226
|
var SUMMARY_EVENT_BASE_ESTIMATED_BYTES = 256;
|
|
@@ -1271,7 +1404,7 @@ var dropEventValues = (events) => {
|
|
|
1271
1404
|
const marker = () => rasputinUnavailable(VALUE_OMITTED_REASON);
|
|
1272
1405
|
const bounded2 = events.map((event) => {
|
|
1273
1406
|
if (event.type === "function_enter") {
|
|
1274
|
-
if (event.args === void 0) return
|
|
1407
|
+
if (event.args === void 0) return event;
|
|
1275
1408
|
dropped += event.args.length;
|
|
1276
1409
|
return { ...event, args: event.args.map(marker) };
|
|
1277
1410
|
}
|
|
@@ -1283,7 +1416,7 @@ var dropEventValues = (events) => {
|
|
|
1283
1416
|
dropped++;
|
|
1284
1417
|
return { ...event, error: marker() };
|
|
1285
1418
|
}
|
|
1286
|
-
return
|
|
1419
|
+
return event;
|
|
1287
1420
|
});
|
|
1288
1421
|
return { events: bounded2, dropped };
|
|
1289
1422
|
};
|
|
@@ -1324,7 +1457,7 @@ var minimalState = (state, size) => {
|
|
|
1324
1457
|
startedAt: truncateUtf8(state.startedAt, 128) ?? "",
|
|
1325
1458
|
durationMs: Number.isFinite(state.durationMs) ? state.durationMs : 0,
|
|
1326
1459
|
recorder: {
|
|
1327
|
-
inlineWallTimeMs: Number.isFinite(state.recorder
|
|
1460
|
+
inlineWallTimeMs: state.recorder && Number.isFinite(state.recorder.inlineWallTimeMs) ? state.recorder.inlineWallTimeMs : 0
|
|
1328
1461
|
},
|
|
1329
1462
|
execution,
|
|
1330
1463
|
functions: [],
|
|
@@ -1342,20 +1475,14 @@ var enforceRuntimeStateSizeBudget = (input) => {
|
|
|
1342
1475
|
const originalBytes = existingSize?.originalBytes ?? initialBytes;
|
|
1343
1476
|
const size = sizeMetadata(originalBytes);
|
|
1344
1477
|
let state = input;
|
|
1478
|
+
const captureProfile = {
|
|
1479
|
+
...state.captureProfile,
|
|
1480
|
+
functionValues: state.captureProfile.functionValues === "none" ? "none" : "selective"
|
|
1481
|
+
};
|
|
1345
1482
|
const stripped = dropEventValues(state.events);
|
|
1346
1483
|
size.eventValuesDropped += stripped.dropped;
|
|
1347
1484
|
state = settleFinalBytes(
|
|
1348
|
-
withSizeMetadata(
|
|
1349
|
-
{
|
|
1350
|
-
...state,
|
|
1351
|
-
captureProfile: {
|
|
1352
|
-
...state.captureProfile,
|
|
1353
|
-
functionValues: state.captureProfile.functionValues === "none" ? "none" : "selective"
|
|
1354
|
-
},
|
|
1355
|
-
events: stripped.events
|
|
1356
|
-
},
|
|
1357
|
-
size
|
|
1358
|
-
)
|
|
1485
|
+
withSizeMetadata({ ...state, captureProfile, events: stripped.events }, size)
|
|
1359
1486
|
);
|
|
1360
1487
|
if (encodedBytes(state) <= MAX_RUNTIME_STATE_BYTES) return state;
|
|
1361
1488
|
size.eventsDropped += state.events.length;
|
|
@@ -2513,6 +2640,7 @@ var warnIfMissingAsyncContextFrame = () => {
|
|
|
2513
2640
|
|
|
2514
2641
|
// src/execution-recorder/execution-recorder.ts
|
|
2515
2642
|
var DEFAULT_MAX_ACTIVE_MEMORY_BYTES = 64 * 1024 * 1024;
|
|
2643
|
+
var DEFAULT_MAX_CAPTURED_CALLS_PER_FUNCTION = 1;
|
|
2516
2644
|
var DEFAULT_MAX_EXECUTION_HOLD_MS = 6e4;
|
|
2517
2645
|
var DEFAULT_MAX_RETAINED_ERROR_RECORDINGS = 32;
|
|
2518
2646
|
var EMPTY_ARGS = [];
|
|
@@ -2630,7 +2758,9 @@ var noOpExecution = {
|
|
|
2630
2758
|
resume: (value) => value
|
|
2631
2759
|
}),
|
|
2632
2760
|
trace: (_functionId, fn) => fn,
|
|
2633
|
-
getStats: () => ({ ...emptyStats })
|
|
2761
|
+
getStats: () => ({ ...emptyStats }),
|
|
2762
|
+
close: () => {
|
|
2763
|
+
}
|
|
2634
2764
|
};
|
|
2635
2765
|
var mergeExecutionMetadata = (target, metadata) => {
|
|
2636
2766
|
if (metadata.kind) target.kind = metadata.kind;
|
|
@@ -2642,35 +2772,44 @@ var newRepeatedGroup = (plan) => ({
|
|
|
2642
2772
|
functionId: plan.functionId,
|
|
2643
2773
|
runtimePlanId: plan.runtimePlanId
|
|
2644
2774
|
});
|
|
2645
|
-
var newSuppression = (group, parentCallId, startedAtNs, endedAtNs) =>
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2775
|
+
var newSuppression = (group, parentCallId, startedAtNs, endedAtNs, timed) => {
|
|
2776
|
+
const durationNs = timed ? endedAtNs - startedAtNs : 0n;
|
|
2777
|
+
return {
|
|
2778
|
+
count: 1,
|
|
2779
|
+
firstTimestampNs: timed ? startedAtNs : 0n,
|
|
2780
|
+
lastTimestampNs: timed ? endedAtNs : 0n,
|
|
2781
|
+
sampledDurationNs: durationNs,
|
|
2782
|
+
sampledDurationCount: timed ? 1 : 0,
|
|
2783
|
+
firstTimed: timed,
|
|
2784
|
+
lastTimed: timed,
|
|
2785
|
+
functionId: group.functionId,
|
|
2786
|
+
runtimePlanId: group.runtimePlanId,
|
|
2787
|
+
...parentCallId === void 0 ? {} : { parentCallId },
|
|
2788
|
+
storageIndex: -1,
|
|
2789
|
+
retainedIndex: -1
|
|
2790
|
+
};
|
|
2791
|
+
};
|
|
2656
2792
|
var EMPTY_POLICY_SNAPSHOT = /* @__PURE__ */ new Map();
|
|
2657
2793
|
var EMPTY_SESSION_SNAPSHOT = /* @__PURE__ */ new Map();
|
|
2658
2794
|
var createExecutionRecorder = (options, hooks = {}) => {
|
|
2659
2795
|
if (!options?.enabled) return noOpExecution;
|
|
2660
2796
|
warnIfMissingAsyncContextFrame();
|
|
2661
|
-
const
|
|
2797
|
+
const adaptiveEnabled = options.adaptive?.enabled === true;
|
|
2662
2798
|
const fullCaptureDurationMs = sanitizeFullCaptureDurationMs(
|
|
2663
2799
|
options.adaptive?.fullCaptureDurationMs
|
|
2664
2800
|
);
|
|
2665
|
-
const
|
|
2801
|
+
const durationSamplingEnabled = adaptiveEnabled && sanitizeDynamicDurationSampling(options.adaptive?.dynamicDurationSampling);
|
|
2802
|
+
const readCallClock = () => process.hrtime.bigint();
|
|
2666
2803
|
const nowMs = () => hooks.nowMs?.() ?? Date.now();
|
|
2804
|
+
const durationSamples = durationSamplingEnabled ? createDynamicDurationSampleBuckets({ nowMs }) : void 0;
|
|
2805
|
+
const localActivations = /* @__PURE__ */ new Map();
|
|
2667
2806
|
const policySnapshotFor = () => hooks.policySnapshot?.() ?? localActivations;
|
|
2668
2807
|
const keyIsActive = (snapshot, key, atMs) => {
|
|
2669
2808
|
const expiresAt = snapshot.get(key);
|
|
2670
2809
|
return expiresAt !== void 0 && expiresAt > atMs;
|
|
2671
2810
|
};
|
|
2672
2811
|
const captureValuesFor = (metadata, snapshot, atMs) => {
|
|
2673
|
-
if (
|
|
2812
|
+
if (!adaptiveEnabled) return true;
|
|
2674
2813
|
const key = executionTypeKey(metadata);
|
|
2675
2814
|
if (!key) return false;
|
|
2676
2815
|
return keyIsActive(snapshot, key, atMs);
|
|
@@ -2712,7 +2851,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2712
2851
|
const maxEventsPerExecution = sanitizeJournalCapacity(options.maxEventsPerExecution);
|
|
2713
2852
|
const maxCapturedCallsPerFunction = Math.max(
|
|
2714
2853
|
1,
|
|
2715
|
-
Math.floor(options.maxCapturedCallsPerFunction ??
|
|
2854
|
+
Math.floor(options.maxCapturedCallsPerFunction ?? DEFAULT_MAX_CAPTURED_CALLS_PER_FUNCTION)
|
|
2716
2855
|
);
|
|
2717
2856
|
const maxActiveMemoryBytes = Math.max(
|
|
2718
2857
|
0,
|
|
@@ -2822,7 +2961,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2822
2961
|
return captureValue(recording, value);
|
|
2823
2962
|
};
|
|
2824
2963
|
const admitSession = (recording, session) => {
|
|
2825
|
-
const wasLight =
|
|
2964
|
+
const wasLight = adaptiveEnabled && !recording.captureValues;
|
|
2826
2965
|
recording.retainSuccess = true;
|
|
2827
2966
|
recording.sessionId = session.sessionId;
|
|
2828
2967
|
recording.captureValues = true;
|
|
@@ -2847,6 +2986,21 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2847
2986
|
}
|
|
2848
2987
|
};
|
|
2849
2988
|
const skipCapture = (store, plan) => store.suppressCapture || plan.excluded || Boolean(store.recording.sessionExcludes?.(plan.definition));
|
|
2989
|
+
const durationSamplingApplies = (recording) => durationSamplingEnabled && recording.identityResolved === true && !recording.captureValues && !recording.retainSuccess;
|
|
2990
|
+
const callStoreFor = (store, functionId, callId) => {
|
|
2991
|
+
const next = { ...store, currentCallId: callId };
|
|
2992
|
+
if (durationSamplingEnabled) next.currentFunctionId = functionId;
|
|
2993
|
+
return next;
|
|
2994
|
+
};
|
|
2995
|
+
const samplingStore = (store, functionId) => {
|
|
2996
|
+
return durationSamplingEnabled ? { ...store, currentFunctionId: functionId } : store;
|
|
2997
|
+
};
|
|
2998
|
+
const decideCallTiming = (recording, plan, callerFunctionId) => {
|
|
2999
|
+
if (!durationSamplingApplies(recording) || !durationSamples) return true;
|
|
3000
|
+
const typeKey = executionTypeKey(recording.execution);
|
|
3001
|
+
if (!typeKey) return true;
|
|
3002
|
+
return durationSamples.take(typeKey, callerFunctionId ?? "", plan.functionId);
|
|
3003
|
+
};
|
|
2850
3004
|
const capturedCallLimitFor = (recording) => recording.sessionMaxCapturedCalls ?? maxCapturedCallsPerFunction;
|
|
2851
3005
|
const tryAdmitLiveSession = (recording) => {
|
|
2852
3006
|
if (recording.retainSuccess || recording.finished) return;
|
|
@@ -2872,7 +3026,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2872
3026
|
if (!key) return;
|
|
2873
3027
|
recording.identityResolved = true;
|
|
2874
3028
|
tryAdmitFromStartSnapshot(recording);
|
|
2875
|
-
if (recording.captureValues ||
|
|
3029
|
+
if (recording.captureValues || !adaptiveEnabled) return;
|
|
2876
3030
|
if (keyIsActive(recording.policySnapshot, key, recording.startedAtMs)) {
|
|
2877
3031
|
recording.captureValues = true;
|
|
2878
3032
|
stats.adaptiveLightExecutions = Math.max(0, stats.adaptiveLightExecutions - 1);
|
|
@@ -2880,7 +3034,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2880
3034
|
}
|
|
2881
3035
|
};
|
|
2882
3036
|
const maybeActivateAdaptive = (recording) => {
|
|
2883
|
-
if (
|
|
3037
|
+
if (!adaptiveEnabled || recording.adaptiveActivated) return;
|
|
2884
3038
|
if (isHttpClientErrorStatus(recording.execution.request?.status)) return;
|
|
2885
3039
|
const key = executionTypeKey(recording.execution);
|
|
2886
3040
|
if (!key) return;
|
|
@@ -2981,11 +3135,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2981
3135
|
};
|
|
2982
3136
|
}
|
|
2983
3137
|
const droppedEvents = Boolean(truncated?.eventsDropped || capture?.eventsDropped);
|
|
3138
|
+
const evidence = retainedTimingsCoverage(events);
|
|
2984
3139
|
return {
|
|
2985
3140
|
source,
|
|
2986
3141
|
functionBoundaries: droppedEvents ? "partial" : "full",
|
|
2987
3142
|
functionValues: recording.captureValues ? eventsHaveOmittedValues(events) ? "selective" : "full" : "none",
|
|
2988
|
-
timings: droppedEvents ? "partial" :
|
|
3143
|
+
timings: droppedEvents && evidence === "full" ? "partial" : evidence
|
|
2989
3144
|
};
|
|
2990
3145
|
};
|
|
2991
3146
|
const stateFrom = (recording, endedAtNs = process.hrtime.bigint()) => {
|
|
@@ -3039,9 +3194,11 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3039
3194
|
recording.journal = void 0;
|
|
3040
3195
|
}
|
|
3041
3196
|
}
|
|
3197
|
+
const captureProfile = resolveCaptureProfile(recording, events, truncated, capture);
|
|
3198
|
+
const fullyTimed = eventsAreFullyTimed(events);
|
|
3042
3199
|
const state = {
|
|
3043
3200
|
version: 4,
|
|
3044
|
-
captureProfile
|
|
3201
|
+
captureProfile,
|
|
3045
3202
|
executionId: recording.executionId,
|
|
3046
3203
|
startedAt: new Date(recording.startedAtMs).toISOString(),
|
|
3047
3204
|
durationMs: elapsedMs2(recording.startedAtNs, endedAtNs),
|
|
@@ -3051,7 +3208,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3051
3208
|
...recording.execution.request ? { request: { ...recording.execution.request } } : {}
|
|
3052
3209
|
},
|
|
3053
3210
|
functions: functions.slice(),
|
|
3054
|
-
events: events.slice(),
|
|
3211
|
+
events: fullyTimed ? asFullyTimedEvents(events) : events.slice(),
|
|
3212
|
+
...fullyTimed || !durationSamplingEnabled ? {} : { durationSampling: { policy: "progressive" } },
|
|
3055
3213
|
...truncated ? { truncated: { ...truncated } } : {},
|
|
3056
3214
|
...capture ? { capture: { ...capture } } : {}
|
|
3057
3215
|
};
|
|
@@ -3321,7 +3479,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3321
3479
|
}
|
|
3322
3480
|
};
|
|
3323
3481
|
};
|
|
3324
|
-
const captureCompletedThrow = (recording, plan, args, parentCallId, startedAtNs, error, capturedArgs) => {
|
|
3482
|
+
const captureCompletedThrow = (recording, plan, args, parentCallId, startedAtNs, error, timed, capturedArgs) => {
|
|
3325
3483
|
if (!recording.journal) {
|
|
3326
3484
|
return;
|
|
3327
3485
|
}
|
|
@@ -3331,17 +3489,17 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3331
3489
|
const callId = ++recording.nextCallId;
|
|
3332
3490
|
const capturedError = serializedError(recording, error, callId);
|
|
3333
3491
|
const recordedArgs = capturedArgs ?? (recording.captureValues ? mapArrayLike(args, (argument) => captureValue(recording, argument)) : ARGS_OMITTED);
|
|
3334
|
-
const endedAtNs =
|
|
3492
|
+
const endedAtNs = readCallClock();
|
|
3335
3493
|
const droppedBefore = recording.journal.dropped;
|
|
3336
3494
|
const retained = recording.journal.forceCompletedCall(
|
|
3337
3495
|
plan.runtimePlanId,
|
|
3338
3496
|
callId,
|
|
3339
3497
|
parentCallId,
|
|
3340
|
-
startedAtNs - recording.startedAtNs,
|
|
3498
|
+
timed ? startedAtNs - recording.startedAtNs : TIMING_UNAVAILABLE,
|
|
3341
3499
|
recordedArgs,
|
|
3342
3500
|
KIND_THROW,
|
|
3343
3501
|
endedAtNs - recording.startedAtNs,
|
|
3344
|
-
endedAtNs - startedAtNs,
|
|
3502
|
+
timed ? endedAtNs - startedAtNs : TIMING_UNAVAILABLE,
|
|
3345
3503
|
capturedError.value
|
|
3346
3504
|
);
|
|
3347
3505
|
if (retained) {
|
|
@@ -3352,17 +3510,23 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3352
3510
|
}
|
|
3353
3511
|
countDroppedEvents(recording, droppedBefore);
|
|
3354
3512
|
};
|
|
3355
|
-
const recordSuppressedCall = (recording, group, parentCallId, startedAtNs, endedAtNs) => {
|
|
3513
|
+
const recordSuppressedCall = (recording, group, parentCallId, startedAtNs, endedAtNs, timed) => {
|
|
3356
3514
|
stats.repeatedCallsSuppressed++;
|
|
3357
3515
|
if (!group.suppressed) {
|
|
3358
|
-
group.suppressed = newSuppression(group, parentCallId, startedAtNs, endedAtNs);
|
|
3516
|
+
group.suppressed = newSuppression(group, parentCallId, startedAtNs, endedAtNs, timed);
|
|
3359
3517
|
appendSuppressedPlaceholder(recording, group.suppressed);
|
|
3360
3518
|
return;
|
|
3361
3519
|
}
|
|
3362
3520
|
const suppressed = group.suppressed;
|
|
3363
3521
|
suppressed.count++;
|
|
3364
|
-
|
|
3365
|
-
|
|
3522
|
+
if (timed) {
|
|
3523
|
+
suppressed.lastTimestampNs = endedAtNs;
|
|
3524
|
+
suppressed.lastTimed = true;
|
|
3525
|
+
suppressed.sampledDurationCount++;
|
|
3526
|
+
suppressed.sampledDurationNs += endedAtNs - startedAtNs;
|
|
3527
|
+
} else {
|
|
3528
|
+
suppressed.lastTimed = false;
|
|
3529
|
+
}
|
|
3366
3530
|
if (suppressed.retainedIndex < 0) {
|
|
3367
3531
|
appendSuppressedPlaceholder(recording, suppressed);
|
|
3368
3532
|
}
|
|
@@ -3475,10 +3639,10 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3475
3639
|
};
|
|
3476
3640
|
const identityComplete = executionTypeKey(execution) !== void 0;
|
|
3477
3641
|
const captureValues = captureValuesFor(execution, livePolicy, startedAtMs);
|
|
3478
|
-
const policySnapshot =
|
|
3642
|
+
const policySnapshot = adaptiveEnabled && !identityComplete ? new Map(livePolicy) : EMPTY_POLICY_SNAPSHOT;
|
|
3479
3643
|
const liveSessions = hooks.sessionCaptureSnapshot?.() ?? EMPTY_SESSION_SNAPSHOT;
|
|
3480
3644
|
const sessionCaptureSnapshot = identityComplete ? EMPTY_SESSION_SNAPSHOT : new Map(liveSessions);
|
|
3481
|
-
if (
|
|
3645
|
+
if (adaptiveEnabled) {
|
|
3482
3646
|
if (captureValues) stats.adaptiveFullExecutions++;
|
|
3483
3647
|
else stats.adaptiveLightExecutions++;
|
|
3484
3648
|
}
|
|
@@ -3625,25 +3789,36 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3625
3789
|
if (group.observedCalls === 1) journal?.notePlan(plan.runtimePlanId);
|
|
3626
3790
|
} catch {
|
|
3627
3791
|
}
|
|
3792
|
+
const timed = durationSamplingEnabled ? decideCallTiming(recording, plan, store.currentFunctionId) : true;
|
|
3628
3793
|
if (group.observedCalls > capturedCallLimitFor(recording)) {
|
|
3629
|
-
const startedAtNs2 =
|
|
3794
|
+
const startedAtNs2 = timed ? readCallClock() : 0n;
|
|
3630
3795
|
try {
|
|
3631
|
-
const result = runStore(
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3796
|
+
const result = runStore(
|
|
3797
|
+
samplingStore(store, plan.functionId),
|
|
3798
|
+
function __rasputinHandleRun__5() {
|
|
3799
|
+
return callback();
|
|
3800
|
+
}
|
|
3801
|
+
);
|
|
3802
|
+
recordSuppressedCall(
|
|
3803
|
+
recording,
|
|
3804
|
+
group,
|
|
3805
|
+
parentCallId,
|
|
3806
|
+
startedAtNs2,
|
|
3807
|
+
timed ? readCallClock() : 0n,
|
|
3808
|
+
timed
|
|
3809
|
+
);
|
|
3635
3810
|
settleInFlight(recording);
|
|
3636
3811
|
return result;
|
|
3637
3812
|
} catch (error) {
|
|
3638
|
-
captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs2, error);
|
|
3813
|
+
captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs2, error, timed);
|
|
3639
3814
|
settleInFlight(recording);
|
|
3640
3815
|
throw error;
|
|
3641
3816
|
}
|
|
3642
3817
|
}
|
|
3643
|
-
const startedAtNs =
|
|
3818
|
+
const startedAtNs = timed ? readCallClock() : 0n;
|
|
3644
3819
|
if (!journal) {
|
|
3645
3820
|
memoryBudget.reserveCall(recording.memory, plan.estimatedCallBytes);
|
|
3646
|
-
return runStore(store, function __rasputinHandleRun__5() {
|
|
3821
|
+
return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
|
|
3647
3822
|
return observeRecordedCallback(
|
|
3648
3823
|
recording,
|
|
3649
3824
|
recorderStartedAtNs,
|
|
@@ -3662,38 +3837,40 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3662
3837
|
countDroppedEvents(recording, droppedBefore);
|
|
3663
3838
|
settleInFlight(recording);
|
|
3664
3839
|
};
|
|
3665
|
-
return runStore(store, function __rasputinHandleRun__5() {
|
|
3840
|
+
return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
|
|
3666
3841
|
return observeRecordedCallback(
|
|
3667
3842
|
recording,
|
|
3668
3843
|
recorderStartedAtNs,
|
|
3669
3844
|
callback,
|
|
3670
3845
|
captureSuccess,
|
|
3671
3846
|
(error) => {
|
|
3672
|
-
captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs, error);
|
|
3847
|
+
captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs, error, timed);
|
|
3673
3848
|
settleInFlight(recording);
|
|
3674
3849
|
}
|
|
3675
3850
|
);
|
|
3676
3851
|
});
|
|
3677
3852
|
}
|
|
3678
3853
|
if (!memoryBudget.reserveCall(recording.memory, plan.estimatedCallBytes)) {
|
|
3679
|
-
return
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3854
|
+
return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
|
|
3855
|
+
return observeRecordedCallback(
|
|
3856
|
+
recording,
|
|
3857
|
+
recorderStartedAtNs,
|
|
3858
|
+
callback,
|
|
3859
|
+
() => settleInFlight(recording),
|
|
3860
|
+
(_error) => {
|
|
3861
|
+
settleInFlight(recording);
|
|
3862
|
+
}
|
|
3863
|
+
);
|
|
3864
|
+
});
|
|
3688
3865
|
}
|
|
3689
3866
|
const callId = ++recording.nextCallId;
|
|
3690
|
-
const enterTimestampNs =
|
|
3867
|
+
const enterTimestampNs = timed ? readCallClock() - recording.startedAtNs : TIMING_UNAVAILABLE;
|
|
3691
3868
|
const capturedArgs = enterPayload(recording, omitCallValues, args);
|
|
3692
3869
|
try {
|
|
3693
3870
|
journal.startCall(plan.runtimePlanId, callId, parentCallId, enterTimestampNs, capturedArgs);
|
|
3694
3871
|
} catch {
|
|
3695
3872
|
journal.dropCall();
|
|
3696
|
-
return runStore(store, function __rasputinHandleRun__5() {
|
|
3873
|
+
return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
|
|
3697
3874
|
return observeRecordedCallback(
|
|
3698
3875
|
recording,
|
|
3699
3876
|
recorderStartedAtNs,
|
|
@@ -3705,7 +3882,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3705
3882
|
);
|
|
3706
3883
|
});
|
|
3707
3884
|
}
|
|
3708
|
-
const callStore =
|
|
3885
|
+
const callStore = callStoreFor(store, plan.functionId, callId);
|
|
3709
3886
|
return runStore(callStore, function __rasputinHandleRun__5() {
|
|
3710
3887
|
return observeRecordedCallback(
|
|
3711
3888
|
recording,
|
|
@@ -3713,15 +3890,25 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3713
3890
|
callback,
|
|
3714
3891
|
(value) => {
|
|
3715
3892
|
if (recording.journal) {
|
|
3716
|
-
const endedAtNs =
|
|
3893
|
+
const endedAtNs = timed ? readCallClock() : void 0;
|
|
3717
3894
|
const returnValue = exitPayload(recording, omitCallValues, value);
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3895
|
+
if (endedAtNs !== void 0) {
|
|
3896
|
+
recording.journal.finishCall(
|
|
3897
|
+
KIND_EXIT,
|
|
3898
|
+
callId,
|
|
3899
|
+
endedAtNs - recording.startedAtNs,
|
|
3900
|
+
endedAtNs - startedAtNs,
|
|
3901
|
+
returnValue
|
|
3902
|
+
);
|
|
3903
|
+
} else {
|
|
3904
|
+
recording.journal.finishCall(
|
|
3905
|
+
KIND_EXIT,
|
|
3906
|
+
callId,
|
|
3907
|
+
TIMING_UNAVAILABLE,
|
|
3908
|
+
TIMING_UNAVAILABLE,
|
|
3909
|
+
returnValue
|
|
3910
|
+
);
|
|
3911
|
+
}
|
|
3725
3912
|
stats.functionCallsCaptured++;
|
|
3726
3913
|
}
|
|
3727
3914
|
settleInFlight(recording);
|
|
@@ -3732,12 +3919,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3732
3919
|
return;
|
|
3733
3920
|
}
|
|
3734
3921
|
const capturedError = serializedError(recording, error, callId);
|
|
3735
|
-
const endedAtNs =
|
|
3922
|
+
const endedAtNs = readCallClock();
|
|
3736
3923
|
recording.journal.finishCall(
|
|
3737
3924
|
KIND_THROW,
|
|
3738
3925
|
callId,
|
|
3739
3926
|
endedAtNs - recording.startedAtNs,
|
|
3740
|
-
endedAtNs - startedAtNs,
|
|
3927
|
+
timed ? endedAtNs - startedAtNs : TIMING_UNAVAILABLE,
|
|
3741
3928
|
capturedError.value
|
|
3742
3929
|
);
|
|
3743
3930
|
stats.functionCallsCaptured++;
|
|
@@ -3749,23 +3936,43 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3749
3936
|
};
|
|
3750
3937
|
const noopHandle2 = passthroughHandle();
|
|
3751
3938
|
class CallFrame {
|
|
3752
|
-
constructor(mode, recording, parentStore, activeStore, plan, args, omitCallValues, parentCallId, startedAtNs, callId, group, captureDroppedThrow) {
|
|
3939
|
+
constructor(mode, recording, parentStore, activeStore, plan, args, omitCallValues, parentCallId, startedAtNs, timed, callId, group, captureDroppedThrow) {
|
|
3753
3940
|
this.mode = mode;
|
|
3754
3941
|
this.status = "open";
|
|
3755
3942
|
this.pendingReturn = void 0;
|
|
3756
3943
|
this.ended = false;
|
|
3757
3944
|
this.suspended = false;
|
|
3758
3945
|
this.startedAtNs = startedAtNs;
|
|
3946
|
+
this.timed = timed;
|
|
3759
3947
|
this.callId = callId;
|
|
3760
3948
|
this.recording = recording;
|
|
3761
3949
|
this.plan = plan;
|
|
3762
3950
|
this.args = args;
|
|
3763
3951
|
this.omitCallValues = omitCallValues;
|
|
3764
3952
|
this.parentCallId = parentCallId;
|
|
3765
|
-
this.parentStore = parentStore;
|
|
3766
3953
|
this.activeStore = activeStore;
|
|
3954
|
+
this.parentStore = parentStore;
|
|
3767
3955
|
this.group = group;
|
|
3768
3956
|
this.captureDroppedThrow = captureDroppedThrow;
|
|
3957
|
+
this.callerClaimed = false;
|
|
3958
|
+
}
|
|
3959
|
+
claimCaller() {
|
|
3960
|
+
if (this.callerClaimed || !durationSamplingEnabled || !this.plan) return;
|
|
3961
|
+
if (this.activeStore !== this.parentStore) return;
|
|
3962
|
+
this.previousFunctionId = this.parentStore.currentFunctionId;
|
|
3963
|
+
this.parentStore.currentFunctionId = this.plan.functionId;
|
|
3964
|
+
this.callerClaimed = true;
|
|
3965
|
+
}
|
|
3966
|
+
reclaimCaller() {
|
|
3967
|
+
if (!durationSamplingEnabled || !this.plan || this.activeStore !== this.parentStore) return;
|
|
3968
|
+
this.parentStore.currentFunctionId = this.plan.functionId;
|
|
3969
|
+
this.callerClaimed = true;
|
|
3970
|
+
}
|
|
3971
|
+
releaseCaller() {
|
|
3972
|
+
if (!this.callerClaimed) return;
|
|
3973
|
+
this.callerClaimed = false;
|
|
3974
|
+
if (this.previousFunctionId === void 0) delete this.parentStore.currentFunctionId;
|
|
3975
|
+
else this.parentStore.currentFunctionId = this.previousFunctionId;
|
|
3769
3976
|
}
|
|
3770
3977
|
leave(value) {
|
|
3771
3978
|
try {
|
|
@@ -3791,6 +3998,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3791
3998
|
this.parentCallId,
|
|
3792
3999
|
this.startedAtNs,
|
|
3793
4000
|
error,
|
|
4001
|
+
this.timed,
|
|
3794
4002
|
this.recording.captureValues ? void 0 : ARGS_OMITTED
|
|
3795
4003
|
);
|
|
3796
4004
|
} else if (this.mode === "dropped" && this.captureDroppedThrow && this.plan) {
|
|
@@ -3801,6 +4009,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3801
4009
|
this.parentCallId,
|
|
3802
4010
|
this.startedAtNs,
|
|
3803
4011
|
error,
|
|
4012
|
+
this.timed,
|
|
3804
4013
|
this.recording.captureValues ? void 0 : ARGS_OMITTED
|
|
3805
4014
|
);
|
|
3806
4015
|
}
|
|
@@ -3819,7 +4028,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3819
4028
|
this.group,
|
|
3820
4029
|
this.parentCallId,
|
|
3821
4030
|
this.startedAtNs,
|
|
3822
|
-
|
|
4031
|
+
this.timed ? readCallClock() : 0n,
|
|
4032
|
+
this.timed
|
|
3823
4033
|
);
|
|
3824
4034
|
} else if (this.mode === "dropped") {
|
|
3825
4035
|
const droppedBefore = this.recording.journal?.dropped ?? 0;
|
|
@@ -3832,6 +4042,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3832
4042
|
try {
|
|
3833
4043
|
if (this.ended) return;
|
|
3834
4044
|
this.ended = true;
|
|
4045
|
+
this.releaseCaller();
|
|
3835
4046
|
if (this.mode !== "excluded") settleInFlight(this.recording);
|
|
3836
4047
|
expectStore(this, this.activeStore);
|
|
3837
4048
|
enterStore(this, this.parentStore);
|
|
@@ -3855,6 +4066,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3855
4066
|
try {
|
|
3856
4067
|
expectStore(this, this.activeStore);
|
|
3857
4068
|
this.suspended = true;
|
|
4069
|
+
this.releaseCaller();
|
|
3858
4070
|
enterStore(this, this.parentStore);
|
|
3859
4071
|
return value;
|
|
3860
4072
|
} catch {
|
|
@@ -3868,6 +4080,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3868
4080
|
expectStore(this, this.parentStore);
|
|
3869
4081
|
this.suspended = false;
|
|
3870
4082
|
enterStore(this, this.activeStore);
|
|
4083
|
+
this.reclaimCaller();
|
|
3871
4084
|
} else {
|
|
3872
4085
|
expectStore(this, this.activeStore);
|
|
3873
4086
|
}
|
|
@@ -3890,32 +4103,42 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3890
4103
|
};
|
|
3891
4104
|
const writeCapturedExit = (frame, value) => {
|
|
3892
4105
|
if (!frame.recording.journal) return;
|
|
3893
|
-
const endedAtNs =
|
|
4106
|
+
const endedAtNs = frame.timed ? readCallClock() : void 0;
|
|
3894
4107
|
const returnValue = exitPayload(frame.recording, frame.omitCallValues, value);
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
4108
|
+
if (endedAtNs !== void 0) {
|
|
4109
|
+
frame.recording.journal.finishCall(
|
|
4110
|
+
KIND_EXIT,
|
|
4111
|
+
frame.callId,
|
|
4112
|
+
endedAtNs - frame.recording.startedAtNs,
|
|
4113
|
+
endedAtNs - frame.startedAtNs,
|
|
4114
|
+
returnValue
|
|
4115
|
+
);
|
|
4116
|
+
} else {
|
|
4117
|
+
frame.recording.journal.finishCall(
|
|
4118
|
+
KIND_EXIT,
|
|
4119
|
+
frame.callId,
|
|
4120
|
+
TIMING_UNAVAILABLE,
|
|
4121
|
+
TIMING_UNAVAILABLE,
|
|
4122
|
+
returnValue
|
|
4123
|
+
);
|
|
4124
|
+
}
|
|
3902
4125
|
stats.functionCallsCaptured++;
|
|
3903
4126
|
};
|
|
3904
4127
|
const writeCapturedThrow = (frame, error) => {
|
|
3905
4128
|
if (!frame.recording.journal) return;
|
|
3906
|
-
const endedAtNs =
|
|
4129
|
+
const endedAtNs = readCallClock();
|
|
3907
4130
|
const capturedError = serializedError(frame.recording, error, frame.callId);
|
|
3908
4131
|
frame.recording.journal.finishCall(
|
|
3909
4132
|
KIND_THROW,
|
|
3910
4133
|
frame.callId,
|
|
3911
4134
|
endedAtNs - frame.recording.startedAtNs,
|
|
3912
|
-
endedAtNs - frame.startedAtNs,
|
|
4135
|
+
frame.timed ? endedAtNs - frame.startedAtNs : TIMING_UNAVAILABLE,
|
|
3913
4136
|
capturedError.value
|
|
3914
4137
|
);
|
|
3915
4138
|
stats.functionCallsCaptured++;
|
|
3916
4139
|
capturedError.commit();
|
|
3917
4140
|
};
|
|
3918
|
-
const activateUncaptured = (mode, recording, parentStore, plan, args, omitCallValues, parentCallId, startedAtNs, group, captureDroppedThrow) => {
|
|
4141
|
+
const activateUncaptured = (mode, recording, parentStore, plan, args, omitCallValues, parentCallId, startedAtNs, timed, group, captureDroppedThrow) => {
|
|
3919
4142
|
const frame = new CallFrame(
|
|
3920
4143
|
mode,
|
|
3921
4144
|
recording,
|
|
@@ -3926,10 +4149,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3926
4149
|
omitCallValues,
|
|
3927
4150
|
parentCallId,
|
|
3928
4151
|
startedAtNs,
|
|
4152
|
+
timed,
|
|
3929
4153
|
0,
|
|
3930
4154
|
group,
|
|
3931
4155
|
captureDroppedThrow
|
|
3932
4156
|
);
|
|
4157
|
+
frame.claimCaller();
|
|
3933
4158
|
enterStore(frame, parentStore);
|
|
3934
4159
|
return frame;
|
|
3935
4160
|
};
|
|
@@ -3952,6 +4177,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3952
4177
|
false,
|
|
3953
4178
|
void 0,
|
|
3954
4179
|
0n,
|
|
4180
|
+
true,
|
|
3955
4181
|
0,
|
|
3956
4182
|
void 0,
|
|
3957
4183
|
false
|
|
@@ -3974,6 +4200,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3974
4200
|
false,
|
|
3975
4201
|
void 0,
|
|
3976
4202
|
0n,
|
|
4203
|
+
true,
|
|
3977
4204
|
0,
|
|
3978
4205
|
void 0,
|
|
3979
4206
|
false
|
|
@@ -3989,7 +4216,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3989
4216
|
if (group.observedCalls === 1) journal?.notePlan(plan.runtimePlanId);
|
|
3990
4217
|
} catch {
|
|
3991
4218
|
}
|
|
3992
|
-
const
|
|
4219
|
+
const timed = durationSamplingEnabled ? decideCallTiming(recording, plan, store.currentFunctionId) : true;
|
|
4220
|
+
const startedAtNs = timed ? readCallClock() : 0n;
|
|
3993
4221
|
const parentStore = store;
|
|
3994
4222
|
const retainedArgs = recording.captureValues ? args : EMPTY_ARGS;
|
|
3995
4223
|
if (group.observedCalls > capturedCallLimitFor(recording)) {
|
|
@@ -4002,6 +4230,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4002
4230
|
omitCallValues,
|
|
4003
4231
|
parentCallId,
|
|
4004
4232
|
startedAtNs,
|
|
4233
|
+
timed,
|
|
4005
4234
|
group,
|
|
4006
4235
|
false
|
|
4007
4236
|
);
|
|
@@ -4017,6 +4246,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4017
4246
|
omitCallValues,
|
|
4018
4247
|
parentCallId,
|
|
4019
4248
|
startedAtNs,
|
|
4249
|
+
timed,
|
|
4020
4250
|
group,
|
|
4021
4251
|
false
|
|
4022
4252
|
);
|
|
@@ -4031,6 +4261,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4031
4261
|
omitCallValues,
|
|
4032
4262
|
parentCallId,
|
|
4033
4263
|
startedAtNs,
|
|
4264
|
+
timed,
|
|
4034
4265
|
group,
|
|
4035
4266
|
true
|
|
4036
4267
|
);
|
|
@@ -4045,12 +4276,13 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4045
4276
|
omitCallValues,
|
|
4046
4277
|
parentCallId,
|
|
4047
4278
|
startedAtNs,
|
|
4279
|
+
timed,
|
|
4048
4280
|
group,
|
|
4049
4281
|
false
|
|
4050
4282
|
);
|
|
4051
4283
|
}
|
|
4052
4284
|
const callId = ++recording.nextCallId;
|
|
4053
|
-
const enterTimestampNs =
|
|
4285
|
+
const enterTimestampNs = timed ? readCallClock() - recording.startedAtNs : TIMING_UNAVAILABLE;
|
|
4054
4286
|
const capturedArgs = enterPayload(recording, omitCallValues, args);
|
|
4055
4287
|
try {
|
|
4056
4288
|
journal.startCall(plan.runtimePlanId, callId, parentCallId, enterTimestampNs, capturedArgs);
|
|
@@ -4065,11 +4297,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4065
4297
|
omitCallValues,
|
|
4066
4298
|
parentCallId,
|
|
4067
4299
|
startedAtNs,
|
|
4300
|
+
timed,
|
|
4068
4301
|
group,
|
|
4069
4302
|
false
|
|
4070
4303
|
);
|
|
4071
4304
|
}
|
|
4072
|
-
const callStore =
|
|
4305
|
+
const callStore = callStoreFor(store, plan.functionId, callId);
|
|
4073
4306
|
const captured = new CallFrame(
|
|
4074
4307
|
"captured",
|
|
4075
4308
|
recording,
|
|
@@ -4080,6 +4313,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4080
4313
|
omitCallValues,
|
|
4081
4314
|
parentCallId,
|
|
4082
4315
|
startedAtNs,
|
|
4316
|
+
timed,
|
|
4083
4317
|
callId,
|
|
4084
4318
|
group,
|
|
4085
4319
|
false
|
|
@@ -4148,6 +4382,9 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4148
4382
|
runPreparedFunction,
|
|
4149
4383
|
enterPreparedFunction,
|
|
4150
4384
|
trace,
|
|
4385
|
+
close: () => {
|
|
4386
|
+
durationSamples?.stop();
|
|
4387
|
+
},
|
|
4151
4388
|
getStats: () => ({
|
|
4152
4389
|
...stats,
|
|
4153
4390
|
...memoryBudget.getStats(),
|
|
@@ -5049,7 +5286,7 @@ var createExecutionRecordingCoordinator = (options) => {
|
|
|
5049
5286
|
// src/execution-recorder/bind-adaptive-recorder.ts
|
|
5050
5287
|
var bindAdaptiveRecorder = (input) => {
|
|
5051
5288
|
const options = input.executionRecorder;
|
|
5052
|
-
const
|
|
5289
|
+
const adaptiveEnabled = options?.adaptive?.enabled === true;
|
|
5053
5290
|
const activation = resolveClientActivation({
|
|
5054
5291
|
enabled: input.enabled,
|
|
5055
5292
|
dsn: input.dsn,
|
|
@@ -5068,14 +5305,14 @@ var bindAdaptiveRecorder = (input) => {
|
|
|
5068
5305
|
release: activation.release,
|
|
5069
5306
|
recorderOptions: options,
|
|
5070
5307
|
scrubPII: input.scrubPII,
|
|
5071
|
-
mode,
|
|
5308
|
+
mode: adaptiveEnabled ? "adaptive" : "full",
|
|
5072
5309
|
fetch: input.fetch
|
|
5073
5310
|
}) : void 0;
|
|
5074
5311
|
const runtime = createExecutionRecorder(
|
|
5075
5312
|
{ ...options, enabled: input.recorderEnabled },
|
|
5076
5313
|
coordinator ? {
|
|
5077
5314
|
policySnapshot: coordinator.peek,
|
|
5078
|
-
onQualifyingFailure:
|
|
5315
|
+
onQualifyingFailure: adaptiveEnabled ? coordinator.activate : void 0,
|
|
5079
5316
|
getStats: coordinator.getStats,
|
|
5080
5317
|
sessionCaptureSnapshot: coordinator.peekSessions,
|
|
5081
5318
|
consumeSession: coordinator.consumeSession,
|