@zintrust/trace 1.5.2 → 1.6.1

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.
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@zintrust/trace",
3
- "version": "1.5.2",
4
- "buildDate": "2026-04-25T12:38:43.860Z",
3
+ "version": "1.5.1",
4
+ "buildDate": "2026-04-28T16:08:58.961Z",
5
5
  "buildEnvironment": {
6
- "node": "v20.20.2",
7
- "platform": "linux",
8
- "arch": "x64"
6
+ "node": "v22.22.1",
7
+ "platform": "darwin",
8
+ "arch": "arm64"
9
9
  },
10
10
  "git": {
11
- "commit": "616b0d5d",
12
- "branch": "master"
11
+ "commit": "6c6a3f59",
12
+ "branch": "release"
13
13
  },
14
14
  "package": {
15
15
  "engines": {
@@ -29,6 +29,10 @@
29
29
  "size": 4640,
30
30
  "sha256": "c51cc312046b6b2bbe1673f1ff9508425cc7140a1d2341907f67aa36069c09f9"
31
31
  },
32
+ "build-manifest.json": {
33
+ "size": 15912,
34
+ "sha256": "b7ce0234e13707d03336dbad905b5c1403a910880469504ec6cde78ad67fe9a9"
35
+ },
32
36
  "cli-register.d.ts": {
33
37
  "size": 255,
34
38
  "sha256": "da8d689fe5ef32e97e755f28017e4d3cb1aa63489073a71907ea41ad5761ede9"
@@ -83,7 +87,7 @@
83
87
  },
84
88
  "index.js": {
85
89
  "size": 3421,
86
- "sha256": "199bd3c4a0618b7b336e3b866169656a0b49c8f527b083be87d44fe092518ad6"
90
+ "sha256": "6cab0d02424c088c23dce13c349f177993fd55f21864eea1842c2276a81ad526"
87
91
  },
88
92
  "ingest/TraceIngestGateway.d.ts": {
89
93
  "size": 786,
@@ -142,12 +146,20 @@
142
146
  "sha256": "2d05bec517f57634276220b8a946125059fe0e320c42295b4f5a985431bb3d1c"
143
147
  },
144
148
  "register.d.ts": {
145
- "size": 16,
146
- "sha256": "71d366165dd36f1675aa253a76262b226fb6c62e5ab632746b8aea61c0c625fc"
149
+ "size": 72,
150
+ "sha256": "535869aa1bfcdf0ec26fad27d7f18bb8822bc586c38fcc5ffdde5274ecbea17e"
147
151
  },
148
152
  "register.js": {
149
- "size": 19822,
150
- "sha256": "c553356d90c812f7de430d5679b1d44468131433e034ae2ea89e2876b1254444"
153
+ "size": 20927,
154
+ "sha256": "026fd79a98596d2be108b350668f4345b11020953f24369866c0aad42cd7ba0f"
155
+ },
156
+ "storage/DebuggerStorage.d.ts": {
157
+ "size": 517,
158
+ "sha256": "c9c215aaa414f7b0c1fec6c82b054fc52bdf97af58f96f35c7f96672fb859c31"
159
+ },
160
+ "storage/DebuggerStorage.js": {
161
+ "size": 7442,
162
+ "sha256": "5ecce0fcfcf695df587a7b90a7a5c7efd2e64ad13c9f2d104b392f89f34f0dc4"
151
163
  },
152
164
  "storage/ProxyTraceStorage.d.ts": {
153
165
  "size": 339,
@@ -1 +1,2 @@
1
1
  export type {};
2
+ export declare const registerTraceReady: Promise<void>;
package/dist/register.js CHANGED
@@ -131,249 +131,258 @@ const buildTraceRedactionOverrides = (input) => {
131
131
  ? redaction
132
132
  : undefined;
133
133
  };
134
- const core = (await importCore());
135
- const Env = core.Env;
136
- const startupOverrides = await resolveTraceStartupOverrides(core);
137
- if (!traceAlreadyInitialized && Env) {
134
+ const readTraceEnvValues = (Env) => {
135
+ return {
136
+ connectionRaw: Env.get('TRACE_DB_CONNECTION', '').trim(),
137
+ observeConnectionRaw: Env.get('TRACE_QUERY_CONNECTION', '').trim(),
138
+ pruneAfterHoursRaw: Env.get('TRACE_PRUNE_HOURS', '').trim(),
139
+ slowQueryThresholdRaw: Env.get('TRACE_SLOW_QUERY_MS', '').trim(),
140
+ logMinLevelRaw: Env.get('TRACE_LOG_LEVEL', '').trim(),
141
+ traceProxyRaw: Env.get('TRACE_PROXY', '').trim(),
142
+ traceProxyUrlRaw: Env.get('TRACE_PROXY_URL', '').trim(),
143
+ traceProxyPathRaw: Env.get('TRACE_PROXY_PATH', '').trim(),
144
+ traceProxyKeyIdRaw: Env.get('TRACE_PROXY_KEY_ID', '').trim(),
145
+ traceProxySecretRaw: Env.get('TRACE_PROXY_SECRET', '').trim(),
146
+ traceProxyTimeoutRaw: Env.get('TRACE_PROXY_TIMEOUT_MS', '').trim(),
147
+ traceServiceTagRaw: Env.get('TRACE_SERVICE_TAG', '').trim(),
148
+ appNameRaw: Env.get('APP_NAME', '').trim(),
149
+ appKeyRaw: Env.get('APP_KEY', '').trim(),
150
+ captureCachePayloadsRaw: Env.get('TRACE_CACHE_PAYLOADS', '').trim(),
151
+ captureQueryBindingsRaw: Env.get('TRACE_QUERY_BINDINGS', '').trim(),
152
+ contentDispatchDriverRaw: Env.get('TRACE_CONTENT_QUEUE_DRIVER', '').trim(),
153
+ contentDispatchQueueRaw: Env.get('TRACE_CONTENT_QUEUE_NAME', '').trim(),
154
+ contentDispatchEnqueueTimeoutRaw: Env.get('TRACE_CONTENT_QUEUE_ENQUEUE_TIMEOUT_MS', '').trim(),
155
+ contentDispatchWorkerEnabledRaw: Env.get('TRACE_CONTENT_QUEUE_WORKER_ENABLED', '').trim(),
156
+ contentDispatchWorkerIntervalRaw: Env.get('TRACE_CONTENT_QUEUE_WORKER_INTERVAL_MS', '').trim(),
157
+ contentDispatchWorkerDurationRaw: Env.get('TRACE_CONTENT_QUEUE_WORKER_MAX_DURATION_MS', '').trim(),
158
+ contentDispatchWorkerConcurrencyRaw: Env.get('TRACE_CONTENT_QUEUE_WORKER_CONCURRENCY', '').trim(),
159
+ redactionKeys: parseEnvList(Env.get('TRACE_REDACT_KEYS', '')),
160
+ redactionHeaders: parseEnvList(Env.get('TRACE_REDACT_HEADERS', '')),
161
+ redactionBody: parseEnvList(Env.get('TRACE_REDACT_BODY', '')),
162
+ redactionQuery: parseEnvList(Env.get('TRACE_REDACT_QUERY', '')),
163
+ };
164
+ };
165
+ const resolveStringOverride = (rawValue, fallback) => {
166
+ return rawValue === '' ? fallback : rawValue;
167
+ };
168
+ const resolveNumberOverride = (rawValue, fallback) => {
169
+ return rawValue === '' ? fallback : Number.parseInt(rawValue, 10);
170
+ };
171
+ const resolveBooleanOverride = (rawValue, fallback) => {
172
+ return parseEnvBool(rawValue) ?? fallback;
173
+ };
174
+ const resolveTraceProxyKeyId = (startupOverrides, values) => {
175
+ return resolveStringOverride(values.traceProxyKeyIdRaw, startupOverrides?.proxy?.keyId ?? values.appNameRaw);
176
+ };
177
+ const resolveTraceProxySecret = (startupOverrides, values) => {
178
+ return resolveStringOverride(values.traceProxySecretRaw, startupOverrides?.proxy?.secret ?? values.appKeyRaw);
179
+ };
180
+ const withStringProperty = (key, value) => {
181
+ return typeof value === 'string' && value !== '' ? { [key]: value } : {};
182
+ };
183
+ const withNumberProperty = (key, value) => {
184
+ return typeof value === 'number' && Number.isFinite(value) ? { [key]: value } : {};
185
+ };
186
+ const withBooleanProperty = (key, value) => {
187
+ return typeof value === 'boolean' ? { [key]: value } : {};
188
+ };
189
+ const resolveTraceServiceTag = (startupOverrides, values) => {
190
+ const fallback = (startupOverrides?.serviceTag ?? values.appNameRaw).trim() || undefined;
191
+ return resolveStringOverride(values.traceServiceTagRaw, fallback);
192
+ };
193
+ const resolveContentDispatchWorkerEnabled = (startupOverrides, values) => {
194
+ return resolveBooleanOverride(values.contentDispatchWorkerEnabledRaw, startupOverrides?.contentDispatch?.worker?.enabled);
195
+ };
196
+ const resolveContentDispatchWorkerInterval = (startupOverrides, values) => {
197
+ return resolveNumberOverride(values.contentDispatchWorkerIntervalRaw, startupOverrides?.contentDispatch?.worker?.intervalMs);
198
+ };
199
+ const resolveContentDispatchWorkerDuration = (startupOverrides, values) => {
200
+ return resolveNumberOverride(values.contentDispatchWorkerDurationRaw, startupOverrides?.contentDispatch?.worker?.maxDurationMs);
201
+ };
202
+ const resolveContentDispatchWorkerConcurrency = (startupOverrides, values) => {
203
+ return resolveNumberOverride(values.contentDispatchWorkerConcurrencyRaw, startupOverrides?.contentDispatch?.worker?.concurrency);
204
+ };
205
+ const buildTraceContentDispatchWorkerConfig = (startupOverrides, values) => {
206
+ const defaultWorker = TraceConfig.defaults().contentDispatch.worker;
207
+ const startupWorker = startupOverrides?.contentDispatch?.worker;
208
+ const contentDispatchWorkerEnabled = resolveContentDispatchWorkerEnabled(startupOverrides, values);
209
+ const contentDispatchWorkerInterval = resolveContentDispatchWorkerInterval(startupOverrides, values);
210
+ const contentDispatchWorkerDuration = resolveContentDispatchWorkerDuration(startupOverrides, values);
211
+ const contentDispatchWorkerConcurrency = resolveContentDispatchWorkerConcurrency(startupOverrides, values);
212
+ return {
213
+ ...defaultWorker,
214
+ ...startupWorker,
215
+ enabled: contentDispatchWorkerEnabled ?? startupWorker?.enabled ?? defaultWorker.enabled,
216
+ intervalMs: contentDispatchWorkerInterval ?? startupWorker?.intervalMs ?? defaultWorker.intervalMs,
217
+ maxDurationMs: contentDispatchWorkerDuration ?? startupWorker?.maxDurationMs ?? defaultWorker.maxDurationMs,
218
+ concurrency: contentDispatchWorkerConcurrency ?? startupWorker?.concurrency ?? defaultWorker.concurrency,
219
+ };
220
+ };
221
+ const buildTraceProxyConfig = (startupOverrides, values) => {
222
+ const traceProxyEnabled = resolveBooleanOverride(values.traceProxyRaw, startupOverrides?.proxy?.enabled);
223
+ const traceProxyUrl = resolveStringOverride(values.traceProxyUrlRaw, startupOverrides?.proxy?.url);
224
+ const traceProxyPath = resolveStringOverride(values.traceProxyPathRaw, startupOverrides?.proxy?.path);
225
+ const traceProxyKeyId = resolveTraceProxyKeyId(startupOverrides, values);
226
+ const traceProxySecret = resolveTraceProxySecret(startupOverrides, values);
227
+ const traceProxyTimeout = resolveNumberOverride(values.traceProxyTimeoutRaw, startupOverrides?.proxy?.timeoutMs);
228
+ return {
229
+ ...TraceConfig.defaults().proxy,
230
+ ...startupOverrides?.proxy,
231
+ ...withBooleanProperty('enabled', traceProxyEnabled),
232
+ ...withStringProperty('url', traceProxyUrl),
233
+ ...withStringProperty('path', traceProxyPath),
234
+ ...withStringProperty('keyId', traceProxyKeyId),
235
+ ...withStringProperty('secret', traceProxySecret),
236
+ ...withNumberProperty('timeoutMs', traceProxyTimeout),
237
+ };
238
+ };
239
+ const buildTraceContentDispatchConfig = (startupOverrides, values) => {
240
+ const defaultContentDispatch = TraceConfig.defaults().contentDispatch;
241
+ const startupContentDispatch = startupOverrides?.contentDispatch;
242
+ const contentDispatchDriver = resolveStringOverride(values.contentDispatchDriverRaw, startupContentDispatch?.driver);
243
+ const contentDispatchQueueName = resolveStringOverride(values.contentDispatchQueueRaw, startupContentDispatch?.queueName);
244
+ const contentDispatchEnqueueTimeout = resolveNumberOverride(values.contentDispatchEnqueueTimeoutRaw, startupContentDispatch?.enqueueTimeoutMs);
245
+ return {
246
+ ...defaultContentDispatch,
247
+ ...startupContentDispatch,
248
+ ...withStringProperty('driver', contentDispatchDriver),
249
+ ...withStringProperty('queueName', contentDispatchQueueName),
250
+ ...withNumberProperty('enqueueTimeoutMs', contentDispatchEnqueueTimeout),
251
+ worker: buildTraceContentDispatchWorkerConfig(startupOverrides, values),
252
+ };
253
+ };
254
+ const buildTraceRuntimeConfig = (Env, startupOverrides) => {
255
+ const values = readTraceEnvValues(Env);
138
256
  const enabled = startupOverrides?.enabled === true || Env.getBool('TRACE_ENABLED', false);
139
- if (enabled) {
140
- const connectionRaw = Env.get('TRACE_DB_CONNECTION', '').trim();
141
- const observeConnectionRaw = Env.get('TRACE_QUERY_CONNECTION', '').trim();
142
- const pruneAfterHoursRaw = Env.get('TRACE_PRUNE_HOURS', '').trim();
143
- const slowQueryThresholdRaw = Env.get('TRACE_SLOW_QUERY_MS', '').trim();
144
- const logMinLevelRaw = Env.get('TRACE_LOG_LEVEL', '').trim();
145
- const traceProxyRaw = Env.get('TRACE_PROXY', '').trim();
146
- const traceProxyUrlRaw = Env.get('TRACE_PROXY_URL', '').trim();
147
- const traceProxyPathRaw = Env.get('TRACE_PROXY_PATH', '').trim();
148
- const traceProxyKeyIdRaw = Env.get('TRACE_PROXY_KEY_ID', '').trim();
149
- const traceProxySecretRaw = Env.get('TRACE_PROXY_SECRET', '').trim();
150
- const traceProxyTimeoutRaw = Env.get('TRACE_PROXY_TIMEOUT_MS', '').trim();
151
- const traceServiceTagRaw = Env.get('TRACE_SERVICE_TAG', '').trim();
152
- const appNameRaw = Env.get('APP_NAME', '').trim();
153
- const appKeyRaw = Env.get('APP_KEY', '').trim();
154
- const captureCachePayloadsRaw = Env.get('TRACE_CACHE_PAYLOADS', '').trim();
155
- const captureQueryBindingsRaw = Env.get('TRACE_QUERY_BINDINGS', '').trim();
156
- const contentDispatchDriverRaw = Env.get('TRACE_CONTENT_QUEUE_DRIVER', '').trim();
157
- const contentDispatchQueueRaw = Env.get('TRACE_CONTENT_QUEUE_NAME', '').trim();
158
- const contentDispatchEnqueueTimeoutRaw = Env.get('TRACE_CONTENT_QUEUE_ENQUEUE_TIMEOUT_MS', '').trim();
159
- const contentDispatchWorkerEnabledRaw = Env.get('TRACE_CONTENT_QUEUE_WORKER_ENABLED', '').trim();
160
- const contentDispatchWorkerIntervalRaw = Env.get('TRACE_CONTENT_QUEUE_WORKER_INTERVAL_MS', '').trim();
161
- const contentDispatchWorkerDurationRaw = Env.get('TRACE_CONTENT_QUEUE_WORKER_MAX_DURATION_MS', '').trim();
162
- const contentDispatchWorkerConcurrencyRaw = Env.get('TRACE_CONTENT_QUEUE_WORKER_CONCURRENCY', '').trim();
163
- const redactionKeys = parseEnvList(Env.get('TRACE_REDACT_KEYS', ''));
164
- const redactionHeaders = parseEnvList(Env.get('TRACE_REDACT_HEADERS', ''));
165
- const redactionBody = parseEnvList(Env.get('TRACE_REDACT_BODY', ''));
166
- const redactionQuery = parseEnvList(Env.get('TRACE_REDACT_QUERY', ''));
167
- const connection = connectionRaw === '' ? startupOverrides?.connection : connectionRaw;
168
- const observeConnection = observeConnectionRaw === '' ? startupOverrides?.observeConnection : observeConnectionRaw;
169
- const pruneAfterHours = pruneAfterHoursRaw === ''
170
- ? startupOverrides?.pruneAfterHours
171
- : Number.parseInt(pruneAfterHoursRaw, 10);
172
- const slowQueryThreshold = slowQueryThresholdRaw === ''
173
- ? startupOverrides?.slowQueryThreshold
174
- : Number.parseInt(slowQueryThresholdRaw, 10);
175
- const logMinLevel = (logMinLevelRaw === '' ? startupOverrides?.logMinLevel : logMinLevelRaw);
176
- const captureCachePayloads = parseEnvBool(captureCachePayloadsRaw) ?? startupOverrides?.captureCachePayloads;
177
- const captureQueryBindings = parseEnvBool(captureQueryBindingsRaw) ?? startupOverrides?.captureQueryBindings;
178
- const traceProxyEnabled = parseEnvBool(traceProxyRaw) ?? startupOverrides?.proxy?.enabled;
179
- const traceProxyUrl = traceProxyUrlRaw === '' ? startupOverrides?.proxy?.url : traceProxyUrlRaw;
180
- const traceProxyPath = traceProxyPathRaw === '' ? startupOverrides?.proxy?.path : traceProxyPathRaw;
181
- const traceProxyKeyId = traceProxyKeyIdRaw === ''
182
- ? (startupOverrides?.proxy?.keyId ?? appNameRaw)
183
- : traceProxyKeyIdRaw;
184
- const traceProxySecret = traceProxySecretRaw === ''
185
- ? (startupOverrides?.proxy?.secret ?? appKeyRaw)
186
- : traceProxySecretRaw;
187
- const traceProxyTimeout = traceProxyTimeoutRaw === ''
188
- ? startupOverrides?.proxy?.timeoutMs
189
- : Number.parseInt(traceProxyTimeoutRaw, 10);
190
- const traceServiceTag = traceServiceTagRaw === ''
191
- ? (startupOverrides?.serviceTag ?? appNameRaw).trim() || undefined
192
- : traceServiceTagRaw;
193
- const contentDispatchDriver = contentDispatchDriverRaw === ''
194
- ? startupOverrides?.contentDispatch?.driver
195
- : contentDispatchDriverRaw;
196
- const contentDispatchQueueName = contentDispatchQueueRaw === ''
197
- ? startupOverrides?.contentDispatch?.queueName
198
- : contentDispatchQueueRaw;
199
- const contentDispatchEnqueueTimeout = contentDispatchEnqueueTimeoutRaw === ''
200
- ? startupOverrides?.contentDispatch?.enqueueTimeoutMs
201
- : Number.parseInt(contentDispatchEnqueueTimeoutRaw, 10);
202
- const contentDispatchWorkerEnabled = parseEnvBool(contentDispatchWorkerEnabledRaw) ??
203
- startupOverrides?.contentDispatch?.worker?.enabled;
204
- const contentDispatchWorkerInterval = contentDispatchWorkerIntervalRaw === ''
205
- ? startupOverrides?.contentDispatch?.worker?.intervalMs
206
- : Number.parseInt(contentDispatchWorkerIntervalRaw, 10);
207
- const contentDispatchWorkerDuration = contentDispatchWorkerDurationRaw === ''
208
- ? startupOverrides?.contentDispatch?.worker?.maxDurationMs
209
- : Number.parseInt(contentDispatchWorkerDurationRaw, 10);
210
- const contentDispatchWorkerConcurrency = contentDispatchWorkerConcurrencyRaw === ''
211
- ? startupOverrides?.contentDispatch?.worker?.concurrency
212
- : Number.parseInt(contentDispatchWorkerConcurrencyRaw, 10);
213
- const redaction = buildTraceRedactionOverrides({
214
- startupOverrides,
215
- redactionBody,
216
- redactionHeaders,
217
- redactionKeys,
218
- redactionQuery,
219
- });
220
- const defaultContentDispatch = TraceConfig.defaults().contentDispatch;
221
- const startupContentDispatch = startupOverrides?.contentDispatch;
222
- const startupContentDispatchWorker = startupContentDispatch?.worker;
223
- const config = TraceConfig.merge({
224
- ...startupOverrides,
225
- enabled,
226
- connection,
227
- observeConnection,
228
- ...(typeof traceServiceTag === 'string' && traceServiceTag !== ''
229
- ? { serviceTag: traceServiceTag }
230
- : {}),
231
- proxy: {
232
- ...TraceConfig.defaults().proxy,
233
- ...startupOverrides?.proxy,
234
- ...(typeof traceProxyEnabled === 'boolean' ? { enabled: traceProxyEnabled } : {}),
235
- ...(typeof traceProxyUrl === 'string' && traceProxyUrl !== ''
236
- ? { url: traceProxyUrl }
237
- : {}),
238
- ...(typeof traceProxyPath === 'string' && traceProxyPath !== ''
239
- ? { path: traceProxyPath }
240
- : {}),
241
- ...(typeof traceProxyKeyId === 'string' && traceProxyKeyId !== ''
242
- ? { keyId: traceProxyKeyId }
243
- : {}),
244
- ...(typeof traceProxySecret === 'string' && traceProxySecret !== ''
245
- ? { secret: traceProxySecret }
246
- : {}),
247
- ...(typeof traceProxyTimeout === 'number' && Number.isFinite(traceProxyTimeout)
248
- ? { timeoutMs: traceProxyTimeout }
249
- : {}),
250
- },
251
- ...(typeof pruneAfterHours === 'number' && Number.isFinite(pruneAfterHours)
252
- ? { pruneAfterHours }
253
- : {}),
254
- ...(typeof slowQueryThreshold === 'number' && Number.isFinite(slowQueryThreshold)
255
- ? { slowQueryThreshold }
256
- : {}),
257
- ...(typeof captureCachePayloads === 'boolean' ? { captureCachePayloads } : {}),
258
- ...(typeof captureQueryBindings === 'boolean' ? { captureQueryBindings } : {}),
259
- contentDispatch: {
260
- ...defaultContentDispatch,
261
- ...startupContentDispatch,
262
- ...(typeof contentDispatchDriver === 'string' && contentDispatchDriver !== ''
263
- ? { driver: contentDispatchDriver }
264
- : {}),
265
- ...(typeof contentDispatchQueueName === 'string' && contentDispatchQueueName !== ''
266
- ? { queueName: contentDispatchQueueName }
267
- : {}),
268
- ...(typeof contentDispatchEnqueueTimeout === 'number' &&
269
- Number.isFinite(contentDispatchEnqueueTimeout)
270
- ? { enqueueTimeoutMs: contentDispatchEnqueueTimeout }
271
- : {}),
272
- worker: {
273
- ...defaultContentDispatch.worker,
274
- ...startupContentDispatchWorker,
275
- enabled: typeof contentDispatchWorkerEnabled === 'boolean'
276
- ? contentDispatchWorkerEnabled
277
- : (startupContentDispatchWorker?.enabled ?? defaultContentDispatch.worker.enabled),
278
- intervalMs: typeof contentDispatchWorkerInterval === 'number' &&
279
- Number.isFinite(contentDispatchWorkerInterval)
280
- ? contentDispatchWorkerInterval
281
- : (startupContentDispatchWorker?.intervalMs ??
282
- defaultContentDispatch.worker.intervalMs),
283
- maxDurationMs: typeof contentDispatchWorkerDuration === 'number' &&
284
- Number.isFinite(contentDispatchWorkerDuration)
285
- ? contentDispatchWorkerDuration
286
- : (startupContentDispatchWorker?.maxDurationMs ??
287
- defaultContentDispatch.worker.maxDurationMs),
288
- concurrency: typeof contentDispatchWorkerConcurrency === 'number' &&
289
- Number.isFinite(contentDispatchWorkerConcurrency)
290
- ? contentDispatchWorkerConcurrency
291
- : (startupContentDispatchWorker?.concurrency ??
292
- defaultContentDispatch.worker.concurrency),
293
- },
294
- },
295
- logMinLevel,
296
- ...(redaction === undefined ? {} : { redaction }),
297
- });
298
- const resolvedConnectionName = resolveTraceConnectionName(Env, config.connection);
299
- const resolvedObservedConnectionName = resolveObservedConnectionName(Env, config.observeConnection, resolvedConnectionName);
300
- globalTraceRegisterState.__zintrust_system_trace_connection_name__ = resolvedConnectionName;
301
- globalTraceRegisterState.__zintrust_system_trace_observe_connection_name__ =
302
- resolvedObservedConnectionName;
303
- const storageDb = core.useDatabase?.(undefined, resolvedConnectionName);
304
- const observedDb = core.useDatabase?.(undefined, resolvedObservedConnectionName);
305
- assertTraceConnectionResolved(core, storageDb, {
306
- connectionName: resolvedConnectionName,
307
- envKey: 'TRACE_DB_CONNECTION',
308
- });
309
- assertTraceConnectionResolved(core, observedDb, {
310
- connectionName: resolvedObservedConnectionName,
311
- envKey: 'TRACE_QUERY_CONNECTION',
312
- });
313
- await assertTraceStorageReady(core, storageDb, resolvedConnectionName);
314
- const resolvedStorage = config.proxy.enabled
315
- ? ProxyTraceStorage.create({
316
- baseUrl: config.proxy.url ?? '',
317
- path: config.proxy.path,
318
- keyId: config.proxy.keyId ?? '',
319
- secret: config.proxy.secret ?? '',
320
- timeoutMs: config.proxy.timeoutMs,
321
- })
322
- : TraceStorage.resolveStorage(storageDb);
323
- const storage = TraceWriteDiagnostics.wrapStorage(TraceContentBudget.wrapStorage(TraceContentRedaction.wrapStorage(TraceEntryFiltering.wrapStorage(TraceServiceTag.wrapStorage(resolvedStorage, config), config), config.redaction), config), {
324
- connectionName: resolvedConnectionName,
325
- logger: core.Logger,
326
- });
327
- if (core.RequestContext) {
328
- TraceContext.setRequestContextImpl(core.RequestContext);
329
- }
330
- const [{ HttpWatcher }, { QueryWatcher }, { LogWatcher }, { ExceptionWatcher }, { JobWatcher }, { CacheWatcher }, { ScheduleWatcher }, { MailWatcher }, { AuthWatcher }, { EventWatcher }, { ModelWatcher }, { NotificationWatcher }, { RedisWatcher }, { GateWatcher }, { MiddlewareWatcher }, { CommandWatcher }, { BatchWatcher }, { DumpWatcher }, { ViewWatcher }, { HttpClientWatcher },] = await Promise.all([
331
- import('./watchers/HttpWatcher.js'),
332
- import('./watchers/QueryWatcher.js'),
333
- import('./watchers/LogWatcher.js'),
334
- import('./watchers/ExceptionWatcher.js'),
335
- import('./watchers/JobWatcher.js'),
336
- import('./watchers/CacheWatcher.js'),
337
- import('./watchers/ScheduleWatcher.js'),
338
- import('./watchers/MailWatcher.js'),
339
- import('./watchers/AuthWatcher.js'),
340
- import('./watchers/EventWatcher.js'),
341
- import('./watchers/ModelWatcher.js'),
342
- import('./watchers/NotificationWatcher.js'),
343
- import('./watchers/RedisWatcher.js'),
344
- import('./watchers/GateWatcher.js'),
345
- import('./watchers/MiddlewareWatcher.js'),
346
- import('./watchers/CommandWatcher.js'),
347
- import('./watchers/BatchWatcher.js'),
348
- import('./watchers/DumpWatcher.js'),
349
- import('./watchers/ViewWatcher.js'),
350
- import('./watchers/HttpClientWatcher.js'),
351
- ]);
352
- const watcherArgs = { storage, config, db: observedDb };
353
- HttpWatcher.register({ ...watcherArgs, registerMiddleware: resolveRegisterMiddleware() });
354
- QueryWatcher.register(watcherArgs);
355
- LogWatcher.register(watcherArgs);
356
- ExceptionWatcher.register(watcherArgs);
357
- JobWatcher.register(watcherArgs);
358
- CacheWatcher.register(watcherArgs);
359
- ScheduleWatcher.register(watcherArgs);
360
- MailWatcher.register(watcherArgs);
361
- AuthWatcher.register(watcherArgs);
362
- EventWatcher.register(watcherArgs);
363
- ModelWatcher.register(watcherArgs);
364
- NotificationWatcher.register(watcherArgs);
365
- RedisWatcher.register(watcherArgs);
366
- GateWatcher.register(watcherArgs);
367
- MiddlewareWatcher.register(watcherArgs);
368
- CommandWatcher.register(watcherArgs);
369
- BatchWatcher.register(watcherArgs);
370
- DumpWatcher.register(watcherArgs);
371
- ViewWatcher.register(watcherArgs);
372
- HttpClientWatcher.register(watcherArgs);
257
+ const connection = resolveStringOverride(values.connectionRaw, startupOverrides?.connection);
258
+ const observeConnection = resolveStringOverride(values.observeConnectionRaw, startupOverrides?.observeConnection);
259
+ const pruneAfterHours = resolveNumberOverride(values.pruneAfterHoursRaw, startupOverrides?.pruneAfterHours);
260
+ const slowQueryThreshold = resolveNumberOverride(values.slowQueryThresholdRaw, startupOverrides?.slowQueryThreshold);
261
+ const logMinLevel = (values.logMinLevelRaw === '' ? startupOverrides?.logMinLevel : values.logMinLevelRaw);
262
+ const captureCachePayloads = resolveBooleanOverride(values.captureCachePayloadsRaw, startupOverrides?.captureCachePayloads);
263
+ const captureQueryBindings = resolveBooleanOverride(values.captureQueryBindingsRaw, startupOverrides?.captureQueryBindings);
264
+ const traceServiceTag = resolveTraceServiceTag(startupOverrides, values);
265
+ const redaction = buildTraceRedactionOverrides({
266
+ startupOverrides,
267
+ redactionBody: values.redactionBody,
268
+ redactionHeaders: values.redactionHeaders,
269
+ redactionKeys: values.redactionKeys,
270
+ redactionQuery: values.redactionQuery,
271
+ });
272
+ return TraceConfig.merge({
273
+ ...startupOverrides,
274
+ enabled,
275
+ connection,
276
+ observeConnection,
277
+ ...withStringProperty('serviceTag', traceServiceTag),
278
+ proxy: buildTraceProxyConfig(startupOverrides, values),
279
+ ...withNumberProperty('pruneAfterHours', pruneAfterHours),
280
+ ...withNumberProperty('slowQueryThreshold', slowQueryThreshold),
281
+ ...withBooleanProperty('captureCachePayloads', captureCachePayloads),
282
+ ...withBooleanProperty('captureQueryBindings', captureQueryBindings),
283
+ contentDispatch: buildTraceContentDispatchConfig(startupOverrides, values),
284
+ logMinLevel,
285
+ ...(redaction === undefined ? {} : { redaction }),
286
+ });
287
+ };
288
+ const createTraceWatcherArgs = async (core, Env, config) => {
289
+ const resolvedConnectionName = resolveTraceConnectionName(Env, config.connection);
290
+ const resolvedObservedConnectionName = resolveObservedConnectionName(Env, config.observeConnection, resolvedConnectionName);
291
+ globalTraceRegisterState.__zintrust_system_trace_connection_name__ = resolvedConnectionName;
292
+ globalTraceRegisterState.__zintrust_system_trace_observe_connection_name__ =
293
+ resolvedObservedConnectionName;
294
+ const storageDb = core.useDatabase?.(undefined, resolvedConnectionName);
295
+ const observedDb = core.useDatabase?.(undefined, resolvedObservedConnectionName);
296
+ assertTraceConnectionResolved(core, storageDb, {
297
+ connectionName: resolvedConnectionName,
298
+ envKey: 'TRACE_DB_CONNECTION',
299
+ });
300
+ assertTraceConnectionResolved(core, observedDb, {
301
+ connectionName: resolvedObservedConnectionName,
302
+ envKey: 'TRACE_QUERY_CONNECTION',
303
+ });
304
+ await assertTraceStorageReady(core, storageDb, resolvedConnectionName);
305
+ const resolvedStorage = config.proxy.enabled
306
+ ? ProxyTraceStorage.create({
307
+ baseUrl: config.proxy.url ?? '',
308
+ path: config.proxy.path,
309
+ keyId: config.proxy.keyId ?? '',
310
+ secret: config.proxy.secret ?? '',
311
+ timeoutMs: config.proxy.timeoutMs,
312
+ })
313
+ : TraceStorage.resolveStorage(storageDb);
314
+ const storage = TraceWriteDiagnostics.wrapStorage(TraceContentBudget.wrapStorage(TraceContentRedaction.wrapStorage(TraceEntryFiltering.wrapStorage(TraceServiceTag.wrapStorage(resolvedStorage, config), config), config.redaction), config), {
315
+ connectionName: resolvedConnectionName,
316
+ logger: core.Logger,
317
+ });
318
+ return { storage, config, db: observedDb };
319
+ };
320
+ const registerTraceWatchers = async (watcherArgs) => {
321
+ const [{ HttpWatcher }, { QueryWatcher }, { LogWatcher }, { ExceptionWatcher }, { JobWatcher }, { CacheWatcher }, { ScheduleWatcher }, { MailWatcher }, { AuthWatcher }, { EventWatcher }, { ModelWatcher }, { NotificationWatcher }, { RedisWatcher }, { GateWatcher }, { MiddlewareWatcher }, { CommandWatcher }, { BatchWatcher }, { DumpWatcher }, { ViewWatcher }, { HttpClientWatcher },] = await Promise.all([
322
+ import('./watchers/HttpWatcher.js'),
323
+ import('./watchers/QueryWatcher.js'),
324
+ import('./watchers/LogWatcher.js'),
325
+ import('./watchers/ExceptionWatcher.js'),
326
+ import('./watchers/JobWatcher.js'),
327
+ import('./watchers/CacheWatcher.js'),
328
+ import('./watchers/ScheduleWatcher.js'),
329
+ import('./watchers/MailWatcher.js'),
330
+ import('./watchers/AuthWatcher.js'),
331
+ import('./watchers/EventWatcher.js'),
332
+ import('./watchers/ModelWatcher.js'),
333
+ import('./watchers/NotificationWatcher.js'),
334
+ import('./watchers/RedisWatcher.js'),
335
+ import('./watchers/GateWatcher.js'),
336
+ import('./watchers/MiddlewareWatcher.js'),
337
+ import('./watchers/CommandWatcher.js'),
338
+ import('./watchers/BatchWatcher.js'),
339
+ import('./watchers/DumpWatcher.js'),
340
+ import('./watchers/ViewWatcher.js'),
341
+ import('./watchers/HttpClientWatcher.js'),
342
+ ]);
343
+ HttpWatcher.register({ ...watcherArgs, registerMiddleware: resolveRegisterMiddleware() });
344
+ QueryWatcher.register(watcherArgs);
345
+ LogWatcher.register(watcherArgs);
346
+ ExceptionWatcher.register(watcherArgs);
347
+ JobWatcher.register(watcherArgs);
348
+ CacheWatcher.register(watcherArgs);
349
+ ScheduleWatcher.register(watcherArgs);
350
+ MailWatcher.register(watcherArgs);
351
+ AuthWatcher.register(watcherArgs);
352
+ EventWatcher.register(watcherArgs);
353
+ ModelWatcher.register(watcherArgs);
354
+ NotificationWatcher.register(watcherArgs);
355
+ RedisWatcher.register(watcherArgs);
356
+ GateWatcher.register(watcherArgs);
357
+ MiddlewareWatcher.register(watcherArgs);
358
+ CommandWatcher.register(watcherArgs);
359
+ BatchWatcher.register(watcherArgs);
360
+ DumpWatcher.register(watcherArgs);
361
+ ViewWatcher.register(watcherArgs);
362
+ HttpClientWatcher.register(watcherArgs);
363
+ };
364
+ const activateTrace = async (core, Env, startupOverrides) => {
365
+ const config = buildTraceRuntimeConfig(Env, startupOverrides);
366
+ if (!config.enabled)
367
+ return;
368
+ const watcherArgs = await createTraceWatcherArgs(core, Env, config);
369
+ if (core.RequestContext) {
370
+ TraceContext.setRequestContextImpl(core.RequestContext);
373
371
  }
374
- }
375
- else if (!traceAlreadyInitialized) {
376
- // Running outside a ZinTrust project - skip init silently.
377
- // eslint-disable-next-line no-console
378
- console.warn('[trace] @zintrust/core not found - trace will not be activated.');
379
- }
372
+ await registerTraceWatchers(watcherArgs);
373
+ };
374
+ const initializeTraceRegister = async () => {
375
+ const core = (await importCore());
376
+ const Env = core.Env;
377
+ const startupOverrides = await resolveTraceStartupOverrides(core);
378
+ if (!traceAlreadyInitialized && Env) {
379
+ await activateTrace(core, Env, startupOverrides);
380
+ return;
381
+ }
382
+ if (!traceAlreadyInitialized) {
383
+ // Running outside a ZinTrust project - skip init silently.
384
+ // eslint-disable-next-line no-console
385
+ console.warn('[trace] @zintrust/core not found - trace will not be activated.');
386
+ }
387
+ };
388
+ export const registerTraceReady = initializeTraceRegister();
@@ -0,0 +1,13 @@
1
+ /**
2
+ * TraceStorage — sealed namespace wrapping the D1/SQLite driver.
3
+ * Resolves the correct IDatabase from the app config, then delegates all
4
+ * read/write operations to the trace storage facade.
5
+ */
6
+ import type { IDatabase } from '@zintrust/core';
7
+ import type { ITraceStorage } from '../types';
8
+ export declare const TraceStorage: Readonly<{
9
+ resolveStorage: (db: IDatabase) => ITraceStorage;
10
+ reset: () => void;
11
+ familyHash: (input: string) => string;
12
+ }>;
13
+ export { type ITraceStorage } from '../types';