@zintrust/trace 1.8.1 → 2.0.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.
- package/README.md +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/register.js +9 -1
- package/dist/runtime/BackgroundTaskScheduler.d.ts +38 -0
- package/dist/runtime/BackgroundTaskScheduler.js +105 -0
- package/dist/types.d.ts +2 -0
- package/dist/watchers/ExceptionWatcher.js +10 -2
- package/dist/watchers/HttpClientWatcher.js +10 -2
- package/dist/watchers/HttpWatcher.js +11 -3
- package/dist/watchers/LogWatcher.js +7 -2
- package/dist/watchers/QueryWatcher.js +10 -2
- package/package.json +1 -1
- package/dist/build-manifest.json +0 -453
- package/dist/storage/DebuggerStorage.d.ts +0 -13
- package/dist/storage/DebuggerStorage.js +0 -195
package/README.md
CHANGED
|
@@ -91,6 +91,30 @@ import serviceManifest from './bootstrap/service-manifest';
|
|
|
91
91
|
ProjectRuntime.set({ serviceManifest });
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
#### Cloudflare Workers waitUntil Support
|
|
95
|
+
|
|
96
|
+
For reliable trace persistence in Cloudflare Workers, set the execution context in your Worker fetch handler:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
// src/worker.ts or your Worker entrypoint
|
|
100
|
+
import { BackgroundTaskScheduler } from '@zintrust/trace';
|
|
101
|
+
|
|
102
|
+
export default {
|
|
103
|
+
async fetch(request, env, ctx) {
|
|
104
|
+
// Enable reliable trace persistence via ctx.waitUntil()
|
|
105
|
+
BackgroundTaskScheduler.setExecutionContext(ctx);
|
|
106
|
+
|
|
107
|
+
// Initialize and run your ZinTrust app
|
|
108
|
+
const app = createApp();
|
|
109
|
+
await app.boot();
|
|
110
|
+
|
|
111
|
+
return app.handle(request);
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
This ensures trace writes complete reliably even after the HTTP response is sent. Without this, trace writes may be lost in Workers environments. See [docs/WORKER_WAITUNTIL_SUPPORT.md](./docs/WORKER_WAITUNTIL_SUPPORT.md) for details.
|
|
117
|
+
|
|
94
118
|
Why this is the preferred path:
|
|
95
119
|
|
|
96
120
|
- The plugin files are the framework-owned opt-in point that ZinTrust already auto-loads during boot.
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export type { ITraceStorage } from './storage';
|
|
|
11
11
|
export { TraceContentBudget } from './storage/TraceContentBudget';
|
|
12
12
|
export { TraceContentRedaction } from './storage/TraceContentRedaction';
|
|
13
13
|
export { TraceContext } from './context';
|
|
14
|
+
export { BackgroundTaskScheduler } from './runtime/BackgroundTaskScheduler';
|
|
14
15
|
export { registerTraceDashboard, registerTraceRoutes } from './dashboard/routes';
|
|
15
16
|
export type { TraceDashboardOptions, TraceDashboardRegistrationOptions } from './dashboard/routes';
|
|
16
17
|
export { registerTraceIngestGateway, TraceIngestGateway } from './ingest/TraceIngestGateway';
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,10 @@ export { TraceContentRedaction } from './storage/TraceContentRedaction.js';
|
|
|
21
21
|
// ---------------------------------------------------------------------------
|
|
22
22
|
export { TraceContext } from './context.js';
|
|
23
23
|
// ---------------------------------------------------------------------------
|
|
24
|
+
// Runtime
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
export { BackgroundTaskScheduler } from './runtime/BackgroundTaskScheduler.js';
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
24
28
|
// Dashboard
|
|
25
29
|
// ---------------------------------------------------------------------------
|
|
26
30
|
export { registerTraceDashboard, registerTraceRoutes } from './dashboard/routes.js';
|
package/dist/register.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { TraceConfig } from './config.js';
|
|
23
23
|
import { TraceContext } from './context.js';
|
|
24
|
+
import { BackgroundTaskScheduler } from './runtime/BackgroundTaskScheduler.js';
|
|
24
25
|
import { ProxyTraceStorage, TraceServiceTag, TraceStorage } from './storage/index.js';
|
|
25
26
|
import { TraceContentBudget } from './storage/TraceContentBudget.js';
|
|
26
27
|
import { TraceContentRedaction } from './storage/TraceContentRedaction.js';
|
|
@@ -319,7 +320,14 @@ const createTraceWatcherArgs = async (core, Env, config) => {
|
|
|
319
320
|
connectionName: resolvedConnectionName,
|
|
320
321
|
logger: core.Logger,
|
|
321
322
|
});
|
|
322
|
-
return {
|
|
323
|
+
return {
|
|
324
|
+
storage,
|
|
325
|
+
config,
|
|
326
|
+
db: observedDb,
|
|
327
|
+
scheduleBackgroundTask: (task) => {
|
|
328
|
+
BackgroundTaskScheduler.schedule(task);
|
|
329
|
+
},
|
|
330
|
+
};
|
|
323
331
|
};
|
|
324
332
|
const registerTraceWatchers = async (watcherArgs) => {
|
|
325
333
|
const [{ HttpWatcher }, { QueryWatcher }, { LogWatcher }, { ExceptionWatcher }, { JobWatcher }, { CacheWatcher }, { ScheduleWatcher }, { MailWatcher }, { AuthWatcher }, { EventWatcher }, { ModelWatcher }, { NotificationWatcher }, { RedisWatcher }, { GateWatcher }, { MiddlewareWatcher }, { CommandWatcher }, { BatchWatcher }, { DumpWatcher }, { ViewWatcher }, { HttpClientWatcher },] = await Promise.all([
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BackgroundTaskScheduler — runtime-agnostic background task scheduling.
|
|
3
|
+
* Maps to ctx.waitUntil() in Cloudflare Workers, normal promises in Node.
|
|
4
|
+
*/
|
|
5
|
+
type ExecutionContext = {
|
|
6
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
7
|
+
};
|
|
8
|
+
type BackgroundTaskScheduler = {
|
|
9
|
+
schedule(task: Promise<void>): void;
|
|
10
|
+
isAvailable(): boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const BackgroundTaskScheduler: Readonly<{
|
|
13
|
+
/**
|
|
14
|
+
* Set the Worker execution context for waitUntil support.
|
|
15
|
+
* Call this from your Cloudflare Worker fetch handler:
|
|
16
|
+
* BackgroundTaskScheduler.setExecutionContext(ctx);
|
|
17
|
+
*/
|
|
18
|
+
setExecutionContext(ctx: ExecutionContext): void;
|
|
19
|
+
/**
|
|
20
|
+
* Get the current scheduler instance.
|
|
21
|
+
*/
|
|
22
|
+
getScheduler(): BackgroundTaskScheduler;
|
|
23
|
+
/**
|
|
24
|
+
* Schedule a background task.
|
|
25
|
+
* In Workers: uses ctx.waitUntil() if context is set
|
|
26
|
+
* In Node: fire-and-forget with error suppression
|
|
27
|
+
*/
|
|
28
|
+
schedule(task: Promise<void>): void;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a proper scheduler is available (i.e., Workers context is set).
|
|
31
|
+
*/
|
|
32
|
+
isAvailable(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Reset the scheduler (useful for testing).
|
|
35
|
+
*/
|
|
36
|
+
reset(): void;
|
|
37
|
+
}>;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BackgroundTaskScheduler — runtime-agnostic background task scheduling.
|
|
3
|
+
* Maps to ctx.waitUntil() in Cloudflare Workers, normal promises in Node.
|
|
4
|
+
*/
|
|
5
|
+
let _executionContext;
|
|
6
|
+
let _scheduler;
|
|
7
|
+
const isCloudflareRuntime = () => {
|
|
8
|
+
const globalRef = typeof globalThis === 'undefined' ? undefined : globalThis;
|
|
9
|
+
if (!globalRef)
|
|
10
|
+
return false;
|
|
11
|
+
// @ts-ignore - navigator is available in workers
|
|
12
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent === 'Cloudflare-Workers') {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return (typeof globalRef.caches !== 'undefined' ||
|
|
16
|
+
typeof globalRef.WebSocketPair === 'function' ||
|
|
17
|
+
typeof globalRef.CF !== 'undefined');
|
|
18
|
+
};
|
|
19
|
+
const createWorkerScheduler = (ctx) => {
|
|
20
|
+
return Object.freeze({
|
|
21
|
+
schedule(task) {
|
|
22
|
+
ctx.waitUntil(task);
|
|
23
|
+
},
|
|
24
|
+
isAvailable() {
|
|
25
|
+
return true;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const createNodeScheduler = () => {
|
|
30
|
+
return Object.freeze({
|
|
31
|
+
schedule(task) {
|
|
32
|
+
// In Node, fire-and-forget is acceptable since the process doesn't terminate
|
|
33
|
+
// like Workers do. We still catch errors to prevent unhandled rejections.
|
|
34
|
+
task.catch(() => {
|
|
35
|
+
// Silently ignore background task errors to avoid noise
|
|
36
|
+
// The individual watchers handle their own error logging
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
isAvailable() {
|
|
40
|
+
return true;
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
const createFallbackScheduler = () => {
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
schedule(task) {
|
|
47
|
+
// Fallback: fire-and-forget with error suppression
|
|
48
|
+
task.catch(() => undefined);
|
|
49
|
+
},
|
|
50
|
+
isAvailable() {
|
|
51
|
+
return false;
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
export const BackgroundTaskScheduler = Object.freeze({
|
|
56
|
+
/**
|
|
57
|
+
* Set the Worker execution context for waitUntil support.
|
|
58
|
+
* Call this from your Cloudflare Worker fetch handler:
|
|
59
|
+
* BackgroundTaskScheduler.setExecutionContext(ctx);
|
|
60
|
+
*/
|
|
61
|
+
setExecutionContext(ctx) {
|
|
62
|
+
_executionContext = ctx;
|
|
63
|
+
_scheduler = createWorkerScheduler(ctx);
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Get the current scheduler instance.
|
|
67
|
+
*/
|
|
68
|
+
getScheduler() {
|
|
69
|
+
if (_scheduler)
|
|
70
|
+
return _scheduler;
|
|
71
|
+
if (_executionContext) {
|
|
72
|
+
_scheduler = createWorkerScheduler(_executionContext);
|
|
73
|
+
return _scheduler;
|
|
74
|
+
}
|
|
75
|
+
if (isCloudflareRuntime()) {
|
|
76
|
+
// We're in Workers but no context was set - use fallback
|
|
77
|
+
_scheduler = createFallbackScheduler();
|
|
78
|
+
return _scheduler;
|
|
79
|
+
}
|
|
80
|
+
// Node.js or other runtime
|
|
81
|
+
_scheduler = createNodeScheduler();
|
|
82
|
+
return _scheduler;
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* Schedule a background task.
|
|
86
|
+
* In Workers: uses ctx.waitUntil() if context is set
|
|
87
|
+
* In Node: fire-and-forget with error suppression
|
|
88
|
+
*/
|
|
89
|
+
schedule(task) {
|
|
90
|
+
this.getScheduler().schedule(task);
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* Check if a proper scheduler is available (i.e., Workers context is set).
|
|
94
|
+
*/
|
|
95
|
+
isAvailable() {
|
|
96
|
+
return this.getScheduler().isAvailable();
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* Reset the scheduler (useful for testing).
|
|
100
|
+
*/
|
|
101
|
+
reset() {
|
|
102
|
+
_executionContext = undefined;
|
|
103
|
+
_scheduler = undefined;
|
|
104
|
+
},
|
|
105
|
+
});
|
package/dist/types.d.ts
CHANGED
|
@@ -272,6 +272,8 @@ export interface ITraceWatcherConfig {
|
|
|
272
272
|
db?: IDatabase;
|
|
273
273
|
/** Optional: provide to allow HttpWatcher to register as global middleware. */
|
|
274
274
|
registerMiddleware?: (fn: (req: unknown, res: unknown, next: () => Promise<void>) => Promise<void>) => void;
|
|
275
|
+
/** Optional: schedule a background task (maps to ctx.waitUntil in Workers, normal promise in Node). */
|
|
276
|
+
scheduleBackgroundTask?: (task: Promise<void>) => void;
|
|
275
277
|
}
|
|
276
278
|
export interface ITraceWatcher {
|
|
277
279
|
register(opts: ITraceWatcherConfig): () => void;
|
|
@@ -35,6 +35,7 @@ const buildContent = (err, context) => {
|
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
let _storage = null;
|
|
38
|
+
let _scheduleBackgroundTask = null;
|
|
38
39
|
let _listenerRefCount = 0;
|
|
39
40
|
let _ignoreRoutes = [];
|
|
40
41
|
let _ignorePaths = [];
|
|
@@ -72,7 +73,7 @@ const captureException = (err, context) => {
|
|
|
72
73
|
const content = buildContent(err, context);
|
|
73
74
|
const hash = familyHash(`${content.class}:${content.file}:${content.line}`);
|
|
74
75
|
const uuid = crypto.randomUUID();
|
|
75
|
-
storage
|
|
76
|
+
const writePromise = storage
|
|
76
77
|
.writeEntry({
|
|
77
78
|
uuid,
|
|
78
79
|
batchId: context?.batchId ?? TraceContext.getBatchId(),
|
|
@@ -85,13 +86,19 @@ const captureException = (err, context) => {
|
|
|
85
86
|
})
|
|
86
87
|
.then(() => storage.markFamilyStale(hash, uuid))
|
|
87
88
|
.catch(() => undefined);
|
|
89
|
+
// Use background task scheduler if available (Workers waitUntil support)
|
|
90
|
+
if (_scheduleBackgroundTask) {
|
|
91
|
+
_scheduleBackgroundTask(writePromise);
|
|
92
|
+
}
|
|
93
|
+
// Otherwise, the promise is already fire-and-forget with error suppression
|
|
88
94
|
};
|
|
89
95
|
export const ExceptionWatcher = Object.freeze({
|
|
90
96
|
capture: captureException,
|
|
91
|
-
register({ storage, config }) {
|
|
97
|
+
register({ storage, config, scheduleBackgroundTask }) {
|
|
92
98
|
if (config.watchers.exception === false)
|
|
93
99
|
return () => undefined;
|
|
94
100
|
_storage = storage;
|
|
101
|
+
_scheduleBackgroundTask = scheduleBackgroundTask ?? null;
|
|
95
102
|
_ignoreRoutes = config.ignoreRoutes;
|
|
96
103
|
_ignorePaths = config.ignorePaths;
|
|
97
104
|
if (_listenerRefCount === 0) {
|
|
@@ -104,6 +111,7 @@ export const ExceptionWatcher = Object.freeze({
|
|
|
104
111
|
unregisterProcessListeners();
|
|
105
112
|
}
|
|
106
113
|
_storage = null;
|
|
114
|
+
_scheduleBackgroundTask = null;
|
|
107
115
|
_ignoreRoutes = [];
|
|
108
116
|
_ignorePaths = [];
|
|
109
117
|
};
|
|
@@ -4,6 +4,7 @@ import { AuthTag } from '../utils/authTag.js';
|
|
|
4
4
|
import { redactHeaders, redactUnknown } from '../utils/redact.js';
|
|
5
5
|
import { RequestFilter } from '../utils/requestFilter.js';
|
|
6
6
|
let _storage = null;
|
|
7
|
+
let _scheduleBackgroundTask = null;
|
|
7
8
|
let _redactHeaderNames = [];
|
|
8
9
|
let _redactBodyFields = [];
|
|
9
10
|
let _ignoreRoutes = [];
|
|
@@ -126,7 +127,7 @@ const emit = ({ source, method, url, requestHeaders, responseStatus, duration, r
|
|
|
126
127
|
responseBody,
|
|
127
128
|
error,
|
|
128
129
|
}, sourceRule, normalizedSource);
|
|
129
|
-
_storage
|
|
130
|
+
const writePromise = _storage
|
|
130
131
|
.writeEntry({
|
|
131
132
|
uuid: crypto.randomUUID(),
|
|
132
133
|
batchId: TraceContext.getBatchId(),
|
|
@@ -137,13 +138,19 @@ const emit = ({ source, method, url, requestHeaders, responseStatus, duration, r
|
|
|
137
138
|
createdAt: TraceContext.now(),
|
|
138
139
|
})
|
|
139
140
|
.catch(() => undefined);
|
|
141
|
+
// Use background task scheduler if available (Workers waitUntil support)
|
|
142
|
+
if (_scheduleBackgroundTask) {
|
|
143
|
+
_scheduleBackgroundTask(writePromise);
|
|
144
|
+
}
|
|
145
|
+
// Otherwise, the promise is already fire-and-forget with error suppression
|
|
140
146
|
};
|
|
141
147
|
export const HttpClientWatcher = Object.freeze({
|
|
142
148
|
emit,
|
|
143
|
-
register({ storage, config }) {
|
|
149
|
+
register({ storage, config, scheduleBackgroundTask }) {
|
|
144
150
|
if (!isWatcherEnabled(config.watchers.clientRequest))
|
|
145
151
|
return () => undefined;
|
|
146
152
|
_storage = storage;
|
|
153
|
+
_scheduleBackgroundTask = scheduleBackgroundTask ?? null;
|
|
147
154
|
_clientRequestWatcher =
|
|
148
155
|
typeof config.watchers.clientRequest === 'object' && config.watchers.clientRequest !== null
|
|
149
156
|
? config.watchers.clientRequest
|
|
@@ -154,6 +161,7 @@ export const HttpClientWatcher = Object.freeze({
|
|
|
154
161
|
_ignorePaths = config.ignorePaths;
|
|
155
162
|
return () => {
|
|
156
163
|
_storage = null;
|
|
164
|
+
_scheduleBackgroundTask = null;
|
|
157
165
|
_clientRequestWatcher = undefined;
|
|
158
166
|
_redactBodyFields = [];
|
|
159
167
|
_ignoreRoutes = [];
|
|
@@ -130,7 +130,7 @@ const shouldIgnore = (req, config) => {
|
|
|
130
130
|
};
|
|
131
131
|
const isWatcherEnabled = (config) => config.watchers.request !== false;
|
|
132
132
|
export const HttpWatcher = Object.freeze({
|
|
133
|
-
register({ storage, config, registerMiddleware }) {
|
|
133
|
+
register({ storage, config, registerMiddleware, scheduleBackgroundTask, }) {
|
|
134
134
|
if (!isWatcherEnabled(config))
|
|
135
135
|
return () => undefined;
|
|
136
136
|
if (!registerMiddleware)
|
|
@@ -162,14 +162,22 @@ export const HttpWatcher = Object.freeze({
|
|
|
162
162
|
isLatest: true,
|
|
163
163
|
createdAt: TraceContext.now(),
|
|
164
164
|
};
|
|
165
|
-
storage.writeEntry(entry).catch((error) => {
|
|
165
|
+
const writePromise = storage.writeEntry(entry).catch((error) => {
|
|
166
166
|
Logger.warn('[trace] HttpWatcher writeEntry failed', {
|
|
167
167
|
method: content.method,
|
|
168
168
|
uri: content.uri,
|
|
169
169
|
entryUuid: entry.uuid,
|
|
170
170
|
error: error instanceof Error ? error.message : String(error),
|
|
171
171
|
});
|
|
172
|
-
});
|
|
172
|
+
});
|
|
173
|
+
// Use background task scheduler if available (Workers waitUntil support)
|
|
174
|
+
if (scheduleBackgroundTask) {
|
|
175
|
+
scheduleBackgroundTask(writePromise);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
// Fallback to fire-and-forget for backward compatibility
|
|
179
|
+
writePromise.catch(() => undefined);
|
|
180
|
+
}
|
|
173
181
|
};
|
|
174
182
|
const completionHandler = registerCompletionHandler(response, persistEntry);
|
|
175
183
|
await next();
|
|
@@ -54,7 +54,7 @@ const shouldSkipTraceInfrastructureLog = (message, context) => {
|
|
|
54
54
|
isTraceStorageQueryLog(message, context));
|
|
55
55
|
};
|
|
56
56
|
export const LogWatcher = Object.freeze({
|
|
57
|
-
register({ storage, config }) {
|
|
57
|
+
register({ storage, config, scheduleBackgroundTask }) {
|
|
58
58
|
if (config.watchers.log === false)
|
|
59
59
|
return () => undefined;
|
|
60
60
|
const minPriority = LEVEL_PRIORITY[config.logMinLevel] ?? 1;
|
|
@@ -75,7 +75,7 @@ export const LogWatcher = Object.freeze({
|
|
|
75
75
|
context: context ?? undefined,
|
|
76
76
|
hostname: TraceContext.getHostname(),
|
|
77
77
|
};
|
|
78
|
-
storage
|
|
78
|
+
const writePromise = storage
|
|
79
79
|
.writeEntry({
|
|
80
80
|
uuid: crypto.randomUUID(),
|
|
81
81
|
batchId: TraceContext.getBatchId(),
|
|
@@ -86,6 +86,11 @@ export const LogWatcher = Object.freeze({
|
|
|
86
86
|
createdAt: TraceContext.now(),
|
|
87
87
|
})
|
|
88
88
|
.catch(() => undefined);
|
|
89
|
+
// Use background task scheduler if available (Workers waitUntil support)
|
|
90
|
+
if (scheduleBackgroundTask) {
|
|
91
|
+
scheduleBackgroundTask(writePromise);
|
|
92
|
+
}
|
|
93
|
+
// Otherwise, the promise is already fire-and-forget with error suppression
|
|
89
94
|
});
|
|
90
95
|
return unsubscribe;
|
|
91
96
|
},
|
|
@@ -7,6 +7,7 @@ import { EntryType } from '../types.js';
|
|
|
7
7
|
import { AuthTag } from '../utils/authTag.js';
|
|
8
8
|
let _storage = null;
|
|
9
9
|
let _config = null;
|
|
10
|
+
let _scheduleBackgroundTask = null;
|
|
10
11
|
const bindingsInterpolated = (sql, params) => {
|
|
11
12
|
// Inline params for display only — safe, not for re-execution.
|
|
12
13
|
let i = 0;
|
|
@@ -51,7 +52,7 @@ const emit = (query, params, duration, connection = 'default') => {
|
|
|
51
52
|
const tags = AuthTag.append([]);
|
|
52
53
|
if (slow)
|
|
53
54
|
tags.push('slow');
|
|
54
|
-
_storage
|
|
55
|
+
const writePromise = _storage
|
|
55
56
|
.writeEntry({
|
|
56
57
|
uuid: crypto.randomUUID(),
|
|
57
58
|
batchId,
|
|
@@ -63,16 +64,22 @@ const emit = (query, params, duration, connection = 'default') => {
|
|
|
63
64
|
createdAt: TraceContext.now(),
|
|
64
65
|
})
|
|
65
66
|
.catch(() => undefined);
|
|
67
|
+
// Use background task scheduler if available (Workers waitUntil support)
|
|
68
|
+
if (_scheduleBackgroundTask) {
|
|
69
|
+
_scheduleBackgroundTask(writePromise);
|
|
70
|
+
}
|
|
71
|
+
// Otherwise, the promise is already fire-and-forget with error suppression
|
|
66
72
|
};
|
|
67
73
|
export const QueryWatcher = Object.freeze({
|
|
68
74
|
emit,
|
|
69
|
-
register({ storage, config, db: injectedDb }) {
|
|
75
|
+
register({ storage, config, db: injectedDb, scheduleBackgroundTask, }) {
|
|
70
76
|
if (config.watchers.query === false)
|
|
71
77
|
return () => undefined;
|
|
72
78
|
if (!injectedDb)
|
|
73
79
|
return () => undefined; // no db available
|
|
74
80
|
_storage = storage;
|
|
75
81
|
_config = config;
|
|
82
|
+
_scheduleBackgroundTask = scheduleBackgroundTask ?? null;
|
|
76
83
|
const db = injectedDb;
|
|
77
84
|
const handler = (query, params, duration) => {
|
|
78
85
|
emit(query, params, duration);
|
|
@@ -81,6 +88,7 @@ export const QueryWatcher = Object.freeze({
|
|
|
81
88
|
return () => {
|
|
82
89
|
_storage = null;
|
|
83
90
|
_config = null;
|
|
91
|
+
_scheduleBackgroundTask = null;
|
|
84
92
|
db.offAfterQuery?.(handler);
|
|
85
93
|
};
|
|
86
94
|
},
|
package/package.json
CHANGED
package/dist/build-manifest.json
DELETED
|
@@ -1,453 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@zintrust/trace",
|
|
3
|
-
"version": "1.6.4",
|
|
4
|
-
"buildDate": "2026-04-30T15:30:37.643Z",
|
|
5
|
-
"buildEnvironment": {
|
|
6
|
-
"node": "v25.6.1",
|
|
7
|
-
"platform": "darwin",
|
|
8
|
-
"arch": "arm64"
|
|
9
|
-
},
|
|
10
|
-
"git": {
|
|
11
|
-
"commit": "f235df8b",
|
|
12
|
-
"branch": "release"
|
|
13
|
-
},
|
|
14
|
-
"package": {
|
|
15
|
-
"engines": {
|
|
16
|
-
"node": ">=20.0.0"
|
|
17
|
-
},
|
|
18
|
-
"dependencies": [],
|
|
19
|
-
"peerDependencies": [
|
|
20
|
-
"@zintrust/core"
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
"files": {
|
|
24
|
-
"TraceConnection.d.ts": {
|
|
25
|
-
"size": 1500,
|
|
26
|
-
"sha256": "0748601bebff011a0b3dbab736617d5e3dffe4af671f4b6f7af03012d58e5464"
|
|
27
|
-
},
|
|
28
|
-
"TraceConnection.js": {
|
|
29
|
-
"size": 4640,
|
|
30
|
-
"sha256": "c51cc312046b6b2bbe1673f1ff9508425cc7140a1d2341907f67aa36069c09f9"
|
|
31
|
-
},
|
|
32
|
-
"build-manifest.json": {
|
|
33
|
-
"size": 15912,
|
|
34
|
-
"sha256": "6732e16044ffbcb77bf9873cf30a671007b5acc4aa2f3edf5071da667d4df534"
|
|
35
|
-
},
|
|
36
|
-
"cli-register.d.ts": {
|
|
37
|
-
"size": 255,
|
|
38
|
-
"sha256": "da8d689fe5ef32e97e755f28017e4d3cb1aa63489073a71907ea41ad5761ede9"
|
|
39
|
-
},
|
|
40
|
-
"cli-register.js": {
|
|
41
|
-
"size": 1123,
|
|
42
|
-
"sha256": "c6de87d0a73df7ac66e18ecdc6f758b2652ec3abe9698e43620cf41135b33e4b"
|
|
43
|
-
},
|
|
44
|
-
"config.d.ts": {
|
|
45
|
-
"size": 470,
|
|
46
|
-
"sha256": "b034cbef0c71fb868071363624ef7a9f8d7acc20f8be8c895dd5db5a75e81f37"
|
|
47
|
-
},
|
|
48
|
-
"config.js": {
|
|
49
|
-
"size": 10503,
|
|
50
|
-
"sha256": "4514e95067194c7afacb1202a8f1caffc64a400dd995cf809301b1a51a67da38"
|
|
51
|
-
},
|
|
52
|
-
"context.d.ts": {
|
|
53
|
-
"size": 596,
|
|
54
|
-
"sha256": "4b8dade537b29dae3942d02c22e535f3b1ba1f0f6142e3a74203d4fa962a412b"
|
|
55
|
-
},
|
|
56
|
-
"context.js": {
|
|
57
|
-
"size": 2520,
|
|
58
|
-
"sha256": "00a82a58e18fb33934f449a9fb379a2f90023570ceed1676eae0aed59b02ddeb"
|
|
59
|
-
},
|
|
60
|
-
"dashboard/handlers.d.ts": {
|
|
61
|
-
"size": 993,
|
|
62
|
-
"sha256": "430f5b294d960e13e2ec39ed5c22f6655f85c46c2de9455c222505c67298ec6a"
|
|
63
|
-
},
|
|
64
|
-
"dashboard/handlers.js": {
|
|
65
|
-
"size": 10011,
|
|
66
|
-
"sha256": "a5f7f3d624a844df27ddc9d4908e73d91a4aac9b2aac1aefff1f391913353897"
|
|
67
|
-
},
|
|
68
|
-
"dashboard/routes.d.ts": {
|
|
69
|
-
"size": 997,
|
|
70
|
-
"sha256": "0ac87bc54e57978e8a9ac5924d248e1f984927bb6c819ea5528ab1179b0b50b8"
|
|
71
|
-
},
|
|
72
|
-
"dashboard/routes.js": {
|
|
73
|
-
"size": 2501,
|
|
74
|
-
"sha256": "06f0bf42214ed7691907443c0a1d5a4d8c3db3ce3f7b8269ba401ff421a54dfd"
|
|
75
|
-
},
|
|
76
|
-
"dashboard/ui.d.ts": {
|
|
77
|
-
"size": 117,
|
|
78
|
-
"sha256": "4862b41e0477f01afa0dbb446d4553b65c22ed774cd1e2db3489059ced392f94"
|
|
79
|
-
},
|
|
80
|
-
"dashboard/ui.js": {
|
|
81
|
-
"size": 84221,
|
|
82
|
-
"sha256": "b260cd17012cd5bf5f24f24eb8958d0cf79bed1d976412def3706f960b3aefa6"
|
|
83
|
-
},
|
|
84
|
-
"index.d.ts": {
|
|
85
|
-
"size": 2693,
|
|
86
|
-
"sha256": "901aaefe88fb2cc1e7771cd541f41ebcfe6443390bd66905eacbda51f1a6f73d"
|
|
87
|
-
},
|
|
88
|
-
"index.js": {
|
|
89
|
-
"size": 3421,
|
|
90
|
-
"sha256": "ee5aca20d1e6d980fa0b2c02e4832c35e8a18fff9fe63a7bf6a26ae8f734d377"
|
|
91
|
-
},
|
|
92
|
-
"ingest/TraceIngestGateway.d.ts": {
|
|
93
|
-
"size": 786,
|
|
94
|
-
"sha256": "3a0a46fa5bbf5367047214533ec0ee92a171ee35a60d25c197eea1eed1ff0f65"
|
|
95
|
-
},
|
|
96
|
-
"ingest/TraceIngestGateway.js": {
|
|
97
|
-
"size": 10936,
|
|
98
|
-
"sha256": "c95f0e42f1294d8ae2e406a5910f8e74044c2b586e82e726876d75ddfafef27e"
|
|
99
|
-
},
|
|
100
|
-
"migrations/20260331000001_create_zin_trace_entries_table.d.ts": {
|
|
101
|
-
"size": 304,
|
|
102
|
-
"sha256": "7d99b4d7c02855d6e68ad87e39dffff5fec83a406bdf2414665c23ba3ce8711d"
|
|
103
|
-
},
|
|
104
|
-
"migrations/20260331000001_create_zin_trace_entries_table.js": {
|
|
105
|
-
"size": 955,
|
|
106
|
-
"sha256": "6aa54f3a6a95a78714e9b14d7f6adb4e94e9420e4e17ac467b43fef12bbc2583"
|
|
107
|
-
},
|
|
108
|
-
"migrations/20260331000002_create_zin_trace_entries_tags_table.d.ts": {
|
|
109
|
-
"size": 304,
|
|
110
|
-
"sha256": "6d07c135b0fa34acbda2f7f0788e4db657b00ba7c7459e2b203c8ded9c55b9dc"
|
|
111
|
-
},
|
|
112
|
-
"migrations/20260331000002_create_zin_trace_entries_tags_table.js": {
|
|
113
|
-
"size": 737,
|
|
114
|
-
"sha256": "614280fc7f3a5826c3e8334e2a38d707b562217fb68a660aff0d9a6c072f7b2a"
|
|
115
|
-
},
|
|
116
|
-
"migrations/20260331000003_create_zin_trace_monitoring_table.d.ts": {
|
|
117
|
-
"size": 308,
|
|
118
|
-
"sha256": "019e84f70cedf363eaf85a115d935abed841627b4a31d7fa34131352d402187a"
|
|
119
|
-
},
|
|
120
|
-
"migrations/20260331000003_create_zin_trace_monitoring_table.js": {
|
|
121
|
-
"size": 522,
|
|
122
|
-
"sha256": "dd80ea1fdfe6ea7f57330b2dff530d97ee8054081436f41bbf234b814cb1df19"
|
|
123
|
-
},
|
|
124
|
-
"migrations/20260407193000_widen_trace_created_at_for_sql.d.ts": {
|
|
125
|
-
"size": 335,
|
|
126
|
-
"sha256": "6e9c826a08a983927d9e801b2740f58d0cf6fbf7bff02ee5c1fd01227f73b741"
|
|
127
|
-
},
|
|
128
|
-
"migrations/20260407193000_widen_trace_created_at_for_sql.js": {
|
|
129
|
-
"size": 1185,
|
|
130
|
-
"sha256": "1de9d8e4a91ffeaed4a0bc5cf942e428cd76bdb6b65bc67fa76ef62f3c99e94d"
|
|
131
|
-
},
|
|
132
|
-
"migrations/index.d.ts": {
|
|
133
|
-
"size": 280,
|
|
134
|
-
"sha256": "0ba7bc9421754ff489f6947463c13e7e9c80558eb6611a818f3baab3b518a502"
|
|
135
|
-
},
|
|
136
|
-
"migrations/index.js": {
|
|
137
|
-
"size": 500,
|
|
138
|
-
"sha256": "6118c5f4e01ecd73208425253caa3a17e4304ff6f9f00ac7afc18785684e9e85"
|
|
139
|
-
},
|
|
140
|
-
"plugin.d.ts": {
|
|
141
|
-
"size": 16,
|
|
142
|
-
"sha256": "71d366165dd36f1675aa253a76262b226fb6c62e5ab632746b8aea61c0c625fc"
|
|
143
|
-
},
|
|
144
|
-
"plugin.js": {
|
|
145
|
-
"size": 128,
|
|
146
|
-
"sha256": "2d05bec517f57634276220b8a946125059fe0e320c42295b4f5a985431bb3d1c"
|
|
147
|
-
},
|
|
148
|
-
"register.d.ts": {
|
|
149
|
-
"size": 72,
|
|
150
|
-
"sha256": "535869aa1bfcdf0ec26fad27d7f18bb8822bc586c38fcc5ffdde5274ecbea17e"
|
|
151
|
-
},
|
|
152
|
-
"register.js": {
|
|
153
|
-
"size": 19680,
|
|
154
|
-
"sha256": "042a7585e68a8a676e25f33c9a176c6f263bccb4a63090b4d2cea52b9bcdd193"
|
|
155
|
-
},
|
|
156
|
-
"storage/DebuggerStorage.d.ts": {
|
|
157
|
-
"size": 517,
|
|
158
|
-
"sha256": "c9c215aaa414f7b0c1fec6c82b054fc52bdf97af58f96f35c7f96672fb859c31"
|
|
159
|
-
},
|
|
160
|
-
"storage/DebuggerStorage.js": {
|
|
161
|
-
"size": 7442,
|
|
162
|
-
"sha256": "5ecce0fcfcf695df587a7b90a7a5c7efd2e64ad13c9f2d104b392f89f34f0dc4"
|
|
163
|
-
},
|
|
164
|
-
"storage/ProxyTraceStorage.d.ts": {
|
|
165
|
-
"size": 339,
|
|
166
|
-
"sha256": "9c724ff342dfe82da12e7cce95593f6623faa80c40f97593719b8e78e95f266d"
|
|
167
|
-
},
|
|
168
|
-
"storage/ProxyTraceStorage.js": {
|
|
169
|
-
"size": 4330,
|
|
170
|
-
"sha256": "672c95ed022504b2e5be62f3c2b31bac168ac06158d793dd020f7e38907e8f64"
|
|
171
|
-
},
|
|
172
|
-
"storage/TraceContentBudget.d.ts": {
|
|
173
|
-
"size": 1306,
|
|
174
|
-
"sha256": "606a37af0a4aef4866c22cc727f67f485c43181b40eb831e1920b8b90fdaf503"
|
|
175
|
-
},
|
|
176
|
-
"storage/TraceContentBudget.js": {
|
|
177
|
-
"size": 11495,
|
|
178
|
-
"sha256": "8ed670773814f7b86b916c43ac43b048defc6a102593d808dfb4c8cf7606edf3"
|
|
179
|
-
},
|
|
180
|
-
"storage/TraceContentRedaction.d.ts": {
|
|
181
|
-
"size": 207,
|
|
182
|
-
"sha256": "2fd7b317c5ee87d8ecaa6467a75959499673ef374fec3ecfaa7911c4f3d5c83c"
|
|
183
|
-
},
|
|
184
|
-
"storage/TraceContentRedaction.js": {
|
|
185
|
-
"size": 1083,
|
|
186
|
-
"sha256": "127aa026f155c47361d3b44021138157cb2743f5e02e044ce6df66cc693cc3cb"
|
|
187
|
-
},
|
|
188
|
-
"storage/TraceEntryFiltering.d.ts": {
|
|
189
|
-
"size": 196,
|
|
190
|
-
"sha256": "a1158cedb4e4e749658127086e138e47886422366a697619d6ea9bd3338066e6"
|
|
191
|
-
},
|
|
192
|
-
"storage/TraceEntryFiltering.js": {
|
|
193
|
-
"size": 1579,
|
|
194
|
-
"sha256": "a096b0fadf21cd692e554e6ca7789f08759cffe1c690845cb33c5876c8587cc5"
|
|
195
|
-
},
|
|
196
|
-
"storage/TraceServiceTag.d.ts": {
|
|
197
|
-
"size": 224,
|
|
198
|
-
"sha256": "35d93c82d6db80071946adaa8e40d012408b469949f1002f85ae3fd20b0a70c8"
|
|
199
|
-
},
|
|
200
|
-
"storage/TraceServiceTag.js": {
|
|
201
|
-
"size": 1916,
|
|
202
|
-
"sha256": "1ddad82563c98ddbb4033e9b8fb31901d635cffa7024d499a896f0d7a6d00900"
|
|
203
|
-
},
|
|
204
|
-
"storage/TraceStorage.d.ts": {
|
|
205
|
-
"size": 517,
|
|
206
|
-
"sha256": "c9c215aaa414f7b0c1fec6c82b054fc52bdf97af58f96f35c7f96672fb859c31"
|
|
207
|
-
},
|
|
208
|
-
"storage/TraceStorage.js": {
|
|
209
|
-
"size": 15322,
|
|
210
|
-
"sha256": "95179a66f0774fb6c1622e7477d6e1420e374116800a6a0c60e14de9bd4c4c5c"
|
|
211
|
-
},
|
|
212
|
-
"storage/TraceWriteDiagnostics.d.ts": {
|
|
213
|
-
"size": 581,
|
|
214
|
-
"sha256": "5f49df97a830ad895653fa4a18b3a1b31ca4a5066d6f8150ee02dca013e16397"
|
|
215
|
-
},
|
|
216
|
-
"storage/TraceWriteDiagnostics.js": {
|
|
217
|
-
"size": 7041,
|
|
218
|
-
"sha256": "6fc34e6e52a9b463db0967dba4aec4c8c706b6978c496f568637ffc15327279a"
|
|
219
|
-
},
|
|
220
|
-
"storage/index.d.ts": {
|
|
221
|
-
"size": 210,
|
|
222
|
-
"sha256": "bb4c3a0c73eb3e2629dd1a1dbc29eecedd1910a37b221357cc7981ced320bdeb"
|
|
223
|
-
},
|
|
224
|
-
"storage/index.js": {
|
|
225
|
-
"size": 166,
|
|
226
|
-
"sha256": "ed5e83e108cd15f9a3976be71e966bdf0c44d8e0266d1d2dbad189f0885ad501"
|
|
227
|
-
},
|
|
228
|
-
"types.d.ts": {
|
|
229
|
-
"size": 10037,
|
|
230
|
-
"sha256": "68a2de953af2fce1a12447078177ff886f10e853c760378e13478b2558648868"
|
|
231
|
-
},
|
|
232
|
-
"types.js": {
|
|
233
|
-
"size": 696,
|
|
234
|
-
"sha256": "1cc1b7f7ff4760e6b4ccd642f6aa2f35453c4f40e6a360c3a525304729407836"
|
|
235
|
-
},
|
|
236
|
-
"ui.d.ts": {
|
|
237
|
-
"size": 382,
|
|
238
|
-
"sha256": "d8b33d77c1c6ccd82e140db83a1bf57edb4d62c03cd15360c2c2d70bd2b392ee"
|
|
239
|
-
},
|
|
240
|
-
"ui.js": {
|
|
241
|
-
"size": 285,
|
|
242
|
-
"sha256": "3a3cef493f0b9789a7198da620fd7e72ea2377fed3eba25572bb0d222155a446"
|
|
243
|
-
},
|
|
244
|
-
"utils/authTag.d.ts": {
|
|
245
|
-
"size": 150,
|
|
246
|
-
"sha256": "db7ed89155df453650ad2805d8cd7069a70b14eacac2d97c4b0bebd45df4bdd4"
|
|
247
|
-
},
|
|
248
|
-
"utils/authTag.js": {
|
|
249
|
-
"size": 534,
|
|
250
|
-
"sha256": "0c506812967c17548162ce0f28d96089b023865883ee8cfd0824a94084580afb"
|
|
251
|
-
},
|
|
252
|
-
"utils/entryFilter.d.ts": {
|
|
253
|
-
"size": 183,
|
|
254
|
-
"sha256": "a7809e98f76b4e326262c26b0e43e278b1c50ac0b35fee145e3e6006357dc700"
|
|
255
|
-
},
|
|
256
|
-
"utils/entryFilter.js": {
|
|
257
|
-
"size": 4123,
|
|
258
|
-
"sha256": "de2690c6e5852969083387b469fd2e12f10470c6eee81120154437cd8d8f3555"
|
|
259
|
-
},
|
|
260
|
-
"utils/familyHash.d.ts": {
|
|
261
|
-
"size": 60,
|
|
262
|
-
"sha256": "c94f85390c52470df6946a39576c720ea92c89797ae62fff913191c45580248f"
|
|
263
|
-
},
|
|
264
|
-
"utils/familyHash.js": {
|
|
265
|
-
"size": 266,
|
|
266
|
-
"sha256": "f60526423e69fa5c461b0f5d8dac90b1f0c18149609cd1109226f1c8d985f223"
|
|
267
|
-
},
|
|
268
|
-
"utils/redact.d.ts": {
|
|
269
|
-
"size": 449,
|
|
270
|
-
"sha256": "b72d01ebac46a984d314905b14de5b05c3f9c27141e460c5305dd16e347f5a13"
|
|
271
|
-
},
|
|
272
|
-
"utils/redact.js": {
|
|
273
|
-
"size": 2646,
|
|
274
|
-
"sha256": "4e82eaa3bb48f9d621b70f69519b0615d992068eb9f836beaf6df6c2382c2cff"
|
|
275
|
-
},
|
|
276
|
-
"utils/requestFilter.d.ts": {
|
|
277
|
-
"size": 398,
|
|
278
|
-
"sha256": "fb214bde16e970c58ac23a32b51def87157a495a89e70ad6a1aa9e28c8c721c4"
|
|
279
|
-
},
|
|
280
|
-
"utils/requestFilter.js": {
|
|
281
|
-
"size": 1947,
|
|
282
|
-
"sha256": "214855796b6dbe524a357355fb7c9c8fd0fa9705d9163f7ad0882f463e0ae5b1"
|
|
283
|
-
},
|
|
284
|
-
"utils/stackFrame.d.ts": {
|
|
285
|
-
"size": 149,
|
|
286
|
-
"sha256": "55008bb0bf16e96c7b4f706fa3aa2d3a5bb3a68d0b8bcbd046d23462a7f620e8"
|
|
287
|
-
},
|
|
288
|
-
"utils/stackFrame.js": {
|
|
289
|
-
"size": 1413,
|
|
290
|
-
"sha256": "ca651d04eaea48a240ec7c5714a0f8f1d92f2fcdaa6e735df0009b56de8c29ed"
|
|
291
|
-
},
|
|
292
|
-
"watchers/AuthWatcher.d.ts": {
|
|
293
|
-
"size": 225,
|
|
294
|
-
"sha256": "b062850fa3edd3d58bb293025b1dfc5491e39807b3ab3e4cc1c1aaa31316a7a3"
|
|
295
|
-
},
|
|
296
|
-
"watchers/AuthWatcher.js": {
|
|
297
|
-
"size": 1437,
|
|
298
|
-
"sha256": "c47cca14113fed3825610c9a5a28a4ef7b99ea238952b3df48a997d63eab6fd2"
|
|
299
|
-
},
|
|
300
|
-
"watchers/BatchWatcher.d.ts": {
|
|
301
|
-
"size": 277,
|
|
302
|
-
"sha256": "b1870a793f2dc7ed22705c8a2a6b6f970fa1bcd0229dbf12f185323b35f3bdcf"
|
|
303
|
-
},
|
|
304
|
-
"watchers/BatchWatcher.js": {
|
|
305
|
-
"size": 1338,
|
|
306
|
-
"sha256": "113a1077d267734335483cdc48bf94e929edb11f5a0f3f83234bd4e7da8bf6ef"
|
|
307
|
-
},
|
|
308
|
-
"watchers/CacheWatcher.d.ts": {
|
|
309
|
-
"size": 314,
|
|
310
|
-
"sha256": "19b5f6fe4f0fc8f3df6762f4f46d36f198c7c7d7da8d3d23e5c8f124462e8cf7"
|
|
311
|
-
},
|
|
312
|
-
"watchers/CacheWatcher.js": {
|
|
313
|
-
"size": 2067,
|
|
314
|
-
"sha256": "8e038d3d72fcd69286674ec06b916389872eaa393dc7bfb8667b0979a68115a4"
|
|
315
|
-
},
|
|
316
|
-
"watchers/CommandWatcher.d.ts": {
|
|
317
|
-
"size": 267,
|
|
318
|
-
"sha256": "f1b3a3253e7265c7b56a74ba674cd23426ea5227a33abb1bde0d941e2a02e894"
|
|
319
|
-
},
|
|
320
|
-
"watchers/CommandWatcher.js": {
|
|
321
|
-
"size": 1553,
|
|
322
|
-
"sha256": "b341c7a0ad2a1d8d6d21e5a14b8151d904194d292c8ef1f3a80cf8d507fc3f2a"
|
|
323
|
-
},
|
|
324
|
-
"watchers/DumpWatcher.d.ts": {
|
|
325
|
-
"size": 308,
|
|
326
|
-
"sha256": "13f81df217258b0827027cbba35b5ad549453fe2709bd4fcc66d845b065500ec"
|
|
327
|
-
},
|
|
328
|
-
"watchers/DumpWatcher.js": {
|
|
329
|
-
"size": 1441,
|
|
330
|
-
"sha256": "36ea2e9a6c73dc96e75d31fd3c2710548ebfd0a651bab0dde185c33d611be079"
|
|
331
|
-
},
|
|
332
|
-
"watchers/EventWatcher.d.ts": {
|
|
333
|
-
"size": 223,
|
|
334
|
-
"sha256": "f5a173b0f92490e417d175011d4191d8eafe9ff75d712adb55cece5368753ef6"
|
|
335
|
-
},
|
|
336
|
-
"watchers/EventWatcher.js": {
|
|
337
|
-
"size": 1299,
|
|
338
|
-
"sha256": "832d5db66433f685eea7a3da208fb226b62eb49c22f94619762962a04e58b122"
|
|
339
|
-
},
|
|
340
|
-
"watchers/ExceptionWatcher.d.ts": {
|
|
341
|
-
"size": 311,
|
|
342
|
-
"sha256": "0f58c50fd77704151399ca6cb6ec7890a9aef86afe28235951971f8cc9c1d600"
|
|
343
|
-
},
|
|
344
|
-
"watchers/ExceptionWatcher.js": {
|
|
345
|
-
"size": 3816,
|
|
346
|
-
"sha256": "52d21188c499fa409fa50691fee3d27ea08ad93b26199d9a42c08e76217d6de2"
|
|
347
|
-
},
|
|
348
|
-
"watchers/GateWatcher.d.ts": {
|
|
349
|
-
"size": 262,
|
|
350
|
-
"sha256": "2fb8699f8679d2442aa322d40fb5cd4bb4e944804bdc6b094a9daf406a407abf"
|
|
351
|
-
},
|
|
352
|
-
"watchers/GateWatcher.js": {
|
|
353
|
-
"size": 1330,
|
|
354
|
-
"sha256": "e3666b5d65ead0ccd3fe7a6d684d3245dda9d3ddd6da393e0afa028585f08679"
|
|
355
|
-
},
|
|
356
|
-
"watchers/HttpClientWatcher.d.ts": {
|
|
357
|
-
"size": 346,
|
|
358
|
-
"sha256": "dfb13bba526d5338e4dcd7a5aa0f72a61a03d9e2f6a250250c0bb8f0054c9712"
|
|
359
|
-
},
|
|
360
|
-
"watchers/HttpClientWatcher.js": {
|
|
361
|
-
"size": 5898,
|
|
362
|
-
"sha256": "320b5a264f26bfeb29ba9246ffa65b79e244db715a4614d69a1425364062d5f9"
|
|
363
|
-
},
|
|
364
|
-
"watchers/HttpWatcher.d.ts": {
|
|
365
|
-
"size": 96,
|
|
366
|
-
"sha256": "ce9a95a670f755193fd74ce721dbfa4b30f20c879a6566ebb35229b3b2435429"
|
|
367
|
-
},
|
|
368
|
-
"watchers/HttpWatcher.js": {
|
|
369
|
-
"size": 6152,
|
|
370
|
-
"sha256": "b5af31b46a9a8754f6032fde78fc46e9ad7221977a0bfbbaa26e13214951ea0f"
|
|
371
|
-
},
|
|
372
|
-
"watchers/JobWatcher.d.ts": {
|
|
373
|
-
"size": 441,
|
|
374
|
-
"sha256": "097c043678ac6b218096c9b04bc5922fc8ed2a31e9f53abc36f6e0d6f63180f0"
|
|
375
|
-
},
|
|
376
|
-
"watchers/JobWatcher.js": {
|
|
377
|
-
"size": 3317,
|
|
378
|
-
"sha256": "494646d87c71d1fbf069835fcf10c56dec7b449e2fc1b24e0c82d511aba085e4"
|
|
379
|
-
},
|
|
380
|
-
"watchers/LogWatcher.d.ts": {
|
|
381
|
-
"size": 95,
|
|
382
|
-
"sha256": "f3ddc5f8b58c6c86ac6b464dd48e5a55e79ab2bf2e735feacffc7480e4ccc0c4"
|
|
383
|
-
},
|
|
384
|
-
"watchers/LogWatcher.js": {
|
|
385
|
-
"size": 3290,
|
|
386
|
-
"sha256": "0297479465b25f93ab0b11bfd6c2083afe9023fdddaa1b7841d12d68b294fa3e"
|
|
387
|
-
},
|
|
388
|
-
"watchers/MailWatcher.d.ts": {
|
|
389
|
-
"size": 244,
|
|
390
|
-
"sha256": "5031b96ef8e64a6d376576e8cddf1c2560f22432a78f1d2be55f7cea6bff4547"
|
|
391
|
-
},
|
|
392
|
-
"watchers/MailWatcher.js": {
|
|
393
|
-
"size": 1766,
|
|
394
|
-
"sha256": "2b583137bb9800901a7ae70cc1af6e9f8763215f0f05f170af9cfb4556530780"
|
|
395
|
-
},
|
|
396
|
-
"watchers/MiddlewareWatcher.d.ts": {
|
|
397
|
-
"size": 259,
|
|
398
|
-
"sha256": "5a28b472c835bd0f79ec9d3670516544bc5b6da9f1f1bed5159be0cba39304a1"
|
|
399
|
-
},
|
|
400
|
-
"watchers/MiddlewareWatcher.js": {
|
|
401
|
-
"size": 1510,
|
|
402
|
-
"sha256": "4ed2a81d8f7b7984f572d1bea16abd7a40a896de789e668def961e32bb8eea7f"
|
|
403
|
-
},
|
|
404
|
-
"watchers/ModelWatcher.d.ts": {
|
|
405
|
-
"size": 285,
|
|
406
|
-
"sha256": "4c05112af855a92b3f3f97c6b61bf1b07444bcb7d5a17f3e0ae19da4a85faf1c"
|
|
407
|
-
},
|
|
408
|
-
"watchers/ModelWatcher.js": {
|
|
409
|
-
"size": 1492,
|
|
410
|
-
"sha256": "ae4151b422eb73500f981c799e5a261d7349ad36b4be060a56e5ad7944e85cae"
|
|
411
|
-
},
|
|
412
|
-
"watchers/NotificationWatcher.d.ts": {
|
|
413
|
-
"size": 274,
|
|
414
|
-
"sha256": "a1d918122c5db9a7f27fdf78c0c14a61f6e1213748ee6f9b06f976f33589dc33"
|
|
415
|
-
},
|
|
416
|
-
"watchers/NotificationWatcher.js": {
|
|
417
|
-
"size": 1808,
|
|
418
|
-
"sha256": "06bbc437a9e5ec29252e365fa4707e68ae9348b3f755094c14f0e18c99dad3ed"
|
|
419
|
-
},
|
|
420
|
-
"watchers/QueryWatcher.d.ts": {
|
|
421
|
-
"size": 240,
|
|
422
|
-
"sha256": "5d5046c65e5b683369c7709f1acd09b60aec3e7f44748fd1baeb35498836465b"
|
|
423
|
-
},
|
|
424
|
-
"watchers/QueryWatcher.js": {
|
|
425
|
-
"size": 2855,
|
|
426
|
-
"sha256": "dcb9fe2049e71b5fc850286758737d80738a07dd470d96f36e418d4f54e16263"
|
|
427
|
-
},
|
|
428
|
-
"watchers/RedisWatcher.d.ts": {
|
|
429
|
-
"size": 294,
|
|
430
|
-
"sha256": "0a0f0ef387cb02a20cb9a4308a87b48dbfbf1076b7e3090801fef7c9c794ec84"
|
|
431
|
-
},
|
|
432
|
-
"watchers/RedisWatcher.js": {
|
|
433
|
-
"size": 1349,
|
|
434
|
-
"sha256": "bcafbadbbc6caa85284a384efa8894895c077588ebb5fb45f0f966d869caf960"
|
|
435
|
-
},
|
|
436
|
-
"watchers/ScheduleWatcher.d.ts": {
|
|
437
|
-
"size": 291,
|
|
438
|
-
"sha256": "1d049cfc2472876bf11c4d091c2a889b948bfb2ac714da2aed8affd965f311a6"
|
|
439
|
-
},
|
|
440
|
-
"watchers/ScheduleWatcher.js": {
|
|
441
|
-
"size": 1393,
|
|
442
|
-
"sha256": "f653c3728d928b253b7f4fd4e1afd228bedf4ce32c52f107effa99aa026ada45"
|
|
443
|
-
},
|
|
444
|
-
"watchers/ViewWatcher.d.ts": {
|
|
445
|
-
"size": 202,
|
|
446
|
-
"sha256": "980ac30b405d135cd754de1462722147944a37b4f5271ce769afb6b71fa748b1"
|
|
447
|
-
},
|
|
448
|
-
"watchers/ViewWatcher.js": {
|
|
449
|
-
"size": 1180,
|
|
450
|
-
"sha256": "9af344802c5973a020487e261009e8d1a19a74b78ba7b388d33ce50687277c81"
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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';
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { familyHash } from '../utils/familyHash.js';
|
|
2
|
-
const TABLE_ENTRIES = 'zin_trace_entries';
|
|
3
|
-
const TABLE_TAGS = 'zin_trace_entries_tags';
|
|
4
|
-
const TABLE_MONITORING = 'zin_trace_monitoring';
|
|
5
|
-
const generateUuid = () => crypto.randomUUID();
|
|
6
|
-
const rowToEntry = (row, tags) => ({
|
|
7
|
-
uuid: row.uuid,
|
|
8
|
-
batchId: row.batch_id,
|
|
9
|
-
familyHash: row.family_hash ?? undefined,
|
|
10
|
-
type: row.type,
|
|
11
|
-
content: JSON.parse(row.content),
|
|
12
|
-
tags,
|
|
13
|
-
isLatest: Boolean(row.is_latest),
|
|
14
|
-
createdAt: row.created_at,
|
|
15
|
-
});
|
|
16
|
-
const insertTags = async (db, uuid, tags) => {
|
|
17
|
-
if (tags.length === 0)
|
|
18
|
-
return;
|
|
19
|
-
await Promise.all(tags.map(async (tag) => {
|
|
20
|
-
await db.execute(`INSERT OR IGNORE INTO ${TABLE_TAGS} (entry_uuid, tag) VALUES (?, ?)`, [
|
|
21
|
-
uuid,
|
|
22
|
-
tag,
|
|
23
|
-
]);
|
|
24
|
-
}));
|
|
25
|
-
};
|
|
26
|
-
const buildEntryFilters = (opts) => {
|
|
27
|
-
const conditions = [];
|
|
28
|
-
const params = [];
|
|
29
|
-
if (opts.type) {
|
|
30
|
-
conditions.push('e.type = ?');
|
|
31
|
-
params.push(opts.type);
|
|
32
|
-
}
|
|
33
|
-
if (opts.batchId) {
|
|
34
|
-
conditions.push('e.batch_id = ?');
|
|
35
|
-
params.push(opts.batchId);
|
|
36
|
-
}
|
|
37
|
-
if (opts.from) {
|
|
38
|
-
conditions.push('e.created_at >= ?');
|
|
39
|
-
params.push(opts.from);
|
|
40
|
-
}
|
|
41
|
-
if (opts.to) {
|
|
42
|
-
conditions.push('e.created_at <= ?');
|
|
43
|
-
params.push(opts.to);
|
|
44
|
-
}
|
|
45
|
-
let joinClause = '';
|
|
46
|
-
if (opts.tag) {
|
|
47
|
-
joinClause = `INNER JOIN ${TABLE_TAGS} t ON t.entry_uuid = e.uuid AND t.tag = ?`;
|
|
48
|
-
params.unshift(opts.tag);
|
|
49
|
-
}
|
|
50
|
-
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
51
|
-
const countParams = opts.tag ? [opts.tag, ...params.slice(1)] : [...params];
|
|
52
|
-
return { joinClause, whereClause, params, countParams };
|
|
53
|
-
};
|
|
54
|
-
const loadTagsByUuid = async (db, uuids) => {
|
|
55
|
-
const tagsByUuid = new Map();
|
|
56
|
-
if (uuids.length === 0)
|
|
57
|
-
return tagsByUuid;
|
|
58
|
-
const tagRows = (await db.query(`SELECT entry_uuid, tag FROM ${TABLE_TAGS} WHERE entry_uuid IN (${uuids.map(() => '?').join(',')})`, uuids));
|
|
59
|
-
for (const tagRow of tagRows) {
|
|
60
|
-
const tags = tagsByUuid.get(tagRow.entry_uuid) ?? [];
|
|
61
|
-
tags.push(tagRow.tag);
|
|
62
|
-
tagsByUuid.set(tagRow.entry_uuid, tags);
|
|
63
|
-
}
|
|
64
|
-
return tagsByUuid;
|
|
65
|
-
};
|
|
66
|
-
// The storage facade intentionally groups related DB operations in one factory.
|
|
67
|
-
// eslint-disable-next-line max-lines-per-function
|
|
68
|
-
const createStorage = (db) => {
|
|
69
|
-
const writeEntry = async (entry) => {
|
|
70
|
-
const uuid = entry.uuid || generateUuid();
|
|
71
|
-
await db.execute(`INSERT INTO ${TABLE_ENTRIES} (uuid, batch_id, family_hash, type, content, is_latest, created_at)
|
|
72
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)`, [
|
|
73
|
-
uuid,
|
|
74
|
-
entry.batchId,
|
|
75
|
-
entry.familyHash ?? null,
|
|
76
|
-
entry.type,
|
|
77
|
-
JSON.stringify(entry.content),
|
|
78
|
-
entry.isLatest ? 1 : 0,
|
|
79
|
-
entry.createdAt,
|
|
80
|
-
]);
|
|
81
|
-
await insertTags(db, uuid, entry.tags);
|
|
82
|
-
};
|
|
83
|
-
const updateEntry = async (uuid, patch) => {
|
|
84
|
-
const sets = [];
|
|
85
|
-
const params = [];
|
|
86
|
-
if (patch.content !== undefined) {
|
|
87
|
-
sets.push('content = ?');
|
|
88
|
-
params.push(JSON.stringify(patch.content));
|
|
89
|
-
}
|
|
90
|
-
if (patch.isLatest !== undefined) {
|
|
91
|
-
sets.push('is_latest = ?');
|
|
92
|
-
params.push(patch.isLatest ? 1 : 0);
|
|
93
|
-
}
|
|
94
|
-
if (sets.length === 0)
|
|
95
|
-
return;
|
|
96
|
-
params.push(uuid);
|
|
97
|
-
await db.execute(`UPDATE ${TABLE_ENTRIES} SET ${sets.join(', ')} WHERE uuid = ?`, params);
|
|
98
|
-
};
|
|
99
|
-
const markFamilyStale = async (hash, exceptUuid) => {
|
|
100
|
-
await db.execute(`UPDATE ${TABLE_ENTRIES} SET is_latest = 0
|
|
101
|
-
WHERE family_hash = ? AND uuid != ? AND is_latest = 1`, [hash, exceptUuid]);
|
|
102
|
-
};
|
|
103
|
-
const queryEntries = async (opts) => {
|
|
104
|
-
const page = opts.page ?? 1;
|
|
105
|
-
const perPage = opts.perPage ?? 50;
|
|
106
|
-
const offset = (page - 1) * perPage;
|
|
107
|
-
const { joinClause, whereClause, params, countParams } = buildEntryFilters(opts);
|
|
108
|
-
const countResult = (await db.queryOne(`SELECT COUNT(*) as cnt FROM ${TABLE_ENTRIES} e ${joinClause} ${whereClause}`, countParams));
|
|
109
|
-
const total = countResult?.cnt ?? 0;
|
|
110
|
-
const rows = (await db.query(`SELECT e.id, e.uuid, e.batch_id, e.family_hash, e.type, e.content, e.is_latest, e.created_at
|
|
111
|
-
FROM ${TABLE_ENTRIES} e ${joinClause} ${whereClause}
|
|
112
|
-
ORDER BY e.created_at DESC, e.id DESC
|
|
113
|
-
LIMIT ? OFFSET ?`, [...params, perPage, offset]));
|
|
114
|
-
const tagsByUuid = await loadTagsByUuid(db, rows.map((row) => row.uuid));
|
|
115
|
-
return {
|
|
116
|
-
data: rows.map((row) => rowToEntry(row, tagsByUuid.get(row.uuid) ?? [])),
|
|
117
|
-
total,
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
|
-
const getEntry = async (uuid) => {
|
|
121
|
-
const row = (await db.queryOne(`SELECT id, uuid, batch_id, family_hash, type, content, is_latest, created_at
|
|
122
|
-
FROM ${TABLE_ENTRIES}
|
|
123
|
-
WHERE uuid = ?`, [uuid]));
|
|
124
|
-
if (!row)
|
|
125
|
-
return null;
|
|
126
|
-
const tags = (await db.query(`SELECT tag FROM ${TABLE_TAGS} WHERE entry_uuid = ?`, [
|
|
127
|
-
uuid,
|
|
128
|
-
]));
|
|
129
|
-
return rowToEntry(row, tags.map((tag) => tag.tag));
|
|
130
|
-
};
|
|
131
|
-
const getBatch = async (batchId) => {
|
|
132
|
-
const rows = (await db.query(`SELECT id, uuid, batch_id, family_hash, type, content, is_latest, created_at
|
|
133
|
-
FROM ${TABLE_ENTRIES}
|
|
134
|
-
WHERE batch_id = ?
|
|
135
|
-
ORDER BY created_at ASC, id ASC`, [batchId]));
|
|
136
|
-
if (rows.length === 0)
|
|
137
|
-
return [];
|
|
138
|
-
const tagsByUuid = await loadTagsByUuid(db, rows.map((row) => row.uuid));
|
|
139
|
-
return rows.map((row) => rowToEntry(row, tagsByUuid.get(row.uuid) ?? []));
|
|
140
|
-
};
|
|
141
|
-
const prune = async (olderThanMs, keepExceptions = false) => {
|
|
142
|
-
const countResult = (await db.queryOne(`SELECT COUNT(*) as cnt FROM ${TABLE_ENTRIES}
|
|
143
|
-
WHERE created_at < ?
|
|
144
|
-
${keepExceptions ? "AND type != 'exception'" : ''}`, [olderThanMs]));
|
|
145
|
-
const deleted = countResult?.cnt ?? 0;
|
|
146
|
-
if (deleted === 0)
|
|
147
|
-
return 0;
|
|
148
|
-
await db.execute(`DELETE FROM ${TABLE_ENTRIES}
|
|
149
|
-
WHERE created_at < ?
|
|
150
|
-
${keepExceptions ? "AND type != 'exception'" : ''}`, [olderThanMs]);
|
|
151
|
-
return deleted;
|
|
152
|
-
};
|
|
153
|
-
const clear = async () => {
|
|
154
|
-
await db.execute(`DELETE FROM ${TABLE_ENTRIES}`, []);
|
|
155
|
-
};
|
|
156
|
-
const getMonitoring = async () => {
|
|
157
|
-
const rows = (await db.query(`SELECT tag FROM ${TABLE_MONITORING}`, []));
|
|
158
|
-
return rows.map((row) => row.tag);
|
|
159
|
-
};
|
|
160
|
-
const addMonitoring = async (tag) => {
|
|
161
|
-
await db.execute(`INSERT OR IGNORE INTO ${TABLE_MONITORING} (tag) VALUES (?)`, [tag]);
|
|
162
|
-
};
|
|
163
|
-
const removeMonitoring = async (tag) => {
|
|
164
|
-
await db.execute(`DELETE FROM ${TABLE_MONITORING} WHERE tag = ?`, [tag]);
|
|
165
|
-
};
|
|
166
|
-
const stats = async () => {
|
|
167
|
-
const rows = (await db.query(`SELECT type, COUNT(*) as cnt FROM ${TABLE_ENTRIES} GROUP BY type`, []));
|
|
168
|
-
const output = {};
|
|
169
|
-
for (const row of rows) {
|
|
170
|
-
output[row.type] = row.cnt;
|
|
171
|
-
}
|
|
172
|
-
return output;
|
|
173
|
-
};
|
|
174
|
-
return {
|
|
175
|
-
writeEntry,
|
|
176
|
-
updateEntry,
|
|
177
|
-
markFamilyStale,
|
|
178
|
-
queryEntries,
|
|
179
|
-
getEntry,
|
|
180
|
-
getBatch,
|
|
181
|
-
prune,
|
|
182
|
-
clear,
|
|
183
|
-
getMonitoring,
|
|
184
|
-
addMonitoring,
|
|
185
|
-
removeMonitoring,
|
|
186
|
-
stats,
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
const resolveStorage = (db) => {
|
|
190
|
-
return createStorage(db);
|
|
191
|
-
};
|
|
192
|
-
const reset = () => {
|
|
193
|
-
return;
|
|
194
|
-
};
|
|
195
|
-
export const TraceStorage = Object.freeze({ resolveStorage, reset, familyHash });
|