@zintrust/trace 0.4.75 → 0.4.77

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.
Files changed (73) hide show
  1. package/README.md +101 -15
  2. package/dist/build-manifest.json +210 -162
  3. package/dist/config.d.ts +1 -0
  4. package/dist/config.js +123 -4
  5. package/dist/dashboard/routes.js +4 -4
  6. package/dist/dashboard/ui.js +80 -23
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.js +30 -25
  9. package/dist/migrations/{20260331000001_create_zin_debugger_entries_table.d.ts → 20260331000001_create_zin_trace_entries_table.d.ts} +2 -2
  10. package/dist/migrations/{20260331000001_create_zin_debugger_entries_table.js → 20260331000001_create_zin_trace_entries_table.js} +5 -5
  11. package/dist/migrations/{20260331000002_create_zin_debugger_entries_tags_table.d.ts → 20260331000002_create_zin_trace_entries_tags_table.d.ts} +2 -2
  12. package/dist/migrations/{20260331000002_create_zin_debugger_entries_tags_table.js → 20260331000002_create_zin_trace_entries_tags_table.js} +5 -5
  13. package/dist/migrations/{20260331000003_create_zin_debugger_monitoring_table.d.ts → 20260331000003_create_zin_trace_monitoring_table.d.ts} +2 -2
  14. package/dist/migrations/{20260331000003_create_zin_debugger_monitoring_table.js → 20260331000003_create_zin_trace_monitoring_table.js} +4 -4
  15. package/dist/migrations/20260407193000_widen_trace_created_at_for_sql.d.ts +10 -0
  16. package/dist/migrations/20260407193000_widen_trace_created_at_for_sql.js +34 -0
  17. package/dist/migrations/index.d.ts +3 -3
  18. package/dist/migrations/index.js +5 -4
  19. package/dist/register.js +130 -32
  20. package/dist/storage/DebuggerStorage.js +1 -1
  21. package/dist/storage/TraceContentRedaction.d.ts +4 -0
  22. package/dist/storage/TraceContentRedaction.js +33 -0
  23. package/dist/storage/TraceEntryFiltering.d.ts +4 -0
  24. package/dist/storage/TraceEntryFiltering.js +13 -0
  25. package/dist/storage/TraceStorage.js +36 -6
  26. package/dist/storage/TraceWriteDiagnostics.d.ts +19 -0
  27. package/dist/storage/TraceWriteDiagnostics.js +98 -0
  28. package/dist/storage/index.js +1 -1
  29. package/dist/types.d.ts +37 -20
  30. package/dist/ui.js +1 -1
  31. package/dist/utils/authTag.js +1 -1
  32. package/dist/utils/entryFilter.d.ts +4 -0
  33. package/dist/utils/entryFilter.js +95 -0
  34. package/dist/utils/redact.d.ts +1 -0
  35. package/dist/utils/redact.js +43 -9
  36. package/dist/utils/requestFilter.js +1 -1
  37. package/dist/watchers/AuthWatcher.js +3 -3
  38. package/dist/watchers/BatchWatcher.js +3 -3
  39. package/dist/watchers/CacheWatcher.js +5 -5
  40. package/dist/watchers/CommandWatcher.js +5 -5
  41. package/dist/watchers/DumpWatcher.js +3 -3
  42. package/dist/watchers/EventWatcher.js +4 -4
  43. package/dist/watchers/ExceptionWatcher.js +6 -6
  44. package/dist/watchers/GateWatcher.js +3 -3
  45. package/dist/watchers/HttpClientWatcher.js +6 -6
  46. package/dist/watchers/HttpWatcher.js +108 -24
  47. package/dist/watchers/JobWatcher.js +4 -4
  48. package/dist/watchers/LogWatcher.js +5 -4
  49. package/dist/watchers/MailWatcher.js +3 -3
  50. package/dist/watchers/MiddlewareWatcher.js +3 -3
  51. package/dist/watchers/ModelWatcher.js +3 -3
  52. package/dist/watchers/NotificationWatcher.js +4 -4
  53. package/dist/watchers/QueryWatcher.js +5 -5
  54. package/dist/watchers/RedisWatcher.js +4 -4
  55. package/dist/watchers/ScheduleWatcher.js +3 -3
  56. package/dist/watchers/ViewWatcher.js +3 -3
  57. package/package.json +4 -4
  58. package/src/config.ts +152 -5
  59. package/src/dashboard/routes.ts +6 -2
  60. package/src/dashboard/ui.ts +80 -23
  61. package/src/index.ts +7 -0
  62. package/src/register.ts +137 -10
  63. package/src/storage/TraceContentRedaction.ts +44 -0
  64. package/src/storage/TraceEntryFiltering.ts +14 -0
  65. package/src/storage/TraceStorage.ts +52 -5
  66. package/src/storage/TraceWriteDiagnostics.ts +174 -0
  67. package/src/types.ts +40 -20
  68. package/src/utils/entryFilter.ts +108 -0
  69. package/src/utils/redact.ts +57 -9
  70. package/src/watchers/CommandWatcher.ts +1 -1
  71. package/src/watchers/HttpClientWatcher.ts +1 -1
  72. package/src/watchers/HttpWatcher.ts +132 -21
  73. package/src/watchers/LogWatcher.ts +27 -27
package/README.md CHANGED
@@ -9,7 +9,7 @@ Works with both `zin s` (Node.js) and `zin s --wg` (Cloudflare Workers).
9
9
  ## Installation
10
10
 
11
11
  ```bash
12
- yarn add @zintrust/trace
12
+ npm install @zintrust/trace
13
13
  ```
14
14
 
15
15
  Run the provided migrations to create the three required tables (`zin_trace_entries`, `zin_trace_entries_tags`, `zin_trace_monitoring`):
@@ -63,7 +63,44 @@ Why this is the preferred path:
63
63
  - The core runtime can then lazy-load the trace only after databases and the kernel are ready.
64
64
  - The plugin activates trace runtime logic only; the dashboard route stays inactive until you register it yourself.
65
65
 
66
- With the stock ZinTrust bootstrap, `TRACE_ENABLED=true` plus the plugin import above activates the watchers and storage integration. Dashboard UI/routes are a separate route-level opt-in.
66
+ With the stock ZinTrust bootstrap, `TRACE_ENABLED=true` plus the plugin import above activates the watchers and storage integration. Dashboard UI/routes are still a separate opt-in unless you also set `TRACE_AUTO_MOUNT=true`.
67
+
68
+ ### Optional: configure filters in `config/trace.ts`
69
+
70
+ If you prefer project-owned trace configuration over env-only setup, put the filter rules directly in `config/trace.ts`.
71
+
72
+ ```ts
73
+ // config/trace.ts
74
+ import { Env } from '@config/env';
75
+ import type { TraceConfigOverrides } from '@zintrust/trace';
76
+
77
+ export default {
78
+ enabled: Env.getBool('TRACE_ENABLED', false),
79
+ connection: Env.get('TRACE_DB_CONNECTION', '') || undefined,
80
+ pruneAfterHours: Env.getInt('TRACE_PRUNE_HOURS', 24),
81
+ slowQueryThreshold: Env.getInt('TRACE_SLOW_QUERY_MS', 100),
82
+ logMinLevel: Env.get('TRACE_LOG_LEVEL', 'info') as TraceConfigOverrides['logMinLevel'],
83
+ watchers: {
84
+ request: {
85
+ get: { exclude: ['report'] },
86
+ post: { include: ['auth'] },
87
+ patch: { include: ['profile'] },
88
+ delete: { exclude: ['internal'] },
89
+ },
90
+ log: { exclude: ['healthcheck'] },
91
+ exception: { include: ['trace'] },
92
+ cache: { include: ['session:'] },
93
+ },
94
+ redaction: {
95
+ keys: ['password', 'token', 'secret'],
96
+ headers: ['authorization', 'cookie'],
97
+ body: ['password', 'token', 'secret'],
98
+ query: [],
99
+ },
100
+ } satisfies TraceConfigOverrides;
101
+ ```
102
+
103
+ All include/exclude matching is contains-based, so a term like `report` matches `/reports/daily`, `monthly-report`, or any other trace content containing that fragment.
67
104
 
68
105
  ### 3. Mount the dashboard
69
106
 
@@ -98,6 +135,19 @@ registerTraceRoutes(router, TraceStorage.resolveStorage(db), {
98
135
 
99
136
  If you need a manual late bootstrap instead of plugin-driven activation, you can still import `@zintrust/trace/register` yourself, but that is the advanced path rather than the default project setup.
100
137
 
138
+ ### 4. Optional stock-bootstrap auto-mount
139
+
140
+ If you want core to expose the trace dashboard without editing your route file, opt in explicitly:
141
+
142
+ ```env
143
+ TRACE_ENABLED=true
144
+ TRACE_AUTO_MOUNT=true
145
+ TRACE_BASE_PATH=/trace
146
+ TRACE_MIDDLEWARE=auth,admin
147
+ ```
148
+
149
+ When `TRACE_AUTO_MOUNT=true`, ZinTrust calls `registerTraceDashboard(...)` during bootstrap using `TRACE_BASE_PATH` and the optional comma-separated `TRACE_MIDDLEWARE` list. Keep this off if you want route ownership to stay fully in application code.
150
+
101
151
  ## CLI commands
102
152
 
103
153
  When the optional package is installed, ZinTrust auto-registers these commands:
@@ -111,6 +161,14 @@ zin trace:clear
111
161
 
112
162
  `zin trace:status` reports the active connection, retention window, current entry counts, and the expected dashboard URL derived from your current env and route choices.
113
163
 
164
+ ### Monitoring tags
165
+
166
+ The Monitoring page lets you save a short list of tags that you filter by often.
167
+
168
+ - Add tags like `auth`, `checkout`, `queue:emails`, or `nightly-sync` once, then click them later to jump straight to matching entries.
169
+ - Monitoring tags are just saved dashboard shortcuts. Removing a monitoring tag does not delete trace entries or strip tags from stored data.
170
+ - Use short, exact tag names. The dashboard filters entries by the exact tag value you click.
171
+
114
172
  ---
115
173
 
116
174
  ## Watchers
@@ -164,6 +222,16 @@ const config = TraceConfig.merge({
164
222
  // disable specific watchers
165
223
  redis: false,
166
224
  view: false,
225
+ request: {
226
+ get: { exclude: ['report'] },
227
+ post: { include: ['auth'] },
228
+ },
229
+ log: {
230
+ exclude: ['healthcheck'],
231
+ },
232
+ exception: {
233
+ include: ['trace'],
234
+ },
167
235
  },
168
236
  redaction: {
169
237
  body: ['password', 'secret', 'token'],
@@ -184,18 +252,36 @@ ExceptionWatcher.register({ storage, config, db });
184
252
 
185
253
  `TraceConfig.merge(overrides?)` accepts the following options:
186
254
 
187
- | Option | Type | Default | Description |
188
- | -------------------- | --------------------------------------------------- | ---------------------------------- | -------------------------------------------------------------------- |
189
- | `enabled` | `boolean` | `false` | Master switch — no watchers activate when `false` |
190
- | `connection` | `string \| undefined` | `undefined` | Named DB connection for storing entries; uses `'default'` if omitted |
191
- | `pruneAfterHours` | `number` | `24` | Entries older than this are pruned |
192
- | `slowQueryThreshold` | `number` | `100` | Queries taking longer (ms) are flagged as slow |
193
- | `logMinLevel` | `'debug' \| 'info' \| 'warn' \| 'error' \| 'fatal'` | `'info'` | Minimum log severity captured |
194
- | `ignoreRoutes` | `string[]` | `['/trace', '/health', '/ping']` | Routes excluded from HTTP watcher |
195
- | `watchers` | `Record<string, boolean>` | `{}` | Per-watcher enable/disable flags (`false` = disabled) |
196
- | `redaction.headers` | `string[]` | `['authorization', 'cookie', ...]` | Request header names to redact |
197
- | `redaction.body` | `string[]` | `['password', 'token', ...]` | Request body keys to redact |
198
- | `redaction.query` | `string[]` | `[]` | Query-string keys to redact |
255
+ | Option | Type | Default | Description |
256
+ | -------------------- | --------------------------------------------------- | ---------------------------------- | ---------------------------------------------------------------------------- |
257
+ | `enabled` | `boolean` | `false` | Master switch — no watchers activate when `false` |
258
+ | `connection` | `string \| undefined` | `undefined` | Named DB connection for storing entries; uses `'default'` if omitted |
259
+ | `pruneAfterHours` | `number` | `24` | Entries older than this are pruned |
260
+ | `slowQueryThreshold` | `number` | `100` | Queries taking longer (ms) are flagged as slow |
261
+ | `logMinLevel` | `'debug' \| 'info' \| 'warn' \| 'error' \| 'fatal'` | `'info'` | Minimum log severity captured |
262
+ | `ignoreRoutes` | `string[]` | `['/trace', '/health', '/ping']` | Routes excluded from HTTP watcher |
263
+ | `watchers` | `Record<string, boolean \| { include?, exclude? }>` | `{}` | Per-watcher enable/disable flags plus contains-based include/exclude filters |
264
+ | `redaction.keys` | `string[]` | common auth/card/session keys | Extra sensitive keys redacted recursively before trace persistence |
265
+ | `redaction.headers` | `string[]` | `['authorization', 'cookie', ...]` | Request header names to redact |
266
+ | `redaction.body` | `string[]` | `['password', 'token', ...]` | Request body keys to redact |
267
+ | `redaction.query` | `string[]` | `[]` | Query-string keys to redact |
268
+
269
+ Request watcher filters can also be scoped per method. Matching is contains-based against the stored trace content, so values like `report`, `auth`, or `trace` match any request or entry whose content includes those fragments.
270
+
271
+ ```ts
272
+ const config = TraceConfig.merge({
273
+ watchers: {
274
+ request: {
275
+ get: { exclude: ['report'] },
276
+ post: { include: ['auth'] },
277
+ patch: { include: ['profile'] },
278
+ },
279
+ log: { exclude: ['healthcheck'] },
280
+ exception: { include: ['trace'] },
281
+ cache: { include: ['session:'] },
282
+ },
283
+ });
284
+ ```
199
285
 
200
286
  ---
201
287
 
@@ -275,7 +361,7 @@ import {
275
361
  ## Security considerations
276
362
 
277
363
  - **Always** protect the dashboard with middleware (e.g. `middleware: ['admin']`). `@zintrust/trace/ui` exports `registerTraceDashboard(...)` and `registerTraceRoutes(...)`, and neither applies any authentication by default.
278
- - Sensitive fields in request headers and body are redacted using the `redaction` config before being stored. Review and extend the default redaction lists to match your application's data model.
364
+ - Sensitive fields are redacted using the `redaction` config before they are stored. Review and extend the default `redaction.keys`, `redaction.headers`, `redaction.body`, and `redaction.query` lists to match your application's data model.
279
365
  - Use a **dedicated database connection** (`TRACE_DB_CONNECTION`) in production so trace writes cannot impact your primary DB connection pool.
280
366
  - Keep `TRACE_ENABLED=false` (or unset) in production unless actively investigating an issue.
281
367