@rasputin-ai/node 0.11.3 → 0.12.0
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 +20 -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 +327 -114
- package/dist/instrument/bun.js +1 -1
- package/dist/instrument/node.js +1 -1
- package/dist/internal.js +325 -113
- 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,18 @@ 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 callerStore = (store, functionId, callId) => ({
|
|
2991
|
+
...store,
|
|
2992
|
+
currentFunctionId: functionId,
|
|
2993
|
+
...callId === void 0 ? {} : { currentCallId: callId }
|
|
2994
|
+
});
|
|
2995
|
+
const decideCallTiming = (recording, plan, callerFunctionId) => {
|
|
2996
|
+
if (!durationSamplingApplies(recording) || !durationSamples) return true;
|
|
2997
|
+
const typeKey = executionTypeKey(recording.execution);
|
|
2998
|
+
if (!typeKey) return true;
|
|
2999
|
+
return durationSamples.take(typeKey, callerFunctionId ?? "", plan.functionId);
|
|
3000
|
+
};
|
|
2850
3001
|
const capturedCallLimitFor = (recording) => recording.sessionMaxCapturedCalls ?? maxCapturedCallsPerFunction;
|
|
2851
3002
|
const tryAdmitLiveSession = (recording) => {
|
|
2852
3003
|
if (recording.retainSuccess || recording.finished) return;
|
|
@@ -2872,7 +3023,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2872
3023
|
if (!key) return;
|
|
2873
3024
|
recording.identityResolved = true;
|
|
2874
3025
|
tryAdmitFromStartSnapshot(recording);
|
|
2875
|
-
if (recording.captureValues ||
|
|
3026
|
+
if (recording.captureValues || !adaptiveEnabled) return;
|
|
2876
3027
|
if (keyIsActive(recording.policySnapshot, key, recording.startedAtMs)) {
|
|
2877
3028
|
recording.captureValues = true;
|
|
2878
3029
|
stats.adaptiveLightExecutions = Math.max(0, stats.adaptiveLightExecutions - 1);
|
|
@@ -2880,7 +3031,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2880
3031
|
}
|
|
2881
3032
|
};
|
|
2882
3033
|
const maybeActivateAdaptive = (recording) => {
|
|
2883
|
-
if (
|
|
3034
|
+
if (!adaptiveEnabled || recording.adaptiveActivated) return;
|
|
2884
3035
|
if (isHttpClientErrorStatus(recording.execution.request?.status)) return;
|
|
2885
3036
|
const key = executionTypeKey(recording.execution);
|
|
2886
3037
|
if (!key) return;
|
|
@@ -2981,11 +3132,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
2981
3132
|
};
|
|
2982
3133
|
}
|
|
2983
3134
|
const droppedEvents = Boolean(truncated?.eventsDropped || capture?.eventsDropped);
|
|
3135
|
+
const evidence = retainedTimingsCoverage(events);
|
|
2984
3136
|
return {
|
|
2985
3137
|
source,
|
|
2986
3138
|
functionBoundaries: droppedEvents ? "partial" : "full",
|
|
2987
3139
|
functionValues: recording.captureValues ? eventsHaveOmittedValues(events) ? "selective" : "full" : "none",
|
|
2988
|
-
timings: droppedEvents ? "partial" :
|
|
3140
|
+
timings: droppedEvents && evidence === "full" ? "partial" : evidence
|
|
2989
3141
|
};
|
|
2990
3142
|
};
|
|
2991
3143
|
const stateFrom = (recording, endedAtNs = process.hrtime.bigint()) => {
|
|
@@ -3039,9 +3191,11 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3039
3191
|
recording.journal = void 0;
|
|
3040
3192
|
}
|
|
3041
3193
|
}
|
|
3194
|
+
const captureProfile = resolveCaptureProfile(recording, events, truncated, capture);
|
|
3195
|
+
const fullyTimed = eventsAreFullyTimed(events);
|
|
3042
3196
|
const state = {
|
|
3043
3197
|
version: 4,
|
|
3044
|
-
captureProfile
|
|
3198
|
+
captureProfile,
|
|
3045
3199
|
executionId: recording.executionId,
|
|
3046
3200
|
startedAt: new Date(recording.startedAtMs).toISOString(),
|
|
3047
3201
|
durationMs: elapsedMs2(recording.startedAtNs, endedAtNs),
|
|
@@ -3051,7 +3205,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3051
3205
|
...recording.execution.request ? { request: { ...recording.execution.request } } : {}
|
|
3052
3206
|
},
|
|
3053
3207
|
functions: functions.slice(),
|
|
3054
|
-
events: events.slice(),
|
|
3208
|
+
events: fullyTimed ? asFullyTimedEvents(events) : events.slice(),
|
|
3209
|
+
...fullyTimed || !durationSamplingEnabled ? {} : { durationSampling: { policy: "progressive" } },
|
|
3055
3210
|
...truncated ? { truncated: { ...truncated } } : {},
|
|
3056
3211
|
...capture ? { capture: { ...capture } } : {}
|
|
3057
3212
|
};
|
|
@@ -3321,7 +3476,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3321
3476
|
}
|
|
3322
3477
|
};
|
|
3323
3478
|
};
|
|
3324
|
-
const captureCompletedThrow = (recording, plan, args, parentCallId, startedAtNs, error, capturedArgs) => {
|
|
3479
|
+
const captureCompletedThrow = (recording, plan, args, parentCallId, startedAtNs, error, timed, capturedArgs) => {
|
|
3325
3480
|
if (!recording.journal) {
|
|
3326
3481
|
return;
|
|
3327
3482
|
}
|
|
@@ -3331,17 +3486,17 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3331
3486
|
const callId = ++recording.nextCallId;
|
|
3332
3487
|
const capturedError = serializedError(recording, error, callId);
|
|
3333
3488
|
const recordedArgs = capturedArgs ?? (recording.captureValues ? mapArrayLike(args, (argument) => captureValue(recording, argument)) : ARGS_OMITTED);
|
|
3334
|
-
const endedAtNs =
|
|
3489
|
+
const endedAtNs = readCallClock();
|
|
3335
3490
|
const droppedBefore = recording.journal.dropped;
|
|
3336
3491
|
const retained = recording.journal.forceCompletedCall(
|
|
3337
3492
|
plan.runtimePlanId,
|
|
3338
3493
|
callId,
|
|
3339
3494
|
parentCallId,
|
|
3340
|
-
startedAtNs - recording.startedAtNs,
|
|
3495
|
+
timed ? startedAtNs - recording.startedAtNs : TIMING_UNAVAILABLE,
|
|
3341
3496
|
recordedArgs,
|
|
3342
3497
|
KIND_THROW,
|
|
3343
3498
|
endedAtNs - recording.startedAtNs,
|
|
3344
|
-
endedAtNs - startedAtNs,
|
|
3499
|
+
timed ? endedAtNs - startedAtNs : TIMING_UNAVAILABLE,
|
|
3345
3500
|
capturedError.value
|
|
3346
3501
|
);
|
|
3347
3502
|
if (retained) {
|
|
@@ -3352,17 +3507,23 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3352
3507
|
}
|
|
3353
3508
|
countDroppedEvents(recording, droppedBefore);
|
|
3354
3509
|
};
|
|
3355
|
-
const recordSuppressedCall = (recording, group, parentCallId, startedAtNs, endedAtNs) => {
|
|
3510
|
+
const recordSuppressedCall = (recording, group, parentCallId, startedAtNs, endedAtNs, timed) => {
|
|
3356
3511
|
stats.repeatedCallsSuppressed++;
|
|
3357
3512
|
if (!group.suppressed) {
|
|
3358
|
-
group.suppressed = newSuppression(group, parentCallId, startedAtNs, endedAtNs);
|
|
3513
|
+
group.suppressed = newSuppression(group, parentCallId, startedAtNs, endedAtNs, timed);
|
|
3359
3514
|
appendSuppressedPlaceholder(recording, group.suppressed);
|
|
3360
3515
|
return;
|
|
3361
3516
|
}
|
|
3362
3517
|
const suppressed = group.suppressed;
|
|
3363
3518
|
suppressed.count++;
|
|
3364
|
-
|
|
3365
|
-
|
|
3519
|
+
if (timed) {
|
|
3520
|
+
suppressed.lastTimestampNs = endedAtNs;
|
|
3521
|
+
suppressed.lastTimed = true;
|
|
3522
|
+
suppressed.sampledDurationCount++;
|
|
3523
|
+
suppressed.sampledDurationNs += endedAtNs - startedAtNs;
|
|
3524
|
+
} else {
|
|
3525
|
+
suppressed.lastTimed = false;
|
|
3526
|
+
}
|
|
3366
3527
|
if (suppressed.retainedIndex < 0) {
|
|
3367
3528
|
appendSuppressedPlaceholder(recording, suppressed);
|
|
3368
3529
|
}
|
|
@@ -3475,10 +3636,10 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3475
3636
|
};
|
|
3476
3637
|
const identityComplete = executionTypeKey(execution) !== void 0;
|
|
3477
3638
|
const captureValues = captureValuesFor(execution, livePolicy, startedAtMs);
|
|
3478
|
-
const policySnapshot =
|
|
3639
|
+
const policySnapshot = adaptiveEnabled && !identityComplete ? new Map(livePolicy) : EMPTY_POLICY_SNAPSHOT;
|
|
3479
3640
|
const liveSessions = hooks.sessionCaptureSnapshot?.() ?? EMPTY_SESSION_SNAPSHOT;
|
|
3480
3641
|
const sessionCaptureSnapshot = identityComplete ? EMPTY_SESSION_SNAPSHOT : new Map(liveSessions);
|
|
3481
|
-
if (
|
|
3642
|
+
if (adaptiveEnabled) {
|
|
3482
3643
|
if (captureValues) stats.adaptiveFullExecutions++;
|
|
3483
3644
|
else stats.adaptiveLightExecutions++;
|
|
3484
3645
|
}
|
|
@@ -3625,25 +3786,36 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3625
3786
|
if (group.observedCalls === 1) journal?.notePlan(plan.runtimePlanId);
|
|
3626
3787
|
} catch {
|
|
3627
3788
|
}
|
|
3789
|
+
const timed = durationSamplingEnabled ? decideCallTiming(recording, plan, store.currentFunctionId) : true;
|
|
3628
3790
|
if (group.observedCalls > capturedCallLimitFor(recording)) {
|
|
3629
|
-
const startedAtNs2 =
|
|
3791
|
+
const startedAtNs2 = timed ? readCallClock() : 0n;
|
|
3630
3792
|
try {
|
|
3631
|
-
const result = runStore(
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3793
|
+
const result = runStore(
|
|
3794
|
+
callerStore(store, plan.functionId),
|
|
3795
|
+
function __rasputinHandleRun__5() {
|
|
3796
|
+
return callback();
|
|
3797
|
+
}
|
|
3798
|
+
);
|
|
3799
|
+
recordSuppressedCall(
|
|
3800
|
+
recording,
|
|
3801
|
+
group,
|
|
3802
|
+
parentCallId,
|
|
3803
|
+
startedAtNs2,
|
|
3804
|
+
timed ? readCallClock() : 0n,
|
|
3805
|
+
timed
|
|
3806
|
+
);
|
|
3635
3807
|
settleInFlight(recording);
|
|
3636
3808
|
return result;
|
|
3637
3809
|
} catch (error) {
|
|
3638
|
-
captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs2, error);
|
|
3810
|
+
captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs2, error, timed);
|
|
3639
3811
|
settleInFlight(recording);
|
|
3640
3812
|
throw error;
|
|
3641
3813
|
}
|
|
3642
3814
|
}
|
|
3643
|
-
const startedAtNs =
|
|
3815
|
+
const startedAtNs = timed ? readCallClock() : 0n;
|
|
3644
3816
|
if (!journal) {
|
|
3645
3817
|
memoryBudget.reserveCall(recording.memory, plan.estimatedCallBytes);
|
|
3646
|
-
return runStore(store, function __rasputinHandleRun__5() {
|
|
3818
|
+
return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
|
|
3647
3819
|
return observeRecordedCallback(
|
|
3648
3820
|
recording,
|
|
3649
3821
|
recorderStartedAtNs,
|
|
@@ -3662,38 +3834,40 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3662
3834
|
countDroppedEvents(recording, droppedBefore);
|
|
3663
3835
|
settleInFlight(recording);
|
|
3664
3836
|
};
|
|
3665
|
-
return runStore(store, function __rasputinHandleRun__5() {
|
|
3837
|
+
return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
|
|
3666
3838
|
return observeRecordedCallback(
|
|
3667
3839
|
recording,
|
|
3668
3840
|
recorderStartedAtNs,
|
|
3669
3841
|
callback,
|
|
3670
3842
|
captureSuccess,
|
|
3671
3843
|
(error) => {
|
|
3672
|
-
captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs, error);
|
|
3844
|
+
captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs, error, timed);
|
|
3673
3845
|
settleInFlight(recording);
|
|
3674
3846
|
}
|
|
3675
3847
|
);
|
|
3676
3848
|
});
|
|
3677
3849
|
}
|
|
3678
3850
|
if (!memoryBudget.reserveCall(recording.memory, plan.estimatedCallBytes)) {
|
|
3679
|
-
return
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3851
|
+
return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
|
|
3852
|
+
return observeRecordedCallback(
|
|
3853
|
+
recording,
|
|
3854
|
+
recorderStartedAtNs,
|
|
3855
|
+
callback,
|
|
3856
|
+
() => settleInFlight(recording),
|
|
3857
|
+
(_error) => {
|
|
3858
|
+
settleInFlight(recording);
|
|
3859
|
+
}
|
|
3860
|
+
);
|
|
3861
|
+
});
|
|
3688
3862
|
}
|
|
3689
3863
|
const callId = ++recording.nextCallId;
|
|
3690
|
-
const enterTimestampNs =
|
|
3864
|
+
const enterTimestampNs = timed ? readCallClock() - recording.startedAtNs : TIMING_UNAVAILABLE;
|
|
3691
3865
|
const capturedArgs = enterPayload(recording, omitCallValues, args);
|
|
3692
3866
|
try {
|
|
3693
3867
|
journal.startCall(plan.runtimePlanId, callId, parentCallId, enterTimestampNs, capturedArgs);
|
|
3694
3868
|
} catch {
|
|
3695
3869
|
journal.dropCall();
|
|
3696
|
-
return runStore(store, function __rasputinHandleRun__5() {
|
|
3870
|
+
return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
|
|
3697
3871
|
return observeRecordedCallback(
|
|
3698
3872
|
recording,
|
|
3699
3873
|
recorderStartedAtNs,
|
|
@@ -3705,7 +3879,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3705
3879
|
);
|
|
3706
3880
|
});
|
|
3707
3881
|
}
|
|
3708
|
-
const callStore =
|
|
3882
|
+
const callStore = callerStore(store, plan.functionId, callId);
|
|
3709
3883
|
return runStore(callStore, function __rasputinHandleRun__5() {
|
|
3710
3884
|
return observeRecordedCallback(
|
|
3711
3885
|
recording,
|
|
@@ -3713,15 +3887,25 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3713
3887
|
callback,
|
|
3714
3888
|
(value) => {
|
|
3715
3889
|
if (recording.journal) {
|
|
3716
|
-
const endedAtNs =
|
|
3890
|
+
const endedAtNs = timed ? readCallClock() : void 0;
|
|
3717
3891
|
const returnValue = exitPayload(recording, omitCallValues, value);
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3892
|
+
if (endedAtNs !== void 0) {
|
|
3893
|
+
recording.journal.finishCall(
|
|
3894
|
+
KIND_EXIT,
|
|
3895
|
+
callId,
|
|
3896
|
+
endedAtNs - recording.startedAtNs,
|
|
3897
|
+
endedAtNs - startedAtNs,
|
|
3898
|
+
returnValue
|
|
3899
|
+
);
|
|
3900
|
+
} else {
|
|
3901
|
+
recording.journal.finishCall(
|
|
3902
|
+
KIND_EXIT,
|
|
3903
|
+
callId,
|
|
3904
|
+
TIMING_UNAVAILABLE,
|
|
3905
|
+
TIMING_UNAVAILABLE,
|
|
3906
|
+
returnValue
|
|
3907
|
+
);
|
|
3908
|
+
}
|
|
3725
3909
|
stats.functionCallsCaptured++;
|
|
3726
3910
|
}
|
|
3727
3911
|
settleInFlight(recording);
|
|
@@ -3732,12 +3916,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3732
3916
|
return;
|
|
3733
3917
|
}
|
|
3734
3918
|
const capturedError = serializedError(recording, error, callId);
|
|
3735
|
-
const endedAtNs =
|
|
3919
|
+
const endedAtNs = readCallClock();
|
|
3736
3920
|
recording.journal.finishCall(
|
|
3737
3921
|
KIND_THROW,
|
|
3738
3922
|
callId,
|
|
3739
3923
|
endedAtNs - recording.startedAtNs,
|
|
3740
|
-
endedAtNs - startedAtNs,
|
|
3924
|
+
timed ? endedAtNs - startedAtNs : TIMING_UNAVAILABLE,
|
|
3741
3925
|
capturedError.value
|
|
3742
3926
|
);
|
|
3743
3927
|
stats.functionCallsCaptured++;
|
|
@@ -3749,21 +3933,22 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3749
3933
|
};
|
|
3750
3934
|
const noopHandle2 = passthroughHandle();
|
|
3751
3935
|
class CallFrame {
|
|
3752
|
-
constructor(mode, recording, parentStore, activeStore, plan, args, omitCallValues, parentCallId, startedAtNs, callId, group, captureDroppedThrow) {
|
|
3936
|
+
constructor(mode, recording, parentStore, activeStore, plan, args, omitCallValues, parentCallId, startedAtNs, timed, callId, group, captureDroppedThrow) {
|
|
3753
3937
|
this.mode = mode;
|
|
3754
3938
|
this.status = "open";
|
|
3755
3939
|
this.pendingReturn = void 0;
|
|
3756
3940
|
this.ended = false;
|
|
3757
3941
|
this.suspended = false;
|
|
3758
3942
|
this.startedAtNs = startedAtNs;
|
|
3943
|
+
this.timed = timed;
|
|
3759
3944
|
this.callId = callId;
|
|
3760
3945
|
this.recording = recording;
|
|
3761
3946
|
this.plan = plan;
|
|
3762
3947
|
this.args = args;
|
|
3763
3948
|
this.omitCallValues = omitCallValues;
|
|
3764
3949
|
this.parentCallId = parentCallId;
|
|
3765
|
-
this.parentStore = parentStore;
|
|
3766
3950
|
this.activeStore = activeStore;
|
|
3951
|
+
this.parentStore = parentStore;
|
|
3767
3952
|
this.group = group;
|
|
3768
3953
|
this.captureDroppedThrow = captureDroppedThrow;
|
|
3769
3954
|
}
|
|
@@ -3791,6 +3976,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3791
3976
|
this.parentCallId,
|
|
3792
3977
|
this.startedAtNs,
|
|
3793
3978
|
error,
|
|
3979
|
+
this.timed,
|
|
3794
3980
|
this.recording.captureValues ? void 0 : ARGS_OMITTED
|
|
3795
3981
|
);
|
|
3796
3982
|
} else if (this.mode === "dropped" && this.captureDroppedThrow && this.plan) {
|
|
@@ -3801,6 +3987,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3801
3987
|
this.parentCallId,
|
|
3802
3988
|
this.startedAtNs,
|
|
3803
3989
|
error,
|
|
3990
|
+
this.timed,
|
|
3804
3991
|
this.recording.captureValues ? void 0 : ARGS_OMITTED
|
|
3805
3992
|
);
|
|
3806
3993
|
}
|
|
@@ -3819,7 +4006,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3819
4006
|
this.group,
|
|
3820
4007
|
this.parentCallId,
|
|
3821
4008
|
this.startedAtNs,
|
|
3822
|
-
|
|
4009
|
+
this.timed ? readCallClock() : 0n,
|
|
4010
|
+
this.timed
|
|
3823
4011
|
);
|
|
3824
4012
|
} else if (this.mode === "dropped") {
|
|
3825
4013
|
const droppedBefore = this.recording.journal?.dropped ?? 0;
|
|
@@ -3890,47 +4078,59 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3890
4078
|
};
|
|
3891
4079
|
const writeCapturedExit = (frame, value) => {
|
|
3892
4080
|
if (!frame.recording.journal) return;
|
|
3893
|
-
const endedAtNs =
|
|
4081
|
+
const endedAtNs = frame.timed ? readCallClock() : void 0;
|
|
3894
4082
|
const returnValue = exitPayload(frame.recording, frame.omitCallValues, value);
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
4083
|
+
if (endedAtNs !== void 0) {
|
|
4084
|
+
frame.recording.journal.finishCall(
|
|
4085
|
+
KIND_EXIT,
|
|
4086
|
+
frame.callId,
|
|
4087
|
+
endedAtNs - frame.recording.startedAtNs,
|
|
4088
|
+
endedAtNs - frame.startedAtNs,
|
|
4089
|
+
returnValue
|
|
4090
|
+
);
|
|
4091
|
+
} else {
|
|
4092
|
+
frame.recording.journal.finishCall(
|
|
4093
|
+
KIND_EXIT,
|
|
4094
|
+
frame.callId,
|
|
4095
|
+
TIMING_UNAVAILABLE,
|
|
4096
|
+
TIMING_UNAVAILABLE,
|
|
4097
|
+
returnValue
|
|
4098
|
+
);
|
|
4099
|
+
}
|
|
3902
4100
|
stats.functionCallsCaptured++;
|
|
3903
4101
|
};
|
|
3904
4102
|
const writeCapturedThrow = (frame, error) => {
|
|
3905
4103
|
if (!frame.recording.journal) return;
|
|
3906
|
-
const endedAtNs =
|
|
4104
|
+
const endedAtNs = readCallClock();
|
|
3907
4105
|
const capturedError = serializedError(frame.recording, error, frame.callId);
|
|
3908
4106
|
frame.recording.journal.finishCall(
|
|
3909
4107
|
KIND_THROW,
|
|
3910
4108
|
frame.callId,
|
|
3911
4109
|
endedAtNs - frame.recording.startedAtNs,
|
|
3912
|
-
endedAtNs - frame.startedAtNs,
|
|
4110
|
+
frame.timed ? endedAtNs - frame.startedAtNs : TIMING_UNAVAILABLE,
|
|
3913
4111
|
capturedError.value
|
|
3914
4112
|
);
|
|
3915
4113
|
stats.functionCallsCaptured++;
|
|
3916
4114
|
capturedError.commit();
|
|
3917
4115
|
};
|
|
3918
|
-
const activateUncaptured = (mode, recording, parentStore, plan, args, omitCallValues, parentCallId, startedAtNs, group, captureDroppedThrow) => {
|
|
4116
|
+
const activateUncaptured = (mode, recording, parentStore, plan, args, omitCallValues, parentCallId, startedAtNs, timed, group, captureDroppedThrow) => {
|
|
4117
|
+
const activeStore = callerStore(parentStore, plan.functionId);
|
|
3919
4118
|
const frame = new CallFrame(
|
|
3920
4119
|
mode,
|
|
3921
4120
|
recording,
|
|
3922
4121
|
parentStore,
|
|
3923
|
-
|
|
4122
|
+
activeStore,
|
|
3924
4123
|
plan,
|
|
3925
4124
|
args,
|
|
3926
4125
|
omitCallValues,
|
|
3927
4126
|
parentCallId,
|
|
3928
4127
|
startedAtNs,
|
|
4128
|
+
timed,
|
|
3929
4129
|
0,
|
|
3930
4130
|
group,
|
|
3931
4131
|
captureDroppedThrow
|
|
3932
4132
|
);
|
|
3933
|
-
enterStore(frame,
|
|
4133
|
+
enterStore(frame, activeStore);
|
|
3934
4134
|
return frame;
|
|
3935
4135
|
};
|
|
3936
4136
|
const enterPreparedFunctionFromStore = (store, plan, args, omitValues) => {
|
|
@@ -3952,6 +4152,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3952
4152
|
false,
|
|
3953
4153
|
void 0,
|
|
3954
4154
|
0n,
|
|
4155
|
+
true,
|
|
3955
4156
|
0,
|
|
3956
4157
|
void 0,
|
|
3957
4158
|
false
|
|
@@ -3974,6 +4175,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3974
4175
|
false,
|
|
3975
4176
|
void 0,
|
|
3976
4177
|
0n,
|
|
4178
|
+
true,
|
|
3977
4179
|
0,
|
|
3978
4180
|
void 0,
|
|
3979
4181
|
false
|
|
@@ -3989,7 +4191,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
3989
4191
|
if (group.observedCalls === 1) journal?.notePlan(plan.runtimePlanId);
|
|
3990
4192
|
} catch {
|
|
3991
4193
|
}
|
|
3992
|
-
const
|
|
4194
|
+
const timed = durationSamplingEnabled ? decideCallTiming(recording, plan, store.currentFunctionId) : true;
|
|
4195
|
+
const startedAtNs = timed ? readCallClock() : 0n;
|
|
3993
4196
|
const parentStore = store;
|
|
3994
4197
|
const retainedArgs = recording.captureValues ? args : EMPTY_ARGS;
|
|
3995
4198
|
if (group.observedCalls > capturedCallLimitFor(recording)) {
|
|
@@ -4002,6 +4205,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4002
4205
|
omitCallValues,
|
|
4003
4206
|
parentCallId,
|
|
4004
4207
|
startedAtNs,
|
|
4208
|
+
timed,
|
|
4005
4209
|
group,
|
|
4006
4210
|
false
|
|
4007
4211
|
);
|
|
@@ -4017,6 +4221,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4017
4221
|
omitCallValues,
|
|
4018
4222
|
parentCallId,
|
|
4019
4223
|
startedAtNs,
|
|
4224
|
+
timed,
|
|
4020
4225
|
group,
|
|
4021
4226
|
false
|
|
4022
4227
|
);
|
|
@@ -4031,6 +4236,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4031
4236
|
omitCallValues,
|
|
4032
4237
|
parentCallId,
|
|
4033
4238
|
startedAtNs,
|
|
4239
|
+
timed,
|
|
4034
4240
|
group,
|
|
4035
4241
|
true
|
|
4036
4242
|
);
|
|
@@ -4045,12 +4251,13 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4045
4251
|
omitCallValues,
|
|
4046
4252
|
parentCallId,
|
|
4047
4253
|
startedAtNs,
|
|
4254
|
+
timed,
|
|
4048
4255
|
group,
|
|
4049
4256
|
false
|
|
4050
4257
|
);
|
|
4051
4258
|
}
|
|
4052
4259
|
const callId = ++recording.nextCallId;
|
|
4053
|
-
const enterTimestampNs =
|
|
4260
|
+
const enterTimestampNs = timed ? readCallClock() - recording.startedAtNs : TIMING_UNAVAILABLE;
|
|
4054
4261
|
const capturedArgs = enterPayload(recording, omitCallValues, args);
|
|
4055
4262
|
try {
|
|
4056
4263
|
journal.startCall(plan.runtimePlanId, callId, parentCallId, enterTimestampNs, capturedArgs);
|
|
@@ -4065,11 +4272,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4065
4272
|
omitCallValues,
|
|
4066
4273
|
parentCallId,
|
|
4067
4274
|
startedAtNs,
|
|
4275
|
+
timed,
|
|
4068
4276
|
group,
|
|
4069
4277
|
false
|
|
4070
4278
|
);
|
|
4071
4279
|
}
|
|
4072
|
-
const callStore =
|
|
4280
|
+
const callStore = callerStore(store, plan.functionId, callId);
|
|
4073
4281
|
const captured = new CallFrame(
|
|
4074
4282
|
"captured",
|
|
4075
4283
|
recording,
|
|
@@ -4080,6 +4288,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4080
4288
|
omitCallValues,
|
|
4081
4289
|
parentCallId,
|
|
4082
4290
|
startedAtNs,
|
|
4291
|
+
timed,
|
|
4083
4292
|
callId,
|
|
4084
4293
|
group,
|
|
4085
4294
|
false
|
|
@@ -4148,6 +4357,9 @@ var createExecutionRecorder = (options, hooks = {}) => {
|
|
|
4148
4357
|
runPreparedFunction,
|
|
4149
4358
|
enterPreparedFunction,
|
|
4150
4359
|
trace,
|
|
4360
|
+
close: () => {
|
|
4361
|
+
durationSamples?.stop();
|
|
4362
|
+
},
|
|
4151
4363
|
getStats: () => ({
|
|
4152
4364
|
...stats,
|
|
4153
4365
|
...memoryBudget.getStats(),
|
|
@@ -5049,7 +5261,7 @@ var createExecutionRecordingCoordinator = (options) => {
|
|
|
5049
5261
|
// src/execution-recorder/bind-adaptive-recorder.ts
|
|
5050
5262
|
var bindAdaptiveRecorder = (input) => {
|
|
5051
5263
|
const options = input.executionRecorder;
|
|
5052
|
-
const
|
|
5264
|
+
const adaptiveEnabled = options?.adaptive?.enabled === true;
|
|
5053
5265
|
const activation = resolveClientActivation({
|
|
5054
5266
|
enabled: input.enabled,
|
|
5055
5267
|
dsn: input.dsn,
|
|
@@ -5057,7 +5269,7 @@ var bindAdaptiveRecorder = (input) => {
|
|
|
5057
5269
|
apiUrl: input.apiUrl,
|
|
5058
5270
|
release: input.release
|
|
5059
5271
|
});
|
|
5060
|
-
const coordinator = input.recorderEnabled && activation.enabled ? createExecutionRecordingCoordinator({
|
|
5272
|
+
const coordinator = input.recorderEnabled && activation.enabled && options?.sessions !== false ? createExecutionRecordingCoordinator({
|
|
5061
5273
|
environment: input.environment ?? "",
|
|
5062
5274
|
ingestToken: activation.ingestToken,
|
|
5063
5275
|
activateUrl: resolveEndpointUrls2(activation.apiUrl).executionRecordingActivateUrl,
|
|
@@ -5068,14 +5280,14 @@ var bindAdaptiveRecorder = (input) => {
|
|
|
5068
5280
|
release: activation.release,
|
|
5069
5281
|
recorderOptions: options,
|
|
5070
5282
|
scrubPII: input.scrubPII,
|
|
5071
|
-
mode,
|
|
5283
|
+
mode: adaptiveEnabled ? "adaptive" : "full",
|
|
5072
5284
|
fetch: input.fetch
|
|
5073
5285
|
}) : void 0;
|
|
5074
5286
|
const runtime = createExecutionRecorder(
|
|
5075
5287
|
{ ...options, enabled: input.recorderEnabled },
|
|
5076
5288
|
coordinator ? {
|
|
5077
5289
|
policySnapshot: coordinator.peek,
|
|
5078
|
-
onQualifyingFailure:
|
|
5290
|
+
onQualifyingFailure: adaptiveEnabled ? coordinator.activate : void 0,
|
|
5079
5291
|
getStats: coordinator.getStats,
|
|
5080
5292
|
sessionCaptureSnapshot: coordinator.peekSessions,
|
|
5081
5293
|
consumeSession: coordinator.consumeSession,
|