@zintrust/trace 0.5.9 → 0.7.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/build-manifest.json +66 -66
- package/dist/register.js +7 -3
- package/dist/storage/TraceEntryFiltering.js +55 -0
- package/package.json +3 -3
- package/src/register.ts +12 -3
- package/src/storage/TraceEntryFiltering.ts +79 -1
package/dist/build-manifest.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/trace",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"buildDate": "2026-04-
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"buildDate": "2026-04-17T14:20:06.644Z",
|
|
5
5
|
"buildEnvironment": {
|
|
6
6
|
"node": "v22.22.1",
|
|
7
7
|
"platform": "darwin",
|
|
8
8
|
"arch": "arm64"
|
|
9
9
|
},
|
|
10
10
|
"git": {
|
|
11
|
-
"commit": "
|
|
11
|
+
"commit": "5b1c8641",
|
|
12
12
|
"branch": "release"
|
|
13
13
|
},
|
|
14
14
|
"package": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"files": {
|
|
24
24
|
"build-manifest.json": {
|
|
25
|
-
"size":
|
|
26
|
-
"sha256": "
|
|
25
|
+
"size": 14743,
|
|
26
|
+
"sha256": "28f88d02b98b9c6fcfb60b9344de6eebd8307e3186da15e82d1e4332691ac87d"
|
|
27
27
|
},
|
|
28
28
|
"cli-register.d.ts": {
|
|
29
29
|
"size": 255,
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"sha256": "b034cbef0c71fb868071363624ef7a9f8d7acc20f8be8c895dd5db5a75e81f37"
|
|
39
39
|
},
|
|
40
40
|
"config.js": {
|
|
41
|
-
"size":
|
|
42
|
-
"sha256": "
|
|
41
|
+
"size": 10064,
|
|
42
|
+
"sha256": "cef8c30f280d02b765c3930c1f5d9bac083596f9b944197fe4ad008be6627475"
|
|
43
43
|
},
|
|
44
44
|
"context.d.ts": {
|
|
45
45
|
"size": 596,
|
|
@@ -70,16 +70,16 @@
|
|
|
70
70
|
"sha256": "4862b41e0477f01afa0dbb446d4553b65c22ed774cd1e2db3489059ced392f94"
|
|
71
71
|
},
|
|
72
72
|
"dashboard/ui.js": {
|
|
73
|
-
"size":
|
|
74
|
-
"sha256": "
|
|
73
|
+
"size": 82022,
|
|
74
|
+
"sha256": "e4bff41250c0251d33534b2c54412902aecf61051394b55a32b3673b42e5be48"
|
|
75
75
|
},
|
|
76
76
|
"index.d.ts": {
|
|
77
|
-
"size":
|
|
78
|
-
"sha256": "
|
|
77
|
+
"size": 2599,
|
|
78
|
+
"sha256": "5ee9fa0c65942078a1ac7f38afcdc6b86595842191c766190974733c6f8d86c6"
|
|
79
79
|
},
|
|
80
80
|
"index.js": {
|
|
81
81
|
"size": 3324,
|
|
82
|
-
"sha256": "
|
|
82
|
+
"sha256": "0ff435971e5fb1664cc95787db83a609997ecfee3b389275467e6a8944cf8c0c"
|
|
83
83
|
},
|
|
84
84
|
"migrations/20260331000001_create_zin_trace_entries_table.d.ts": {
|
|
85
85
|
"size": 304,
|
|
@@ -134,8 +134,8 @@
|
|
|
134
134
|
"sha256": "71d366165dd36f1675aa253a76262b226fb6c62e5ab632746b8aea61c0c625fc"
|
|
135
135
|
},
|
|
136
136
|
"register.js": {
|
|
137
|
-
"size":
|
|
138
|
-
"sha256": "
|
|
137
|
+
"size": 19110,
|
|
138
|
+
"sha256": "ae542cd406b32d0de8d3cee6decd2c85a601930b0329c23be56247f3eb456b62"
|
|
139
139
|
},
|
|
140
140
|
"storage/DebuggerStorage.d.ts": {
|
|
141
141
|
"size": 517,
|
|
@@ -146,12 +146,12 @@
|
|
|
146
146
|
"sha256": "5ecce0fcfcf695df587a7b90a7a5c7efd2e64ad13c9f2d104b392f89f34f0dc4"
|
|
147
147
|
},
|
|
148
148
|
"storage/TraceContentBudget.d.ts": {
|
|
149
|
-
"size":
|
|
150
|
-
"sha256": "
|
|
149
|
+
"size": 1306,
|
|
150
|
+
"sha256": "606a37af0a4aef4866c22cc727f67f485c43181b40eb831e1920b8b90fdaf503"
|
|
151
151
|
},
|
|
152
152
|
"storage/TraceContentBudget.js": {
|
|
153
|
-
"size":
|
|
154
|
-
"sha256": "
|
|
153
|
+
"size": 11412,
|
|
154
|
+
"sha256": "e5a72a6bb0c8bb432ea4aa7e8c5b43a8bf9e83d1b2935e102b4d1697da5fd18e"
|
|
155
155
|
},
|
|
156
156
|
"storage/TraceContentRedaction.d.ts": {
|
|
157
157
|
"size": 207,
|
|
@@ -166,8 +166,8 @@
|
|
|
166
166
|
"sha256": "a1158cedb4e4e749658127086e138e47886422366a697619d6ea9bd3338066e6"
|
|
167
167
|
},
|
|
168
168
|
"storage/TraceEntryFiltering.js": {
|
|
169
|
-
"size":
|
|
170
|
-
"sha256": "
|
|
169
|
+
"size": 2465,
|
|
170
|
+
"sha256": "ace7e492373d2dccdbefe20040d30fffd7ad9f8e71113b7a044bddf92dcdf6fb"
|
|
171
171
|
},
|
|
172
172
|
"storage/TraceStorage.d.ts": {
|
|
173
173
|
"size": 517,
|
|
@@ -194,8 +194,8 @@
|
|
|
194
194
|
"sha256": "d916e8e3abb1b1087f6b184851b0e6265e53380d7857b008e745d566aad15d44"
|
|
195
195
|
},
|
|
196
196
|
"types.d.ts": {
|
|
197
|
-
"size":
|
|
198
|
-
"sha256": "
|
|
197
|
+
"size": 9825,
|
|
198
|
+
"sha256": "53a1b2a572b9b5a73261f8c9b85903a3955bf71ec582f96c5b5249951aeb9b88"
|
|
199
199
|
},
|
|
200
200
|
"types.js": {
|
|
201
201
|
"size": 696,
|
|
@@ -242,12 +242,12 @@
|
|
|
242
242
|
"sha256": "4e82eaa3bb48f9d621b70f69519b0615d992068eb9f836beaf6df6c2382c2cff"
|
|
243
243
|
},
|
|
244
244
|
"utils/requestFilter.d.ts": {
|
|
245
|
-
"size":
|
|
246
|
-
"sha256": "
|
|
245
|
+
"size": 398,
|
|
246
|
+
"sha256": "fb214bde16e970c58ac23a32b51def87157a495a89e70ad6a1aa9e28c8c721c4"
|
|
247
247
|
},
|
|
248
248
|
"utils/requestFilter.js": {
|
|
249
|
-
"size":
|
|
250
|
-
"sha256": "
|
|
249
|
+
"size": 1947,
|
|
250
|
+
"sha256": "214855796b6dbe524a357355fb7c9c8fd0fa9705d9163f7ad0882f463e0ae5b1"
|
|
251
251
|
},
|
|
252
252
|
"utils/stackFrame.d.ts": {
|
|
253
253
|
"size": 149,
|
|
@@ -262,160 +262,160 @@
|
|
|
262
262
|
"sha256": "b062850fa3edd3d58bb293025b1dfc5491e39807b3ab3e4cc1c1aaa31316a7a3"
|
|
263
263
|
},
|
|
264
264
|
"watchers/AuthWatcher.js": {
|
|
265
|
-
"size":
|
|
266
|
-
"sha256": "
|
|
265
|
+
"size": 1437,
|
|
266
|
+
"sha256": "c47cca14113fed3825610c9a5a28a4ef7b99ea238952b3df48a997d63eab6fd2"
|
|
267
267
|
},
|
|
268
268
|
"watchers/BatchWatcher.d.ts": {
|
|
269
269
|
"size": 277,
|
|
270
270
|
"sha256": "b1870a793f2dc7ed22705c8a2a6b6f970fa1bcd0229dbf12f185323b35f3bdcf"
|
|
271
271
|
},
|
|
272
272
|
"watchers/BatchWatcher.js": {
|
|
273
|
-
"size":
|
|
274
|
-
"sha256": "
|
|
273
|
+
"size": 1338,
|
|
274
|
+
"sha256": "113a1077d267734335483cdc48bf94e929edb11f5a0f3f83234bd4e7da8bf6ef"
|
|
275
275
|
},
|
|
276
276
|
"watchers/CacheWatcher.d.ts": {
|
|
277
277
|
"size": 314,
|
|
278
278
|
"sha256": "19b5f6fe4f0fc8f3df6762f4f46d36f198c7c7d7da8d3d23e5c8f124462e8cf7"
|
|
279
279
|
},
|
|
280
280
|
"watchers/CacheWatcher.js": {
|
|
281
|
-
"size":
|
|
282
|
-
"sha256": "
|
|
281
|
+
"size": 2067,
|
|
282
|
+
"sha256": "8e038d3d72fcd69286674ec06b916389872eaa393dc7bfb8667b0979a68115a4"
|
|
283
283
|
},
|
|
284
284
|
"watchers/CommandWatcher.d.ts": {
|
|
285
285
|
"size": 267,
|
|
286
286
|
"sha256": "f1b3a3253e7265c7b56a74ba674cd23426ea5227a33abb1bde0d941e2a02e894"
|
|
287
287
|
},
|
|
288
288
|
"watchers/CommandWatcher.js": {
|
|
289
|
-
"size":
|
|
290
|
-
"sha256": "
|
|
289
|
+
"size": 1553,
|
|
290
|
+
"sha256": "b341c7a0ad2a1d8d6d21e5a14b8151d904194d292c8ef1f3a80cf8d507fc3f2a"
|
|
291
291
|
},
|
|
292
292
|
"watchers/DumpWatcher.d.ts": {
|
|
293
293
|
"size": 308,
|
|
294
294
|
"sha256": "13f81df217258b0827027cbba35b5ad549453fe2709bd4fcc66d845b065500ec"
|
|
295
295
|
},
|
|
296
296
|
"watchers/DumpWatcher.js": {
|
|
297
|
-
"size":
|
|
298
|
-
"sha256": "
|
|
297
|
+
"size": 1441,
|
|
298
|
+
"sha256": "36ea2e9a6c73dc96e75d31fd3c2710548ebfd0a651bab0dde185c33d611be079"
|
|
299
299
|
},
|
|
300
300
|
"watchers/EventWatcher.d.ts": {
|
|
301
301
|
"size": 223,
|
|
302
302
|
"sha256": "f5a173b0f92490e417d175011d4191d8eafe9ff75d712adb55cece5368753ef6"
|
|
303
303
|
},
|
|
304
304
|
"watchers/EventWatcher.js": {
|
|
305
|
-
"size":
|
|
306
|
-
"sha256": "
|
|
305
|
+
"size": 1299,
|
|
306
|
+
"sha256": "832d5db66433f685eea7a3da208fb226b62eb49c22f94619762962a04e58b122"
|
|
307
307
|
},
|
|
308
308
|
"watchers/ExceptionWatcher.d.ts": {
|
|
309
309
|
"size": 311,
|
|
310
310
|
"sha256": "0f58c50fd77704151399ca6cb6ec7890a9aef86afe28235951971f8cc9c1d600"
|
|
311
311
|
},
|
|
312
312
|
"watchers/ExceptionWatcher.js": {
|
|
313
|
-
"size":
|
|
314
|
-
"sha256": "
|
|
313
|
+
"size": 3816,
|
|
314
|
+
"sha256": "52d21188c499fa409fa50691fee3d27ea08ad93b26199d9a42c08e76217d6de2"
|
|
315
315
|
},
|
|
316
316
|
"watchers/GateWatcher.d.ts": {
|
|
317
317
|
"size": 262,
|
|
318
318
|
"sha256": "2fb8699f8679d2442aa322d40fb5cd4bb4e944804bdc6b094a9daf406a407abf"
|
|
319
319
|
},
|
|
320
320
|
"watchers/GateWatcher.js": {
|
|
321
|
-
"size":
|
|
322
|
-
"sha256": "
|
|
321
|
+
"size": 1330,
|
|
322
|
+
"sha256": "e3666b5d65ead0ccd3fe7a6d684d3245dda9d3ddd6da393e0afa028585f08679"
|
|
323
323
|
},
|
|
324
324
|
"watchers/HttpClientWatcher.d.ts": {
|
|
325
325
|
"size": 346,
|
|
326
326
|
"sha256": "dfb13bba526d5338e4dcd7a5aa0f72a61a03d9e2f6a250250c0bb8f0054c9712"
|
|
327
327
|
},
|
|
328
328
|
"watchers/HttpClientWatcher.js": {
|
|
329
|
-
"size":
|
|
330
|
-
"sha256": "
|
|
329
|
+
"size": 5898,
|
|
330
|
+
"sha256": "320b5a264f26bfeb29ba9246ffa65b79e244db715a4614d69a1425364062d5f9"
|
|
331
331
|
},
|
|
332
332
|
"watchers/HttpWatcher.d.ts": {
|
|
333
333
|
"size": 96,
|
|
334
334
|
"sha256": "ce9a95a670f755193fd74ce721dbfa4b30f20c879a6566ebb35229b3b2435429"
|
|
335
335
|
},
|
|
336
336
|
"watchers/HttpWatcher.js": {
|
|
337
|
-
"size":
|
|
338
|
-
"sha256": "
|
|
337
|
+
"size": 6152,
|
|
338
|
+
"sha256": "b5af31b46a9a8754f6032fde78fc46e9ad7221977a0bfbbaa26e13214951ea0f"
|
|
339
339
|
},
|
|
340
340
|
"watchers/JobWatcher.d.ts": {
|
|
341
341
|
"size": 441,
|
|
342
342
|
"sha256": "097c043678ac6b218096c9b04bc5922fc8ed2a31e9f53abc36f6e0d6f63180f0"
|
|
343
343
|
},
|
|
344
344
|
"watchers/JobWatcher.js": {
|
|
345
|
-
"size":
|
|
346
|
-
"sha256": "
|
|
345
|
+
"size": 3317,
|
|
346
|
+
"sha256": "494646d87c71d1fbf069835fcf10c56dec7b449e2fc1b24e0c82d511aba085e4"
|
|
347
347
|
},
|
|
348
348
|
"watchers/LogWatcher.d.ts": {
|
|
349
349
|
"size": 95,
|
|
350
350
|
"sha256": "f3ddc5f8b58c6c86ac6b464dd48e5a55e79ab2bf2e735feacffc7480e4ccc0c4"
|
|
351
351
|
},
|
|
352
352
|
"watchers/LogWatcher.js": {
|
|
353
|
-
"size":
|
|
354
|
-
"sha256": "
|
|
353
|
+
"size": 3146,
|
|
354
|
+
"sha256": "aa8a8e7d324a217911640d4616fc9c41f07cb1c3f4ad130a8a05b6c213516fba"
|
|
355
355
|
},
|
|
356
356
|
"watchers/MailWatcher.d.ts": {
|
|
357
357
|
"size": 244,
|
|
358
358
|
"sha256": "5031b96ef8e64a6d376576e8cddf1c2560f22432a78f1d2be55f7cea6bff4547"
|
|
359
359
|
},
|
|
360
360
|
"watchers/MailWatcher.js": {
|
|
361
|
-
"size":
|
|
362
|
-
"sha256": "
|
|
361
|
+
"size": 1766,
|
|
362
|
+
"sha256": "2b583137bb9800901a7ae70cc1af6e9f8763215f0f05f170af9cfb4556530780"
|
|
363
363
|
},
|
|
364
364
|
"watchers/MiddlewareWatcher.d.ts": {
|
|
365
365
|
"size": 259,
|
|
366
366
|
"sha256": "5a28b472c835bd0f79ec9d3670516544bc5b6da9f1f1bed5159be0cba39304a1"
|
|
367
367
|
},
|
|
368
368
|
"watchers/MiddlewareWatcher.js": {
|
|
369
|
-
"size":
|
|
370
|
-
"sha256": "
|
|
369
|
+
"size": 1510,
|
|
370
|
+
"sha256": "4ed2a81d8f7b7984f572d1bea16abd7a40a896de789e668def961e32bb8eea7f"
|
|
371
371
|
},
|
|
372
372
|
"watchers/ModelWatcher.d.ts": {
|
|
373
373
|
"size": 285,
|
|
374
374
|
"sha256": "4c05112af855a92b3f3f97c6b61bf1b07444bcb7d5a17f3e0ae19da4a85faf1c"
|
|
375
375
|
},
|
|
376
376
|
"watchers/ModelWatcher.js": {
|
|
377
|
-
"size":
|
|
378
|
-
"sha256": "
|
|
377
|
+
"size": 1492,
|
|
378
|
+
"sha256": "ae4151b422eb73500f981c799e5a261d7349ad36b4be060a56e5ad7944e85cae"
|
|
379
379
|
},
|
|
380
380
|
"watchers/NotificationWatcher.d.ts": {
|
|
381
381
|
"size": 274,
|
|
382
382
|
"sha256": "a1d918122c5db9a7f27fdf78c0c14a61f6e1213748ee6f9b06f976f33589dc33"
|
|
383
383
|
},
|
|
384
384
|
"watchers/NotificationWatcher.js": {
|
|
385
|
-
"size":
|
|
386
|
-
"sha256": "
|
|
385
|
+
"size": 1808,
|
|
386
|
+
"sha256": "06bbc437a9e5ec29252e365fa4707e68ae9348b3f755094c14f0e18c99dad3ed"
|
|
387
387
|
},
|
|
388
388
|
"watchers/QueryWatcher.d.ts": {
|
|
389
389
|
"size": 240,
|
|
390
390
|
"sha256": "5d5046c65e5b683369c7709f1acd09b60aec3e7f44748fd1baeb35498836465b"
|
|
391
391
|
},
|
|
392
392
|
"watchers/QueryWatcher.js": {
|
|
393
|
-
"size":
|
|
394
|
-
"sha256": "
|
|
393
|
+
"size": 3023,
|
|
394
|
+
"sha256": "edede157915aa7832d602c92f4c2220daaf1d799210eae931b1638da883742ca"
|
|
395
395
|
},
|
|
396
396
|
"watchers/RedisWatcher.d.ts": {
|
|
397
397
|
"size": 294,
|
|
398
398
|
"sha256": "0a0f0ef387cb02a20cb9a4308a87b48dbfbf1076b7e3090801fef7c9c794ec84"
|
|
399
399
|
},
|
|
400
400
|
"watchers/RedisWatcher.js": {
|
|
401
|
-
"size":
|
|
402
|
-
"sha256": "
|
|
401
|
+
"size": 1349,
|
|
402
|
+
"sha256": "bcafbadbbc6caa85284a384efa8894895c077588ebb5fb45f0f966d869caf960"
|
|
403
403
|
},
|
|
404
404
|
"watchers/ScheduleWatcher.d.ts": {
|
|
405
405
|
"size": 291,
|
|
406
406
|
"sha256": "1d049cfc2472876bf11c4d091c2a889b948bfb2ac714da2aed8affd965f311a6"
|
|
407
407
|
},
|
|
408
408
|
"watchers/ScheduleWatcher.js": {
|
|
409
|
-
"size":
|
|
410
|
-
"sha256": "
|
|
409
|
+
"size": 1393,
|
|
410
|
+
"sha256": "f653c3728d928b253b7f4fd4e1afd228bedf4ce32c52f107effa99aa026ada45"
|
|
411
411
|
},
|
|
412
412
|
"watchers/ViewWatcher.d.ts": {
|
|
413
413
|
"size": 202,
|
|
414
414
|
"sha256": "980ac30b405d135cd754de1462722147944a37b4f5271ce769afb6b71fa748b1"
|
|
415
415
|
},
|
|
416
416
|
"watchers/ViewWatcher.js": {
|
|
417
|
-
"size":
|
|
418
|
-
"sha256": "
|
|
417
|
+
"size": 1180,
|
|
418
|
+
"sha256": "9af344802c5973a020487e261009e8d1a19a74b78ba7b388d33ce50687277c81"
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
421
|
}
|
package/dist/register.js
CHANGED
|
@@ -117,11 +117,15 @@ const parseEnvBool = (rawValue) => {
|
|
|
117
117
|
return false;
|
|
118
118
|
return undefined;
|
|
119
119
|
};
|
|
120
|
-
const resolveTraceStartupOverrides = (core) => {
|
|
120
|
+
const resolveTraceStartupOverrides = async (core) => {
|
|
121
121
|
const traceConfigFile = core.StartupConfigFile?.Trace;
|
|
122
122
|
if (typeof traceConfigFile !== 'string' || traceConfigFile.trim() === '')
|
|
123
123
|
return undefined;
|
|
124
|
-
const
|
|
124
|
+
const registry = core.StartupConfigFileRegistry;
|
|
125
|
+
if (registry?.has?.(traceConfigFile) !== true && typeof registry?.preload === 'function') {
|
|
126
|
+
await registry.preload([traceConfigFile]);
|
|
127
|
+
}
|
|
128
|
+
const overrides = registry?.get(traceConfigFile);
|
|
125
129
|
return isObjectValue(overrides) ? overrides : undefined;
|
|
126
130
|
};
|
|
127
131
|
const buildTraceRedactionOverrides = (input) => {
|
|
@@ -195,7 +199,7 @@ const assertTraceStorageReady = async (coreApi, db, connectionName) => {
|
|
|
195
199
|
};
|
|
196
200
|
const core = (await importCore());
|
|
197
201
|
const Env = core.Env;
|
|
198
|
-
const startupOverrides = resolveTraceStartupOverrides(core);
|
|
202
|
+
const startupOverrides = await resolveTraceStartupOverrides(core);
|
|
199
203
|
if (!traceAlreadyInitialized && Env) {
|
|
200
204
|
const enabled = startupOverrides?.enabled === true || Env.getBool('TRACE_ENABLED', false);
|
|
201
205
|
if (enabled) {
|
|
@@ -1,9 +1,64 @@
|
|
|
1
|
+
import { TraceContext } from '../context.js';
|
|
2
|
+
import { EntryType } from '../types.js';
|
|
1
3
|
import { TraceEntryFilter } from '../utils/entryFilter.js';
|
|
4
|
+
import { RequestFilter } from '../utils/requestFilter.js';
|
|
5
|
+
const MAX_IGNORED_BATCHES = 512;
|
|
6
|
+
const isObjectValue = (value) => {
|
|
7
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
8
|
+
};
|
|
9
|
+
const getEntryUri = (entry) => {
|
|
10
|
+
if (entry.type !== EntryType.REQUEST)
|
|
11
|
+
return undefined;
|
|
12
|
+
const content = isObjectValue(entry.content) ? entry.content : undefined;
|
|
13
|
+
const uri = content?.['uri'];
|
|
14
|
+
return typeof uri === 'string' && uri.trim() !== '' ? uri : undefined;
|
|
15
|
+
};
|
|
16
|
+
const createIgnoredBatchTracker = () => {
|
|
17
|
+
const ignoredBatchIds = new Set();
|
|
18
|
+
const ignoredBatchOrder = [];
|
|
19
|
+
const remember = (batchId) => {
|
|
20
|
+
if (ignoredBatchIds.has(batchId))
|
|
21
|
+
return;
|
|
22
|
+
ignoredBatchIds.add(batchId);
|
|
23
|
+
ignoredBatchOrder.push(batchId);
|
|
24
|
+
if (ignoredBatchOrder.length <= MAX_IGNORED_BATCHES)
|
|
25
|
+
return;
|
|
26
|
+
const evictedBatchId = ignoredBatchOrder.shift();
|
|
27
|
+
if (evictedBatchId !== undefined) {
|
|
28
|
+
ignoredBatchIds.delete(evictedBatchId);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const has = (batchId) => {
|
|
32
|
+
return ignoredBatchIds.has(batchId);
|
|
33
|
+
};
|
|
34
|
+
return Object.freeze({ has, remember });
|
|
35
|
+
};
|
|
36
|
+
const shouldDropForIgnoredRequest = (entry, config, tracker) => {
|
|
37
|
+
if (tracker.has(entry.batchId)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
const currentPath = TraceContext.getRequestPath();
|
|
41
|
+
if (typeof currentPath === 'string' &&
|
|
42
|
+
currentPath !== '' &&
|
|
43
|
+
RequestFilter.matchesIgnoredPath(currentPath, config)) {
|
|
44
|
+
tracker.remember(entry.batchId);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
const uri = getEntryUri(entry);
|
|
48
|
+
if (typeof uri === 'string' && RequestFilter.matchesIgnoredPath(uri, config)) {
|
|
49
|
+
tracker.remember(entry.batchId);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
};
|
|
2
54
|
export const TraceEntryFiltering = Object.freeze({
|
|
3
55
|
wrapStorage(storage, config) {
|
|
56
|
+
const ignoredBatchTracker = createIgnoredBatchTracker();
|
|
4
57
|
return Object.freeze({
|
|
5
58
|
...storage,
|
|
6
59
|
async writeEntry(entry) {
|
|
60
|
+
if (shouldDropForIgnoredRequest(entry, config, ignoredBatchTracker))
|
|
61
|
+
return;
|
|
7
62
|
if (!TraceEntryFilter.shouldCapture(entry, config))
|
|
8
63
|
return;
|
|
9
64
|
await storage.writeEntry(entry);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/trace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Trace assistant for ZinTrust: logs requests, queries, exceptions, jobs, and more.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"node": ">=20.0.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@zintrust/core": "^0.
|
|
43
|
+
"@zintrust/core": "^0.7.0"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
@@ -56,4 +56,4 @@
|
|
|
56
56
|
"build": "tsc -p tsconfig.json && tsc -p tsconfig.migrations.json && node ../../scripts/fix-dist-esm-imports.mjs dist",
|
|
57
57
|
"prepublishOnly": "npm run build"
|
|
58
58
|
}
|
|
59
|
-
}
|
|
59
|
+
}
|
package/src/register.ts
CHANGED
|
@@ -72,7 +72,9 @@ type CoreApi = {
|
|
|
72
72
|
Trace?: string;
|
|
73
73
|
};
|
|
74
74
|
StartupConfigFileRegistry?: {
|
|
75
|
+
preload?(files: readonly string[]): Promise<void>;
|
|
75
76
|
get<T>(file: string): T | undefined;
|
|
77
|
+
has?(file: string): boolean;
|
|
76
78
|
};
|
|
77
79
|
};
|
|
78
80
|
|
|
@@ -181,11 +183,18 @@ const parseEnvBool = (rawValue: string): boolean | undefined => {
|
|
|
181
183
|
return undefined;
|
|
182
184
|
};
|
|
183
185
|
|
|
184
|
-
const resolveTraceStartupOverrides = (
|
|
186
|
+
const resolveTraceStartupOverrides = async (
|
|
187
|
+
core: CoreApi
|
|
188
|
+
): Promise<TraceConfigOverrides | undefined> => {
|
|
185
189
|
const traceConfigFile = core.StartupConfigFile?.Trace;
|
|
186
190
|
if (typeof traceConfigFile !== 'string' || traceConfigFile.trim() === '') return undefined;
|
|
187
191
|
|
|
188
|
-
const
|
|
192
|
+
const registry = core.StartupConfigFileRegistry;
|
|
193
|
+
if (registry?.has?.(traceConfigFile) !== true && typeof registry?.preload === 'function') {
|
|
194
|
+
await registry.preload([traceConfigFile]);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const overrides = registry?.get<unknown>(traceConfigFile);
|
|
189
198
|
return isObjectValue(overrides) ? (overrides as TraceConfigOverrides) : undefined;
|
|
190
199
|
};
|
|
191
200
|
|
|
@@ -296,7 +305,7 @@ const assertTraceStorageReady = async (
|
|
|
296
305
|
|
|
297
306
|
const core = (await importCore()) as CoreApi;
|
|
298
307
|
const Env = core.Env;
|
|
299
|
-
const startupOverrides = resolveTraceStartupOverrides(core);
|
|
308
|
+
const startupOverrides = await resolveTraceStartupOverrides(core);
|
|
300
309
|
|
|
301
310
|
if (!traceAlreadyInitialized && Env) {
|
|
302
311
|
const enabled = startupOverrides?.enabled === true || Env.getBool('TRACE_ENABLED', false);
|
|
@@ -1,11 +1,89 @@
|
|
|
1
|
+
import { TraceContext } from '../context';
|
|
1
2
|
import type { ITraceConfig, ITraceEntry, ITraceStorage } from '../types';
|
|
3
|
+
import { EntryType } from '../types';
|
|
2
4
|
import { TraceEntryFilter } from '../utils/entryFilter';
|
|
5
|
+
import { RequestFilter } from '../utils/requestFilter';
|
|
6
|
+
|
|
7
|
+
const MAX_IGNORED_BATCHES = 512;
|
|
8
|
+
|
|
9
|
+
interface IIgnoredBatchTracker {
|
|
10
|
+
has(batchId: string): boolean;
|
|
11
|
+
remember(batchId: string): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const isObjectValue = (value: unknown): value is Record<string, unknown> => {
|
|
15
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const getEntryUri = (entry: ITraceEntry): string | undefined => {
|
|
19
|
+
if (entry.type !== EntryType.REQUEST) return undefined;
|
|
20
|
+
|
|
21
|
+
const content = isObjectValue(entry.content) ? entry.content : undefined;
|
|
22
|
+
const uri = content?.['uri'];
|
|
23
|
+
return typeof uri === 'string' && uri.trim() !== '' ? uri : undefined;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const createIgnoredBatchTracker = (): IIgnoredBatchTracker => {
|
|
27
|
+
const ignoredBatchIds = new Set<string>();
|
|
28
|
+
const ignoredBatchOrder: string[] = [];
|
|
29
|
+
|
|
30
|
+
const remember = (batchId: string): void => {
|
|
31
|
+
if (ignoredBatchIds.has(batchId)) return;
|
|
32
|
+
|
|
33
|
+
ignoredBatchIds.add(batchId);
|
|
34
|
+
ignoredBatchOrder.push(batchId);
|
|
35
|
+
|
|
36
|
+
if (ignoredBatchOrder.length <= MAX_IGNORED_BATCHES) return;
|
|
37
|
+
|
|
38
|
+
const evictedBatchId = ignoredBatchOrder.shift();
|
|
39
|
+
if (evictedBatchId !== undefined) {
|
|
40
|
+
ignoredBatchIds.delete(evictedBatchId);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const has = (batchId: string): boolean => {
|
|
45
|
+
return ignoredBatchIds.has(batchId);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return Object.freeze({ has, remember });
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const shouldDropForIgnoredRequest = (
|
|
52
|
+
entry: ITraceEntry,
|
|
53
|
+
config: ITraceConfig,
|
|
54
|
+
tracker: IIgnoredBatchTracker
|
|
55
|
+
): boolean => {
|
|
56
|
+
if (tracker.has(entry.batchId)) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const currentPath = TraceContext.getRequestPath();
|
|
61
|
+
if (
|
|
62
|
+
typeof currentPath === 'string' &&
|
|
63
|
+
currentPath !== '' &&
|
|
64
|
+
RequestFilter.matchesIgnoredPath(currentPath, config)
|
|
65
|
+
) {
|
|
66
|
+
tracker.remember(entry.batchId);
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const uri = getEntryUri(entry);
|
|
71
|
+
if (typeof uri === 'string' && RequestFilter.matchesIgnoredPath(uri, config)) {
|
|
72
|
+
tracker.remember(entry.batchId);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return false;
|
|
77
|
+
};
|
|
3
78
|
|
|
4
79
|
export const TraceEntryFiltering = Object.freeze({
|
|
5
80
|
wrapStorage(storage: ITraceStorage, config: ITraceConfig): ITraceStorage {
|
|
81
|
+
const ignoredBatchTracker = createIgnoredBatchTracker();
|
|
82
|
+
|
|
6
83
|
return Object.freeze({
|
|
7
84
|
...storage,
|
|
8
|
-
async writeEntry(entry: ITraceEntry) {
|
|
85
|
+
async writeEntry(entry: ITraceEntry): Promise<void> {
|
|
86
|
+
if (shouldDropForIgnoredRequest(entry, config, ignoredBatchTracker)) return;
|
|
9
87
|
if (!TraceEntryFilter.shouldCapture(entry, config)) return;
|
|
10
88
|
await storage.writeEntry(entry);
|
|
11
89
|
},
|