@zintrust/trace 0.5.2 → 0.5.5
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/README.md +55 -13
- package/dist/config.js +25 -0
- package/dist/index.d.ts +1 -1
- package/dist/register.js +67 -1
- package/dist/storage/TraceContentBudget.d.ts +37 -2
- package/dist/storage/TraceContentBudget.js +222 -65
- package/dist/types.d.ts +13 -0
- package/package.json +3 -3
- package/src/config.ts +32 -0
- package/src/index.ts +2 -0
- package/src/register.ts +94 -1
- package/src/storage/TraceContentBudget.ts +360 -96
- package/src/types.ts +15 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/trace",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
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.5.
|
|
43
|
+
"@zintrust/core": "^0.5.2"
|
|
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/config.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
TraceClientRequestCaptureRule,
|
|
7
7
|
TraceClientRequestWatcherToggle,
|
|
8
8
|
TraceConfigOverrides,
|
|
9
|
+
TraceContentDispatchConfig,
|
|
9
10
|
TraceFilterRule,
|
|
10
11
|
TraceRequestWatcherConfig,
|
|
11
12
|
TraceWatcherToggle,
|
|
@@ -233,6 +234,25 @@ const mergeWatchers = (
|
|
|
233
234
|
};
|
|
234
235
|
};
|
|
235
236
|
|
|
237
|
+
const mergeContentDispatch = (
|
|
238
|
+
base: TraceContentDispatchConfig,
|
|
239
|
+
override?: TraceConfigOverrides['contentDispatch']
|
|
240
|
+
): TraceContentDispatchConfig => {
|
|
241
|
+
const workerOverride = override?.worker;
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
...base,
|
|
245
|
+
...override,
|
|
246
|
+
worker:
|
|
247
|
+
workerOverride === undefined
|
|
248
|
+
? base.worker
|
|
249
|
+
: {
|
|
250
|
+
...base.worker,
|
|
251
|
+
...workerOverride,
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
|
|
236
256
|
const DEFAULTS: ITraceConfig = Object.freeze({
|
|
237
257
|
enabled: false,
|
|
238
258
|
connection: undefined,
|
|
@@ -243,6 +263,17 @@ const DEFAULTS: ITraceConfig = Object.freeze({
|
|
|
243
263
|
captureCachePayloads: false,
|
|
244
264
|
captureQueryBindings: true,
|
|
245
265
|
logMinLevel: 'info',
|
|
266
|
+
contentDispatch: {
|
|
267
|
+
driver: undefined,
|
|
268
|
+
queueName: 'trace-content',
|
|
269
|
+
enqueueTimeoutMs: 25,
|
|
270
|
+
worker: {
|
|
271
|
+
enabled: true,
|
|
272
|
+
intervalMs: 1000,
|
|
273
|
+
maxDurationMs: 250,
|
|
274
|
+
concurrency: 1,
|
|
275
|
+
},
|
|
276
|
+
},
|
|
246
277
|
watchers: {},
|
|
247
278
|
redaction: {
|
|
248
279
|
keys: [
|
|
@@ -310,6 +341,7 @@ export const TraceConfig = Object.freeze({
|
|
|
310
341
|
return Object.freeze({
|
|
311
342
|
...DEFAULTS,
|
|
312
343
|
...overrides,
|
|
344
|
+
contentDispatch: mergeContentDispatch(DEFAULTS.contentDispatch, overrides.contentDispatch),
|
|
313
345
|
watchers: mergeWatchers(DEFAULTS.watchers, overrides.watchers),
|
|
314
346
|
redaction: {
|
|
315
347
|
keys: mergeStringLists(DEFAULTS.redaction.keys, overrides.redaction?.keys),
|
package/src/index.ts
CHANGED
package/src/register.ts
CHANGED
|
@@ -309,6 +309,28 @@ if (!traceAlreadyInitialized && Env) {
|
|
|
309
309
|
const logMinLevelRaw = Env.get('TRACE_LOG_LEVEL', '').trim();
|
|
310
310
|
const captureCachePayloadsRaw = Env.get('TRACE_CACHE_PAYLOADS', '').trim();
|
|
311
311
|
const captureQueryBindingsRaw = Env.get('TRACE_QUERY_BINDINGS', '').trim();
|
|
312
|
+
const contentDispatchDriverRaw = Env.get('TRACE_CONTENT_QUEUE_DRIVER', '').trim();
|
|
313
|
+
const contentDispatchQueueRaw = Env.get('TRACE_CONTENT_QUEUE_NAME', '').trim();
|
|
314
|
+
const contentDispatchEnqueueTimeoutRaw = Env.get(
|
|
315
|
+
'TRACE_CONTENT_QUEUE_ENQUEUE_TIMEOUT_MS',
|
|
316
|
+
''
|
|
317
|
+
).trim();
|
|
318
|
+
const contentDispatchWorkerEnabledRaw = Env.get(
|
|
319
|
+
'TRACE_CONTENT_QUEUE_WORKER_ENABLED',
|
|
320
|
+
''
|
|
321
|
+
).trim();
|
|
322
|
+
const contentDispatchWorkerIntervalRaw = Env.get(
|
|
323
|
+
'TRACE_CONTENT_QUEUE_WORKER_INTERVAL_MS',
|
|
324
|
+
''
|
|
325
|
+
).trim();
|
|
326
|
+
const contentDispatchWorkerDurationRaw = Env.get(
|
|
327
|
+
'TRACE_CONTENT_QUEUE_WORKER_MAX_DURATION_MS',
|
|
328
|
+
''
|
|
329
|
+
).trim();
|
|
330
|
+
const contentDispatchWorkerConcurrencyRaw = Env.get(
|
|
331
|
+
'TRACE_CONTENT_QUEUE_WORKER_CONCURRENCY',
|
|
332
|
+
''
|
|
333
|
+
).trim();
|
|
312
334
|
const redactionKeys = parseEnvList(Env.get('TRACE_REDACT_KEYS', ''));
|
|
313
335
|
const redactionHeaders = parseEnvList(Env.get('TRACE_REDACT_HEADERS', ''));
|
|
314
336
|
const redactionBody = parseEnvList(Env.get('TRACE_REDACT_BODY', ''));
|
|
@@ -335,6 +357,33 @@ if (!traceAlreadyInitialized && Env) {
|
|
|
335
357
|
parseEnvBool(captureCachePayloadsRaw) ?? startupOverrides?.captureCachePayloads;
|
|
336
358
|
const captureQueryBindings =
|
|
337
359
|
parseEnvBool(captureQueryBindingsRaw) ?? startupOverrides?.captureQueryBindings;
|
|
360
|
+
const contentDispatchDriver =
|
|
361
|
+
contentDispatchDriverRaw === ''
|
|
362
|
+
? startupOverrides?.contentDispatch?.driver
|
|
363
|
+
: contentDispatchDriverRaw;
|
|
364
|
+
const contentDispatchQueueName =
|
|
365
|
+
contentDispatchQueueRaw === ''
|
|
366
|
+
? startupOverrides?.contentDispatch?.queueName
|
|
367
|
+
: contentDispatchQueueRaw;
|
|
368
|
+
const contentDispatchEnqueueTimeout =
|
|
369
|
+
contentDispatchEnqueueTimeoutRaw === ''
|
|
370
|
+
? startupOverrides?.contentDispatch?.enqueueTimeoutMs
|
|
371
|
+
: Number.parseInt(contentDispatchEnqueueTimeoutRaw, 10);
|
|
372
|
+
const contentDispatchWorkerEnabled =
|
|
373
|
+
parseEnvBool(contentDispatchWorkerEnabledRaw) ??
|
|
374
|
+
startupOverrides?.contentDispatch?.worker?.enabled;
|
|
375
|
+
const contentDispatchWorkerInterval =
|
|
376
|
+
contentDispatchWorkerIntervalRaw === ''
|
|
377
|
+
? startupOverrides?.contentDispatch?.worker?.intervalMs
|
|
378
|
+
: Number.parseInt(contentDispatchWorkerIntervalRaw, 10);
|
|
379
|
+
const contentDispatchWorkerDuration =
|
|
380
|
+
contentDispatchWorkerDurationRaw === ''
|
|
381
|
+
? startupOverrides?.contentDispatch?.worker?.maxDurationMs
|
|
382
|
+
: Number.parseInt(contentDispatchWorkerDurationRaw, 10);
|
|
383
|
+
const contentDispatchWorkerConcurrency =
|
|
384
|
+
contentDispatchWorkerConcurrencyRaw === ''
|
|
385
|
+
? startupOverrides?.contentDispatch?.worker?.concurrency
|
|
386
|
+
: Number.parseInt(contentDispatchWorkerConcurrencyRaw, 10);
|
|
338
387
|
const redaction = buildTraceRedactionOverrides({
|
|
339
388
|
startupOverrides,
|
|
340
389
|
redactionBody,
|
|
@@ -342,6 +391,9 @@ if (!traceAlreadyInitialized && Env) {
|
|
|
342
391
|
redactionKeys,
|
|
343
392
|
redactionQuery,
|
|
344
393
|
});
|
|
394
|
+
const defaultContentDispatch = TraceConfig.defaults().contentDispatch;
|
|
395
|
+
const startupContentDispatch = startupOverrides?.contentDispatch;
|
|
396
|
+
const startupContentDispatchWorker = startupContentDispatch?.worker;
|
|
345
397
|
|
|
346
398
|
const config = TraceConfig.merge({
|
|
347
399
|
...startupOverrides,
|
|
@@ -356,6 +408,46 @@ if (!traceAlreadyInitialized && Env) {
|
|
|
356
408
|
: {}),
|
|
357
409
|
...(typeof captureCachePayloads === 'boolean' ? { captureCachePayloads } : {}),
|
|
358
410
|
...(typeof captureQueryBindings === 'boolean' ? { captureQueryBindings } : {}),
|
|
411
|
+
contentDispatch: {
|
|
412
|
+
...defaultContentDispatch,
|
|
413
|
+
...startupContentDispatch,
|
|
414
|
+
...(typeof contentDispatchDriver === 'string' && contentDispatchDriver !== ''
|
|
415
|
+
? { driver: contentDispatchDriver }
|
|
416
|
+
: {}),
|
|
417
|
+
...(typeof contentDispatchQueueName === 'string' && contentDispatchQueueName !== ''
|
|
418
|
+
? { queueName: contentDispatchQueueName }
|
|
419
|
+
: {}),
|
|
420
|
+
...(typeof contentDispatchEnqueueTimeout === 'number' &&
|
|
421
|
+
Number.isFinite(contentDispatchEnqueueTimeout)
|
|
422
|
+
? { enqueueTimeoutMs: contentDispatchEnqueueTimeout }
|
|
423
|
+
: {}),
|
|
424
|
+
worker: {
|
|
425
|
+
...defaultContentDispatch.worker,
|
|
426
|
+
...startupContentDispatchWorker,
|
|
427
|
+
enabled:
|
|
428
|
+
typeof contentDispatchWorkerEnabled === 'boolean'
|
|
429
|
+
? contentDispatchWorkerEnabled
|
|
430
|
+
: (startupContentDispatchWorker?.enabled ?? defaultContentDispatch.worker.enabled),
|
|
431
|
+
intervalMs:
|
|
432
|
+
typeof contentDispatchWorkerInterval === 'number' &&
|
|
433
|
+
Number.isFinite(contentDispatchWorkerInterval)
|
|
434
|
+
? contentDispatchWorkerInterval
|
|
435
|
+
: (startupContentDispatchWorker?.intervalMs ??
|
|
436
|
+
defaultContentDispatch.worker.intervalMs),
|
|
437
|
+
maxDurationMs:
|
|
438
|
+
typeof contentDispatchWorkerDuration === 'number' &&
|
|
439
|
+
Number.isFinite(contentDispatchWorkerDuration)
|
|
440
|
+
? contentDispatchWorkerDuration
|
|
441
|
+
: (startupContentDispatchWorker?.maxDurationMs ??
|
|
442
|
+
defaultContentDispatch.worker.maxDurationMs),
|
|
443
|
+
concurrency:
|
|
444
|
+
typeof contentDispatchWorkerConcurrency === 'number' &&
|
|
445
|
+
Number.isFinite(contentDispatchWorkerConcurrency)
|
|
446
|
+
? contentDispatchWorkerConcurrency
|
|
447
|
+
: (startupContentDispatchWorker?.concurrency ??
|
|
448
|
+
defaultContentDispatch.worker.concurrency),
|
|
449
|
+
},
|
|
450
|
+
},
|
|
359
451
|
logMinLevel,
|
|
360
452
|
...(redaction === undefined ? {} : { redaction }),
|
|
361
453
|
});
|
|
@@ -384,7 +476,8 @@ if (!traceAlreadyInitialized && Env) {
|
|
|
384
476
|
TraceContentRedaction.wrapStorage(
|
|
385
477
|
TraceEntryFiltering.wrapStorage(TraceStorage.resolveStorage(storageDb), config),
|
|
386
478
|
config.redaction
|
|
387
|
-
)
|
|
479
|
+
),
|
|
480
|
+
config
|
|
388
481
|
),
|
|
389
482
|
{
|
|
390
483
|
connectionName: resolvedConnectionName,
|