@reproapp/node-sdk 0.0.22 → 0.0.23
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/index.js +23 -2
- package/package.json +1 -1
- package/src/index.ts +23 -2
- package/test/trace-batch-size.test.js +16 -0
package/dist/index.js
CHANGED
|
@@ -1712,6 +1712,18 @@ const TRACE_BATCH_MAX_SERIALIZED_BYTES = (() => {
|
|
|
1712
1712
|
return Math.trunc(env);
|
|
1713
1713
|
return 512 * 1024;
|
|
1714
1714
|
})();
|
|
1715
|
+
const TRACE_MAX_EVENTS_PER_REQUEST = (() => {
|
|
1716
|
+
const env = Number(process.env.REPRO_TRACE_MAX_EVENTS_PER_REQUEST);
|
|
1717
|
+
if (Number.isFinite(env) && env > 0)
|
|
1718
|
+
return Math.trunc(env);
|
|
1719
|
+
return 1000;
|
|
1720
|
+
})();
|
|
1721
|
+
const TRACE_MAX_BATCHES_PER_REQUEST = (() => {
|
|
1722
|
+
const env = Number(process.env.REPRO_TRACE_MAX_BATCHES_PER_REQUEST);
|
|
1723
|
+
if (Number.isFinite(env) && env > 0)
|
|
1724
|
+
return Math.trunc(env);
|
|
1725
|
+
return 8;
|
|
1726
|
+
})();
|
|
1715
1727
|
const TRACE_FLUSH_DELAY_MS = 20;
|
|
1716
1728
|
// Choose how to order trace events in payloads.
|
|
1717
1729
|
// - "chronological" (default): preserve event arrival order (no reshuffle).
|
|
@@ -3766,22 +3778,31 @@ function estimateTraceBatchSerializedBytes(batch, requestRid, actionId, batchInd
|
|
|
3766
3778
|
function chunkTraceEventsForTransport(events, requestRid, actionId) {
|
|
3767
3779
|
if (!Array.isArray(events) || events.length === 0)
|
|
3768
3780
|
return [];
|
|
3769
|
-
const
|
|
3781
|
+
const boundedEvents = events.slice(0, TRACE_MAX_EVENTS_PER_REQUEST);
|
|
3782
|
+
const countBatches = chunkArray(boundedEvents, TRACE_BATCH_SIZE);
|
|
3770
3783
|
const sizedBatches = [];
|
|
3771
3784
|
let current = [];
|
|
3772
3785
|
for (const event of countBatches.flat()) {
|
|
3786
|
+
if (sizedBatches.length >= TRACE_MAX_BATCHES_PER_REQUEST) {
|
|
3787
|
+
break;
|
|
3788
|
+
}
|
|
3773
3789
|
const candidate = current.concat(event);
|
|
3774
3790
|
const batchIndex = sizedBatches.length;
|
|
3775
3791
|
const estimatedBytes = estimateTraceBatchSerializedBytes(candidate, requestRid, actionId, batchIndex);
|
|
3776
3792
|
if (current.length > 0 &&
|
|
3777
3793
|
estimatedBytes > TRACE_BATCH_MAX_SERIALIZED_BYTES) {
|
|
3778
3794
|
sizedBatches.push(current);
|
|
3795
|
+
if (sizedBatches.length >= TRACE_MAX_BATCHES_PER_REQUEST) {
|
|
3796
|
+
current = [];
|
|
3797
|
+
break;
|
|
3798
|
+
}
|
|
3779
3799
|
current = [event];
|
|
3780
3800
|
continue;
|
|
3781
3801
|
}
|
|
3782
3802
|
current = candidate;
|
|
3783
3803
|
}
|
|
3784
|
-
if (current.length > 0
|
|
3804
|
+
if (current.length > 0 &&
|
|
3805
|
+
sizedBatches.length < TRACE_MAX_BATCHES_PER_REQUEST) {
|
|
3785
3806
|
sizedBatches.push(current);
|
|
3786
3807
|
}
|
|
3787
3808
|
return sizedBatches;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2116,6 +2116,16 @@ const TRACE_BATCH_MAX_SERIALIZED_BYTES = (() => {
|
|
|
2116
2116
|
if (Number.isFinite(env) && env > 0) return Math.trunc(env);
|
|
2117
2117
|
return 512 * 1024;
|
|
2118
2118
|
})();
|
|
2119
|
+
const TRACE_MAX_EVENTS_PER_REQUEST = (() => {
|
|
2120
|
+
const env = Number(process.env.REPRO_TRACE_MAX_EVENTS_PER_REQUEST);
|
|
2121
|
+
if (Number.isFinite(env) && env > 0) return Math.trunc(env);
|
|
2122
|
+
return 1000;
|
|
2123
|
+
})();
|
|
2124
|
+
const TRACE_MAX_BATCHES_PER_REQUEST = (() => {
|
|
2125
|
+
const env = Number(process.env.REPRO_TRACE_MAX_BATCHES_PER_REQUEST);
|
|
2126
|
+
if (Number.isFinite(env) && env > 0) return Math.trunc(env);
|
|
2127
|
+
return 8;
|
|
2128
|
+
})();
|
|
2119
2129
|
const TRACE_FLUSH_DELAY_MS = 20;
|
|
2120
2130
|
// Choose how to order trace events in payloads.
|
|
2121
2131
|
// - "chronological" (default): preserve event arrival order (no reshuffle).
|
|
@@ -4499,11 +4509,15 @@ function chunkTraceEventsForTransport(
|
|
|
4499
4509
|
): TraceEventRecord[][] {
|
|
4500
4510
|
if (!Array.isArray(events) || events.length === 0) return [];
|
|
4501
4511
|
|
|
4502
|
-
const
|
|
4512
|
+
const boundedEvents = events.slice(0, TRACE_MAX_EVENTS_PER_REQUEST);
|
|
4513
|
+
const countBatches = chunkArray(boundedEvents, TRACE_BATCH_SIZE);
|
|
4503
4514
|
const sizedBatches: TraceEventRecord[][] = [];
|
|
4504
4515
|
let current: TraceEventRecord[] = [];
|
|
4505
4516
|
|
|
4506
4517
|
for (const event of countBatches.flat()) {
|
|
4518
|
+
if (sizedBatches.length >= TRACE_MAX_BATCHES_PER_REQUEST) {
|
|
4519
|
+
break;
|
|
4520
|
+
}
|
|
4507
4521
|
const candidate = current.concat(event);
|
|
4508
4522
|
const batchIndex = sizedBatches.length;
|
|
4509
4523
|
const estimatedBytes = estimateTraceBatchSerializedBytes(
|
|
@@ -4518,6 +4532,10 @@ function chunkTraceEventsForTransport(
|
|
|
4518
4532
|
estimatedBytes > TRACE_BATCH_MAX_SERIALIZED_BYTES
|
|
4519
4533
|
) {
|
|
4520
4534
|
sizedBatches.push(current);
|
|
4535
|
+
if (sizedBatches.length >= TRACE_MAX_BATCHES_PER_REQUEST) {
|
|
4536
|
+
current = [];
|
|
4537
|
+
break;
|
|
4538
|
+
}
|
|
4521
4539
|
current = [event];
|
|
4522
4540
|
continue;
|
|
4523
4541
|
}
|
|
@@ -4525,7 +4543,10 @@ function chunkTraceEventsForTransport(
|
|
|
4525
4543
|
current = candidate;
|
|
4526
4544
|
}
|
|
4527
4545
|
|
|
4528
|
-
if (
|
|
4546
|
+
if (
|
|
4547
|
+
current.length > 0 &&
|
|
4548
|
+
sizedBatches.length < TRACE_MAX_BATCHES_PER_REQUEST
|
|
4549
|
+
) {
|
|
4529
4550
|
sizedBatches.push(current);
|
|
4530
4551
|
}
|
|
4531
4552
|
|
|
@@ -37,6 +37,10 @@ function main() {
|
|
|
37
37
|
);
|
|
38
38
|
|
|
39
39
|
assert(batches.length > 1, `expected more than one batch, got ${batches.length}`);
|
|
40
|
+
assert(
|
|
41
|
+
batches.length <= 8,
|
|
42
|
+
`expected trace transport to cap batches per request, got ${batches.length}`,
|
|
43
|
+
);
|
|
40
44
|
|
|
41
45
|
batches.forEach((batch, index) => {
|
|
42
46
|
const size = __reproTestHooks.estimateTraceBatchSerializedBytesForTest(
|
|
@@ -51,6 +55,18 @@ function main() {
|
|
|
51
55
|
);
|
|
52
56
|
});
|
|
53
57
|
|
|
58
|
+
const manyEvents = Array.from({ length: 1500 }, (_, index) => makeEvent(index, 'tiny'));
|
|
59
|
+
const cappedBatches = __reproTestHooks.chunkTraceEventsForTransportForTest(
|
|
60
|
+
manyEvents,
|
|
61
|
+
'RID_test_trace_event_cap',
|
|
62
|
+
'A_test_trace_event_cap',
|
|
63
|
+
);
|
|
64
|
+
const cappedEventCount = cappedBatches.reduce((sum, batch) => sum + batch.length, 0);
|
|
65
|
+
assert(
|
|
66
|
+
cappedEventCount <= 1000,
|
|
67
|
+
`expected trace transport to cap events per request, got ${cappedEventCount}`,
|
|
68
|
+
);
|
|
69
|
+
|
|
54
70
|
// eslint-disable-next-line no-console
|
|
55
71
|
console.log('trace batch size chunking OK');
|
|
56
72
|
}
|