@reproapp/node-sdk 0.0.9 → 0.0.11
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.d.ts +10 -0
- package/dist/index.js +62 -14
- package/package.json +2 -2
- package/src/index.ts +67 -16
- package/test/kafka-runtime-privacy-policy.test.js +6 -0
- package/test/sdk-background-priority.test.js +35 -0
package/dist/index.d.ts
CHANGED
|
@@ -254,6 +254,8 @@ export type ReproTracingInitOptions = TracerInitOpts & {
|
|
|
254
254
|
export declare function initReproTracing(opts?: ReproTracingInitOptions): TracerApi | null;
|
|
255
255
|
/** Optional helper if users want to check it. */
|
|
256
256
|
export declare function isReproTracingEnabled(): boolean;
|
|
257
|
+
declare function sanitizeTraceValueForPrivacy(value: any): any;
|
|
258
|
+
declare function sanitizeMaterializedTraceValue(value: any): any;
|
|
257
259
|
export declare function __materializePendingTraceEventsForWorker(payload: TraceMaterializationWorkerPayload): Promise<PendingTraceEventRecord[]>;
|
|
258
260
|
type NormalizedMaskRule = {
|
|
259
261
|
when?: ReproMaskWhen;
|
|
@@ -344,6 +346,12 @@ export declare function initRepro(cfg: ReproInitConfig): Promise<void>;
|
|
|
344
346
|
/** @internal Test hooks for runtime privacy policy wiring. */
|
|
345
347
|
export declare const __reproTestHooks: {
|
|
346
348
|
shareRuntimePrivacyStateForTest: typeof shareRuntimePrivacyState;
|
|
349
|
+
setFullValueCaptureEnabledForTest(enabled: boolean): void;
|
|
350
|
+
scheduleSdkBackgroundWorkForTest(work: () => Promise<void> | void, options?: {
|
|
351
|
+
priority?: 'high' | 'normal';
|
|
352
|
+
}): void;
|
|
353
|
+
drainSdkBackgroundQueueForTest(): Promise<void>;
|
|
354
|
+
resetSdkBackgroundQueuesForTest(): void;
|
|
347
355
|
getRuntimePrivacyPolicyForTest(cfg: ReproMiddlewareConfig): NormalizedRuntimePrivacyPolicy | null;
|
|
348
356
|
setRuntimePrivacyPolicyForTest(cfg: ReproMiddlewareConfig, policy: NormalizedRuntimePrivacyPolicy | null): void;
|
|
349
357
|
recordKafkaTraceEventAsyncForTest: typeof recordKafkaTraceEventAsync;
|
|
@@ -352,5 +360,7 @@ export declare const __reproTestHooks: {
|
|
|
352
360
|
wrapKafkaEachMessageHandlerForTest: typeof wrapKafkaEachMessageHandler;
|
|
353
361
|
chunkTraceEventsForTransportForTest: typeof chunkTraceEventsForTransport;
|
|
354
362
|
estimateTraceBatchSerializedBytesForTest: typeof estimateTraceBatchSerializedBytes;
|
|
363
|
+
sanitizeTraceValueForPrivacyForTest: typeof sanitizeTraceValueForPrivacy;
|
|
364
|
+
sanitizeMaterializedTraceValueForTest: typeof sanitizeMaterializedTraceValue;
|
|
355
365
|
};
|
|
356
366
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -863,6 +863,7 @@ let activeClientRequestCount = 0;
|
|
|
863
863
|
let oldestActiveClientRequestAt = null;
|
|
864
864
|
let lastClientActivityAt = 0;
|
|
865
865
|
let sdkBackgroundQuietUntil = 0;
|
|
866
|
+
const sdkBackgroundHighQueue = [];
|
|
866
867
|
const sdkBackgroundQueue = [];
|
|
867
868
|
let sdkBackgroundTimer = null;
|
|
868
869
|
let sdkBackgroundDraining = false;
|
|
@@ -1155,8 +1156,13 @@ function endClientRequest() {
|
|
|
1155
1156
|
scheduleSdkBackgroundDrain();
|
|
1156
1157
|
}
|
|
1157
1158
|
}
|
|
1158
|
-
function scheduleSdkBackgroundWork(work) {
|
|
1159
|
-
|
|
1159
|
+
function scheduleSdkBackgroundWork(work, options = {}) {
|
|
1160
|
+
if (options.priority === 'high') {
|
|
1161
|
+
sdkBackgroundHighQueue.push(work);
|
|
1162
|
+
}
|
|
1163
|
+
else {
|
|
1164
|
+
sdkBackgroundQueue.push(work);
|
|
1165
|
+
}
|
|
1160
1166
|
scheduleSdkBackgroundDrain();
|
|
1161
1167
|
}
|
|
1162
1168
|
function scheduleSdkBackgroundDrain(delayMs = 0) {
|
|
@@ -1209,12 +1215,12 @@ async function drainSdkBackgroundQueue() {
|
|
|
1209
1215
|
}
|
|
1210
1216
|
sdkBackgroundDraining = true;
|
|
1211
1217
|
try {
|
|
1212
|
-
while (sdkBackgroundQueue.length > 0) {
|
|
1218
|
+
while (sdkBackgroundHighQueue.length > 0 || sdkBackgroundQueue.length > 0) {
|
|
1213
1219
|
if (shouldDeferSdkBackgroundWork()) {
|
|
1214
1220
|
scheduleSdkBackgroundDrain();
|
|
1215
1221
|
return;
|
|
1216
1222
|
}
|
|
1217
|
-
const work = sdkBackgroundQueue.shift();
|
|
1223
|
+
const work = sdkBackgroundHighQueue.shift() ?? sdkBackgroundQueue.shift();
|
|
1218
1224
|
if (!work)
|
|
1219
1225
|
continue;
|
|
1220
1226
|
try {
|
|
@@ -1228,7 +1234,7 @@ async function drainSdkBackgroundQueue() {
|
|
|
1228
1234
|
}
|
|
1229
1235
|
finally {
|
|
1230
1236
|
sdkBackgroundDraining = false;
|
|
1231
|
-
if (sdkBackgroundQueue.length > 0) {
|
|
1237
|
+
if (sdkBackgroundHighQueue.length > 0 || sdkBackgroundQueue.length > 0) {
|
|
1232
1238
|
scheduleSdkBackgroundDrain();
|
|
1233
1239
|
}
|
|
1234
1240
|
else {
|
|
@@ -2032,14 +2038,26 @@ function sanitizeTraceValue(value, depth = 0, seen = new WeakMap(), options = {}
|
|
|
2032
2038
|
return circularReference(existingPath);
|
|
2033
2039
|
seen.set(value, valuePath);
|
|
2034
2040
|
if (!options.disableTruncation && depth >= TRACE_VALUE_MAX_DEPTH) {
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2041
|
+
if (Array.isArray(value)) {
|
|
2042
|
+
return {
|
|
2043
|
+
__type: 'Array',
|
|
2044
|
+
length: value.length,
|
|
2045
|
+
__truncated: `depth>${TRACE_VALUE_MAX_DEPTH}`,
|
|
2046
|
+
};
|
|
2038
2047
|
}
|
|
2039
2048
|
const ctor = value?.constructor?.name;
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2049
|
+
const keys = Object.keys(value);
|
|
2050
|
+
const summary = {
|
|
2051
|
+
__truncated: `depth>${TRACE_VALUE_MAX_DEPTH}`,
|
|
2052
|
+
__keys: keys.slice(0, TRACE_VALUE_MAX_KEYS),
|
|
2053
|
+
};
|
|
2054
|
+
if (keys.length > TRACE_VALUE_MAX_KEYS) {
|
|
2055
|
+
summary.__truncatedKeys = keys.length - TRACE_VALUE_MAX_KEYS;
|
|
2056
|
+
}
|
|
2057
|
+
if (ctor && ctor !== 'Object') {
|
|
2058
|
+
summary.__class = ctor;
|
|
2059
|
+
}
|
|
2060
|
+
return summary;
|
|
2043
2061
|
}
|
|
2044
2062
|
if (Array.isArray(value)) {
|
|
2045
2063
|
const sourceItems = options.disableTruncation ? value : value.slice(0, TRACE_VALUE_MAX_ITEMS);
|
|
@@ -2105,6 +2123,9 @@ function sanitizeTraceArgs(values) {
|
|
|
2105
2123
|
function sanitizeTraceValueForPrivacy(value) {
|
|
2106
2124
|
return sanitizeTraceValue(value, 0, new WeakMap(), { preserveLongStrings: true, disableTruncation: true });
|
|
2107
2125
|
}
|
|
2126
|
+
function sanitizeInlinePrivacyValue(value) {
|
|
2127
|
+
return sanitizeTraceValue(value, 0, new WeakMap(), { preserveLongStrings: true, disableTruncation: true });
|
|
2128
|
+
}
|
|
2108
2129
|
function sanitizeMaterializedTraceValue(value) {
|
|
2109
2130
|
return sanitizeTraceValue(value, 0, new WeakMap(), { preserveLongStrings: true, disableTruncation: true });
|
|
2110
2131
|
}
|
|
@@ -3860,7 +3881,7 @@ function reproMiddleware(cfg) {
|
|
|
3860
3881
|
}
|
|
3861
3882
|
catch { }
|
|
3862
3883
|
if (flushPayload) {
|
|
3863
|
-
const scheduleFlushPayload = () => scheduleSdkBackgroundWork(flushPayload);
|
|
3884
|
+
const scheduleFlushPayload = () => scheduleSdkBackgroundWork(flushPayload, { priority: 'high' });
|
|
3864
3885
|
if (sessionDrainWait) {
|
|
3865
3886
|
sessionDrainWait.then(scheduleFlushPayload).catch(scheduleFlushPayload);
|
|
3866
3887
|
}
|
|
@@ -5176,7 +5197,7 @@ function cloneKafkaTelemetryValue(value) {
|
|
|
5176
5197
|
}
|
|
5177
5198
|
}
|
|
5178
5199
|
async function materializeKafkaRequestBody(cfg, maskReq, body) {
|
|
5179
|
-
return materializeInlinePrivacyValueAsync('request.body',
|
|
5200
|
+
return materializeInlinePrivacyValueAsync('request.body', sanitizeInlinePrivacyValue(body), cfg, maskReq, null, normalizeMaskingConfig(cfg.masking), getRuntimePrivacyState(cfg).policy ?? null);
|
|
5180
5201
|
}
|
|
5181
5202
|
function summarizeKafkaError(error) {
|
|
5182
5203
|
const message = typeof error?.message === 'string'
|
|
@@ -5404,7 +5425,7 @@ function scheduleKafkaTraceFlush(cfg, kafkaCtx, actionId, requestRid, rawTraceEv
|
|
|
5404
5425
|
post(cfg, sid, { entries });
|
|
5405
5426
|
}
|
|
5406
5427
|
});
|
|
5407
|
-
});
|
|
5428
|
+
}, { priority: 'high' });
|
|
5408
5429
|
}
|
|
5409
5430
|
function patchKafkaProducerInstance(producer, cfg) {
|
|
5410
5431
|
if (!producer || producer.__repro_kafka_producer_patched)
|
|
@@ -6667,6 +6688,31 @@ exports.initRepro = initRepro;
|
|
|
6667
6688
|
/** @internal Test hooks for runtime privacy policy wiring. */
|
|
6668
6689
|
exports.__reproTestHooks = {
|
|
6669
6690
|
shareRuntimePrivacyStateForTest: shareRuntimePrivacyState,
|
|
6691
|
+
setFullValueCaptureEnabledForTest(enabled) {
|
|
6692
|
+
__FULL_VALUE_CAPTURE_ENABLED = enabled === true;
|
|
6693
|
+
},
|
|
6694
|
+
scheduleSdkBackgroundWorkForTest(work, options) {
|
|
6695
|
+
scheduleSdkBackgroundWork(work, options);
|
|
6696
|
+
},
|
|
6697
|
+
async drainSdkBackgroundQueueForTest() {
|
|
6698
|
+
await drainSdkBackgroundQueue();
|
|
6699
|
+
},
|
|
6700
|
+
resetSdkBackgroundQueuesForTest() {
|
|
6701
|
+
sdkBackgroundHighQueue.length = 0;
|
|
6702
|
+
sdkBackgroundQueue.length = 0;
|
|
6703
|
+
if (sdkBackgroundTimer) {
|
|
6704
|
+
try {
|
|
6705
|
+
clearTimeout(sdkBackgroundTimer);
|
|
6706
|
+
}
|
|
6707
|
+
catch { }
|
|
6708
|
+
sdkBackgroundTimer = null;
|
|
6709
|
+
}
|
|
6710
|
+
sdkBackgroundDraining = false;
|
|
6711
|
+
activeClientRequestCount = 0;
|
|
6712
|
+
oldestActiveClientRequestAt = null;
|
|
6713
|
+
lastClientActivityAt = 0;
|
|
6714
|
+
sdkBackgroundQuietUntil = 0;
|
|
6715
|
+
},
|
|
6670
6716
|
getRuntimePrivacyPolicyForTest(cfg) {
|
|
6671
6717
|
return getRuntimePrivacyState(cfg).policy;
|
|
6672
6718
|
},
|
|
@@ -6679,4 +6725,6 @@ exports.__reproTestHooks = {
|
|
|
6679
6725
|
wrapKafkaEachMessageHandlerForTest: wrapKafkaEachMessageHandler,
|
|
6680
6726
|
chunkTraceEventsForTransportForTest: chunkTraceEventsForTransport,
|
|
6681
6727
|
estimateTraceBatchSerializedBytesForTest: estimateTraceBatchSerializedBytes,
|
|
6728
|
+
sanitizeTraceValueForPrivacyForTest: sanitizeTraceValueForPrivacy,
|
|
6729
|
+
sanitizeMaterializedTraceValueForTest: sanitizeMaterializedTraceValue,
|
|
6682
6730
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reproapp/node-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Repro Nest SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"build": "tsc -p tsconfig.json",
|
|
13
13
|
"dev": "tsc -p tsconfig.json --watch --preserveWatchOutput",
|
|
14
14
|
"prepublishOnly": "npm run build",
|
|
15
|
-
"test": "npm run build && node test/unawaited.test.js && node test/integration-unawaited.js && node test/request-flush-timing.test.js && node test/express-trace-http-args.test.js && node test/trace-batch-size.test.js && node -r ./tracer/register test/promise-map.test.js && node test/disable-subtree.test.js && node test/circular-capture.test.js && node test/wrap-plugin-arrow-args.test.js && node test/privacy-runtime-policy.test.js && node test/runtime-privacy-materialization.test.js && node test/kafka-runtime-privacy-policy.test.js"
|
|
15
|
+
"test": "npm run build && node test/unawaited.test.js && node test/integration-unawaited.js && node test/request-flush-timing.test.js && node test/express-trace-http-args.test.js && node test/trace-batch-size.test.js && node test/sdk-background-priority.test.js && node -r ./tracer/register test/promise-map.test.js && node test/disable-subtree.test.js && node test/circular-capture.test.js && node test/wrap-plugin-arrow-args.test.js && node test/privacy-runtime-policy.test.js && node test/runtime-privacy-materialization.test.js && node test/kafka-runtime-privacy-policy.test.js"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"express": "^5.1.0",
|
package/src/index.ts
CHANGED
|
@@ -1231,6 +1231,7 @@ let activeClientRequestCount = 0;
|
|
|
1231
1231
|
let oldestActiveClientRequestAt: number | null = null;
|
|
1232
1232
|
let lastClientActivityAt = 0;
|
|
1233
1233
|
let sdkBackgroundQuietUntil = 0;
|
|
1234
|
+
const sdkBackgroundHighQueue: Array<() => Promise<void> | void> = [];
|
|
1234
1235
|
const sdkBackgroundQueue: Array<() => Promise<void> | void> = [];
|
|
1235
1236
|
let sdkBackgroundTimer: NodeJS.Timeout | null = null;
|
|
1236
1237
|
let sdkBackgroundDraining = false;
|
|
@@ -1499,8 +1500,15 @@ function endClientRequest(): void {
|
|
|
1499
1500
|
}
|
|
1500
1501
|
}
|
|
1501
1502
|
|
|
1502
|
-
function scheduleSdkBackgroundWork(
|
|
1503
|
-
|
|
1503
|
+
function scheduleSdkBackgroundWork(
|
|
1504
|
+
work: () => Promise<void> | void,
|
|
1505
|
+
options: { priority?: 'high' | 'normal' } = {},
|
|
1506
|
+
): void {
|
|
1507
|
+
if (options.priority === 'high') {
|
|
1508
|
+
sdkBackgroundHighQueue.push(work);
|
|
1509
|
+
} else {
|
|
1510
|
+
sdkBackgroundQueue.push(work);
|
|
1511
|
+
}
|
|
1504
1512
|
scheduleSdkBackgroundDrain();
|
|
1505
1513
|
}
|
|
1506
1514
|
|
|
@@ -1549,12 +1557,12 @@ async function drainSdkBackgroundQueue(): Promise<void> {
|
|
|
1549
1557
|
|
|
1550
1558
|
sdkBackgroundDraining = true;
|
|
1551
1559
|
try {
|
|
1552
|
-
while (sdkBackgroundQueue.length > 0) {
|
|
1560
|
+
while (sdkBackgroundHighQueue.length > 0 || sdkBackgroundQueue.length > 0) {
|
|
1553
1561
|
if (shouldDeferSdkBackgroundWork()) {
|
|
1554
1562
|
scheduleSdkBackgroundDrain();
|
|
1555
1563
|
return;
|
|
1556
1564
|
}
|
|
1557
|
-
const work = sdkBackgroundQueue.shift();
|
|
1565
|
+
const work = sdkBackgroundHighQueue.shift() ?? sdkBackgroundQueue.shift();
|
|
1558
1566
|
if (!work) continue;
|
|
1559
1567
|
try {
|
|
1560
1568
|
await drainQueuedIngestBeforeBackgroundWork();
|
|
@@ -1565,7 +1573,7 @@ async function drainSdkBackgroundQueue(): Promise<void> {
|
|
|
1565
1573
|
}
|
|
1566
1574
|
} finally {
|
|
1567
1575
|
sdkBackgroundDraining = false;
|
|
1568
|
-
if (sdkBackgroundQueue.length > 0) {
|
|
1576
|
+
if (sdkBackgroundHighQueue.length > 0 || sdkBackgroundQueue.length > 0) {
|
|
1569
1577
|
scheduleSdkBackgroundDrain();
|
|
1570
1578
|
} else {
|
|
1571
1579
|
kickIngestQueueDrain();
|
|
@@ -2429,14 +2437,26 @@ function sanitizeTraceValue(
|
|
|
2429
2437
|
seen.set(value, valuePath);
|
|
2430
2438
|
|
|
2431
2439
|
if (!options.disableTruncation && depth >= TRACE_VALUE_MAX_DEPTH) {
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2440
|
+
if (Array.isArray(value)) {
|
|
2441
|
+
return {
|
|
2442
|
+
__type: 'Array',
|
|
2443
|
+
length: value.length,
|
|
2444
|
+
__truncated: `depth>${TRACE_VALUE_MAX_DEPTH}`,
|
|
2445
|
+
};
|
|
2435
2446
|
}
|
|
2436
2447
|
const ctor = value?.constructor?.name;
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2448
|
+
const keys = Object.keys(value);
|
|
2449
|
+
const summary: Record<string, any> = {
|
|
2450
|
+
__truncated: `depth>${TRACE_VALUE_MAX_DEPTH}`,
|
|
2451
|
+
__keys: keys.slice(0, TRACE_VALUE_MAX_KEYS),
|
|
2452
|
+
};
|
|
2453
|
+
if (keys.length > TRACE_VALUE_MAX_KEYS) {
|
|
2454
|
+
summary.__truncatedKeys = keys.length - TRACE_VALUE_MAX_KEYS;
|
|
2455
|
+
}
|
|
2456
|
+
if (ctor && ctor !== 'Object') {
|
|
2457
|
+
summary.__class = ctor;
|
|
2458
|
+
}
|
|
2459
|
+
return summary;
|
|
2440
2460
|
}
|
|
2441
2461
|
|
|
2442
2462
|
if (Array.isArray(value)) {
|
|
@@ -2505,6 +2525,10 @@ function sanitizeTraceValueForPrivacy(value: any): any {
|
|
|
2505
2525
|
return sanitizeTraceValue(value, 0, new WeakMap(), { preserveLongStrings: true, disableTruncation: true });
|
|
2506
2526
|
}
|
|
2507
2527
|
|
|
2528
|
+
function sanitizeInlinePrivacyValue(value: any): any {
|
|
2529
|
+
return sanitizeTraceValue(value, 0, new WeakMap(), { preserveLongStrings: true, disableTruncation: true });
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2508
2532
|
function sanitizeMaterializedTraceValue(value: any): any {
|
|
2509
2533
|
return sanitizeTraceValue(value, 0, new WeakMap(), { preserveLongStrings: true, disableTruncation: true });
|
|
2510
2534
|
}
|
|
@@ -4674,11 +4698,11 @@ export function reproMiddleware(cfg: ReproMiddlewareConfig) {
|
|
|
4674
4698
|
return;
|
|
4675
4699
|
}
|
|
4676
4700
|
}
|
|
4677
|
-
|
|
4678
|
-
|
|
4701
|
+
flushed = true;
|
|
4702
|
+
clearTimers();
|
|
4679
4703
|
try { unsubscribe && unsubscribe(); } catch {}
|
|
4680
4704
|
if (flushPayload) {
|
|
4681
|
-
const scheduleFlushPayload = () => scheduleSdkBackgroundWork(flushPayload
|
|
4705
|
+
const scheduleFlushPayload = () => scheduleSdkBackgroundWork(flushPayload!, { priority: 'high' });
|
|
4682
4706
|
if (sessionDrainWait) {
|
|
4683
4707
|
sessionDrainWait.then(scheduleFlushPayload).catch(scheduleFlushPayload);
|
|
4684
4708
|
} else {
|
|
@@ -6083,7 +6107,7 @@ async function materializeKafkaRequestBody(
|
|
|
6083
6107
|
): Promise<InlinePrivacyMaterializationResult> {
|
|
6084
6108
|
return materializeInlinePrivacyValueAsync(
|
|
6085
6109
|
'request.body',
|
|
6086
|
-
|
|
6110
|
+
sanitizeInlinePrivacyValue(body),
|
|
6087
6111
|
cfg,
|
|
6088
6112
|
maskReq,
|
|
6089
6113
|
null,
|
|
@@ -6381,7 +6405,7 @@ function scheduleKafkaTraceFlush(
|
|
|
6381
6405
|
post(cfg, sid, { entries });
|
|
6382
6406
|
}
|
|
6383
6407
|
});
|
|
6384
|
-
});
|
|
6408
|
+
}, { priority: 'high' });
|
|
6385
6409
|
}
|
|
6386
6410
|
|
|
6387
6411
|
function patchKafkaProducerInstance(producer: any, cfg: KafkaJsPatchConfig) {
|
|
@@ -7686,6 +7710,31 @@ export async function initRepro(cfg: ReproInitConfig): Promise<void> {
|
|
|
7686
7710
|
/** @internal Test hooks for runtime privacy policy wiring. */
|
|
7687
7711
|
export const __reproTestHooks = {
|
|
7688
7712
|
shareRuntimePrivacyStateForTest: shareRuntimePrivacyState,
|
|
7713
|
+
setFullValueCaptureEnabledForTest(enabled: boolean): void {
|
|
7714
|
+
__FULL_VALUE_CAPTURE_ENABLED = enabled === true;
|
|
7715
|
+
},
|
|
7716
|
+
scheduleSdkBackgroundWorkForTest(
|
|
7717
|
+
work: () => Promise<void> | void,
|
|
7718
|
+
options?: { priority?: 'high' | 'normal' },
|
|
7719
|
+
): void {
|
|
7720
|
+
scheduleSdkBackgroundWork(work, options);
|
|
7721
|
+
},
|
|
7722
|
+
async drainSdkBackgroundQueueForTest(): Promise<void> {
|
|
7723
|
+
await drainSdkBackgroundQueue();
|
|
7724
|
+
},
|
|
7725
|
+
resetSdkBackgroundQueuesForTest(): void {
|
|
7726
|
+
sdkBackgroundHighQueue.length = 0;
|
|
7727
|
+
sdkBackgroundQueue.length = 0;
|
|
7728
|
+
if (sdkBackgroundTimer) {
|
|
7729
|
+
try { clearTimeout(sdkBackgroundTimer); } catch {}
|
|
7730
|
+
sdkBackgroundTimer = null;
|
|
7731
|
+
}
|
|
7732
|
+
sdkBackgroundDraining = false;
|
|
7733
|
+
activeClientRequestCount = 0;
|
|
7734
|
+
oldestActiveClientRequestAt = null;
|
|
7735
|
+
lastClientActivityAt = 0;
|
|
7736
|
+
sdkBackgroundQuietUntil = 0;
|
|
7737
|
+
},
|
|
7689
7738
|
getRuntimePrivacyPolicyForTest(cfg: ReproMiddlewareConfig): NormalizedRuntimePrivacyPolicy | null {
|
|
7690
7739
|
return getRuntimePrivacyState(cfg).policy;
|
|
7691
7740
|
},
|
|
@@ -7701,4 +7750,6 @@ export const __reproTestHooks = {
|
|
|
7701
7750
|
wrapKafkaEachMessageHandlerForTest: wrapKafkaEachMessageHandler,
|
|
7702
7751
|
chunkTraceEventsForTransportForTest: chunkTraceEventsForTransport,
|
|
7703
7752
|
estimateTraceBatchSerializedBytesForTest: estimateTraceBatchSerializedBytes,
|
|
7753
|
+
sanitizeTraceValueForPrivacyForTest: sanitizeTraceValueForPrivacy,
|
|
7754
|
+
sanitizeMaterializedTraceValueForTest: sanitizeMaterializedTraceValue,
|
|
7704
7755
|
};
|
|
@@ -567,6 +567,7 @@ async function testLargeStringTraceValuesAreCapturedInlineWithoutTruncation() {
|
|
|
567
567
|
};
|
|
568
568
|
|
|
569
569
|
const sink = [];
|
|
570
|
+
__reproTestHooks.setFullValueCaptureEnabledForTest(true);
|
|
570
571
|
await __reproTestHooks.recordKafkaTraceEventAsyncForTest(
|
|
571
572
|
{
|
|
572
573
|
type: 'enter',
|
|
@@ -579,6 +580,7 @@ async function testLargeStringTraceValuesAreCapturedInlineWithoutTruncation() {
|
|
|
579
580
|
cfg,
|
|
580
581
|
maskReq,
|
|
581
582
|
);
|
|
583
|
+
__reproTestHooks.setFullValueCaptureEnabledForTest(false);
|
|
582
584
|
|
|
583
585
|
assert.strictEqual(sink.length, 1);
|
|
584
586
|
assert.strictEqual(sink[0].fn, 'parseGatewayPayload');
|
|
@@ -622,6 +624,7 @@ async function testLargeStructuredTraceValuesAreCapturedInlineWithoutTruncation(
|
|
|
622
624
|
};
|
|
623
625
|
|
|
624
626
|
const sink = [];
|
|
627
|
+
__reproTestHooks.setFullValueCaptureEnabledForTest(true);
|
|
625
628
|
await __reproTestHooks.recordKafkaTraceEventAsyncForTest(
|
|
626
629
|
{
|
|
627
630
|
type: 'enter',
|
|
@@ -634,6 +637,7 @@ async function testLargeStructuredTraceValuesAreCapturedInlineWithoutTruncation(
|
|
|
634
637
|
cfg,
|
|
635
638
|
maskReq,
|
|
636
639
|
);
|
|
640
|
+
__reproTestHooks.setFullValueCaptureEnabledForTest(false);
|
|
637
641
|
|
|
638
642
|
assert.strictEqual(sink.length, 1);
|
|
639
643
|
assert.strictEqual(sink[0].fn, 'recordConsumedEvent');
|
|
@@ -677,6 +681,7 @@ async function testLargeTraceReturnValueIsCapturedInlineWithoutTruncation() {
|
|
|
677
681
|
};
|
|
678
682
|
|
|
679
683
|
const sink = [];
|
|
684
|
+
__reproTestHooks.setFullValueCaptureEnabledForTest(true);
|
|
680
685
|
await __reproTestHooks.recordKafkaTraceEventAsyncForTest(
|
|
681
686
|
{
|
|
682
687
|
type: 'exit',
|
|
@@ -689,6 +694,7 @@ async function testLargeTraceReturnValueIsCapturedInlineWithoutTruncation() {
|
|
|
689
694
|
cfg,
|
|
690
695
|
maskReq,
|
|
691
696
|
);
|
|
697
|
+
__reproTestHooks.setFullValueCaptureEnabledForTest(false);
|
|
692
698
|
|
|
693
699
|
assert.strictEqual(sink.length, 1);
|
|
694
700
|
assert.strictEqual(sink[0].fn, 'toDrillResponse');
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
|
|
3
|
+
const sdk = require('../dist/index.js');
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const hooks = sdk.__reproTestHooks;
|
|
7
|
+
hooks.resetSdkBackgroundQueuesForTest();
|
|
8
|
+
|
|
9
|
+
const order = [];
|
|
10
|
+
|
|
11
|
+
hooks.scheduleSdkBackgroundWorkForTest(() => {
|
|
12
|
+
order.push('normal-1');
|
|
13
|
+
});
|
|
14
|
+
hooks.scheduleSdkBackgroundWorkForTest(() => {
|
|
15
|
+
order.push('normal-2');
|
|
16
|
+
});
|
|
17
|
+
hooks.scheduleSdkBackgroundWorkForTest(() => {
|
|
18
|
+
order.push('high-1');
|
|
19
|
+
}, { priority: 'high' });
|
|
20
|
+
hooks.scheduleSdkBackgroundWorkForTest(() => {
|
|
21
|
+
order.push('high-2');
|
|
22
|
+
}, { priority: 'high' });
|
|
23
|
+
|
|
24
|
+
await hooks.drainSdkBackgroundQueueForTest();
|
|
25
|
+
|
|
26
|
+
assert.deepStrictEqual(order, ['high-1', 'high-2', 'normal-1', 'normal-2']);
|
|
27
|
+
|
|
28
|
+
hooks.resetSdkBackgroundQueuesForTest();
|
|
29
|
+
console.log('sdk background priority OK');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
main().catch((error) => {
|
|
33
|
+
console.error(error);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
});
|