@zintrust/trace 1.6.1 → 1.6.3

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 (50) hide show
  1. package/dist/register.js +19 -15
  2. package/package.json +2 -3
  3. package/src/TraceConnection.ts +0 -182
  4. package/src/cli-register.ts +0 -63
  5. package/src/config.ts +0 -383
  6. package/src/context.ts +0 -101
  7. package/src/dashboard/handlers.ts +0 -353
  8. package/src/dashboard/routes.ts +0 -114
  9. package/src/dashboard/ui.ts +0 -1262
  10. package/src/dashboard/zintrust-debuger.svg +0 -30
  11. package/src/index.ts +0 -102
  12. package/src/ingest/TraceIngestGateway.ts +0 -414
  13. package/src/plugin.ts +0 -9
  14. package/src/register.ts +0 -659
  15. package/src/storage/ProxyTraceStorage.ts +0 -190
  16. package/src/storage/TraceContentBudget.ts +0 -491
  17. package/src/storage/TraceContentRedaction.ts +0 -44
  18. package/src/storage/TraceEntryFiltering.ts +0 -92
  19. package/src/storage/TraceServiceTag.ts +0 -56
  20. package/src/storage/TraceStorage.ts +0 -543
  21. package/src/storage/TraceWriteDiagnostics.ts +0 -289
  22. package/src/storage/index.ts +0 -4
  23. package/src/types.ts +0 -430
  24. package/src/ui.ts +0 -9
  25. package/src/utils/authTag.ts +0 -20
  26. package/src/utils/entryFilter.ts +0 -131
  27. package/src/utils/familyHash.ts +0 -8
  28. package/src/utils/redact.ts +0 -112
  29. package/src/utils/requestFilter.ts +0 -79
  30. package/src/utils/stackFrame.ts +0 -44
  31. package/src/watchers/AuthWatcher.ts +0 -53
  32. package/src/watchers/BatchWatcher.ts +0 -55
  33. package/src/watchers/CacheWatcher.ts +0 -72
  34. package/src/watchers/CommandWatcher.ts +0 -58
  35. package/src/watchers/DumpWatcher.ts +0 -45
  36. package/src/watchers/EventWatcher.ts +0 -46
  37. package/src/watchers/ExceptionWatcher.ts +0 -130
  38. package/src/watchers/GateWatcher.ts +0 -53
  39. package/src/watchers/HttpClientWatcher.ts +0 -219
  40. package/src/watchers/HttpWatcher.ts +0 -220
  41. package/src/watchers/JobWatcher.ts +0 -124
  42. package/src/watchers/LogWatcher.ts +0 -120
  43. package/src/watchers/MailWatcher.ts +0 -65
  44. package/src/watchers/MiddlewareWatcher.ts +0 -54
  45. package/src/watchers/ModelWatcher.ts +0 -60
  46. package/src/watchers/NotificationWatcher.ts +0 -60
  47. package/src/watchers/QueryWatcher.ts +0 -107
  48. package/src/watchers/RedisWatcher.ts +0 -42
  49. package/src/watchers/ScheduleWatcher.ts +0 -57
  50. package/src/watchers/ViewWatcher.ts +0 -40
@@ -1,44 +0,0 @@
1
- import type { ITraceEntry, ITraceStorage, RedactionConfig } from '../types';
2
- import { redactUnknown } from '../utils/redact';
3
-
4
- const collectRedactionFields = (redaction: RedactionConfig): string[] => {
5
- return [
6
- ...new Set([...redaction.keys, ...redaction.headers, ...redaction.body, ...redaction.query]),
7
- ];
8
- };
9
-
10
- const redactTraceEntry = (entry: ITraceEntry, redaction: RedactionConfig): ITraceEntry => {
11
- return {
12
- ...entry,
13
- content: redactUnknown(entry.content, collectRedactionFields(redaction)),
14
- };
15
- };
16
-
17
- const redactTracePatch = (
18
- patch: Partial<Pick<ITraceEntry, 'content' | 'isLatest'>>,
19
- redaction: RedactionConfig
20
- ): Partial<Pick<ITraceEntry, 'content' | 'isLatest'>> => {
21
- if (patch.content === undefined) return patch;
22
-
23
- return {
24
- ...patch,
25
- content: redactUnknown(patch.content, collectRedactionFields(redaction)),
26
- };
27
- };
28
-
29
- export const TraceContentRedaction = Object.freeze({
30
- wrapStorage(storage: ITraceStorage, redaction: RedactionConfig): ITraceStorage {
31
- return Object.freeze({
32
- ...storage,
33
- writeEntry: async (entry: ITraceEntry): Promise<void> => {
34
- await storage.writeEntry(redactTraceEntry(entry, redaction));
35
- },
36
- updateEntry: async (
37
- uuid: string,
38
- patch: Partial<Pick<ITraceEntry, 'content' | 'isLatest'>>
39
- ): Promise<void> => {
40
- await storage.updateEntry(uuid, redactTracePatch(patch, redaction));
41
- },
42
- });
43
- },
44
- });
@@ -1,92 +0,0 @@
1
- import { TraceContext } from '../context';
2
- import type { ITraceConfig, ITraceEntry, ITraceStorage } from '../types';
3
- import { EntryType } from '../types';
4
- import { TraceEntryFilter } from '../utils/entryFilter';
5
- import { RequestFilter } from '../utils/requestFilter';
6
-
7
- const MAX_IGNORED_BATCHES = 512;
8
-
9
- interface IIgnoredBatchTracker {
10
- has(batchId: string): boolean;
11
- remember(batchId: string): void;
12
- }
13
-
14
- const isObjectValue = (value: unknown): value is Record<string, unknown> => {
15
- return typeof value === 'object' && value !== null && !Array.isArray(value);
16
- };
17
-
18
- const getEntryUri = (entry: ITraceEntry): string | undefined => {
19
- if (entry.type !== EntryType.REQUEST) return undefined;
20
-
21
- const content = isObjectValue(entry.content) ? entry.content : undefined;
22
- const uri = content?.['uri'];
23
- return typeof uri === 'string' && uri.trim() !== '' ? uri : undefined;
24
- };
25
-
26
- const createIgnoredBatchTracker = (): IIgnoredBatchTracker => {
27
- const ignoredBatchIds = new Set<string>();
28
- const ignoredBatchOrder: string[] = [];
29
-
30
- const remember = (batchId: string): void => {
31
- if (ignoredBatchIds.has(batchId)) return;
32
-
33
- ignoredBatchIds.add(batchId);
34
- ignoredBatchOrder.push(batchId);
35
-
36
- if (ignoredBatchOrder.length <= MAX_IGNORED_BATCHES) return;
37
-
38
- const evictedBatchId = ignoredBatchOrder.shift();
39
- if (evictedBatchId !== undefined) {
40
- ignoredBatchIds.delete(evictedBatchId);
41
- }
42
- };
43
-
44
- const has = (batchId: string): boolean => {
45
- return ignoredBatchIds.has(batchId);
46
- };
47
-
48
- return Object.freeze({ has, remember });
49
- };
50
-
51
- const shouldDropForIgnoredRequest = (
52
- entry: ITraceEntry,
53
- config: ITraceConfig,
54
- tracker: IIgnoredBatchTracker
55
- ): boolean => {
56
- if (tracker.has(entry.batchId)) {
57
- return true;
58
- }
59
-
60
- const currentPath = TraceContext.getRequestPath();
61
- if (
62
- typeof currentPath === 'string' &&
63
- currentPath !== '' &&
64
- RequestFilter.matchesIgnoredPath(currentPath, config)
65
- ) {
66
- tracker.remember(entry.batchId);
67
- return true;
68
- }
69
-
70
- const uri = getEntryUri(entry);
71
- if (typeof uri === 'string' && RequestFilter.matchesIgnoredPath(uri, config)) {
72
- tracker.remember(entry.batchId);
73
- return true;
74
- }
75
-
76
- return false;
77
- };
78
-
79
- export const TraceEntryFiltering = Object.freeze({
80
- wrapStorage(storage: ITraceStorage, config: ITraceConfig): ITraceStorage {
81
- const ignoredBatchTracker = createIgnoredBatchTracker();
82
-
83
- return Object.freeze({
84
- ...storage,
85
- async writeEntry(entry: ITraceEntry): Promise<void> {
86
- if (shouldDropForIgnoredRequest(entry, config, ignoredBatchTracker)) return;
87
- if (!TraceEntryFilter.shouldCapture(entry, config)) return;
88
- await storage.writeEntry(entry);
89
- },
90
- });
91
- },
92
- });
@@ -1,56 +0,0 @@
1
- import { ErrorFactory } from '@zintrust/core';
2
- import type { ITraceConfig, ITraceEntry, ITraceStorage } from '../types';
3
-
4
- const appendServiceTag = (entry: ITraceEntry, serviceTag?: string): ITraceEntry => {
5
- const normalizedTag = serviceTag?.trim() ?? '';
6
- if (normalizedTag === '' || entry.tags.includes(normalizedTag)) {
7
- return entry;
8
- }
9
-
10
- return {
11
- ...entry,
12
- tags: [...entry.tags, normalizedTag],
13
- };
14
- };
15
-
16
- const unsupportedRead = async <T>(): Promise<T> => {
17
- throw ErrorFactory.createConfigError(
18
- 'Trace proxy mode only supports runtime persistence on the sender. Query the trace server database or dashboard directly.'
19
- );
20
- };
21
-
22
- const bindOrUnsupported = <T extends (...args: never[]) => Promise<unknown>>(
23
- method: T | undefined
24
- ): T => {
25
- if (method === undefined) {
26
- return unsupportedRead as unknown as T;
27
- }
28
-
29
- return method;
30
- };
31
-
32
- export const TraceServiceTag = Object.freeze({
33
- wrapStorage(storage: ITraceStorage, config: ITraceConfig): ITraceStorage {
34
- const writeEntry = async (entry: ITraceEntry): Promise<void> => {
35
- await storage.writeEntry(appendServiceTag(entry, config.serviceTag));
36
- };
37
-
38
- return Object.freeze({
39
- writeEntry,
40
- updateEntry: storage.updateEntry.bind(storage),
41
- markFamilyStale: storage.markFamilyStale.bind(storage),
42
- queryEntries: bindOrUnsupported(storage.queryEntries?.bind(storage)),
43
- getEntry: bindOrUnsupported(storage.getEntry?.bind(storage)),
44
- getBatch: bindOrUnsupported(storage.getBatch?.bind(storage)),
45
- queryBatchEntries: bindOrUnsupported(storage.queryBatchEntries?.bind(storage)),
46
- prune: bindOrUnsupported(storage.prune?.bind(storage)),
47
- clear: bindOrUnsupported(storage.clear?.bind(storage)),
48
- getMonitoring: bindOrUnsupported(storage.getMonitoring?.bind(storage)),
49
- addMonitoring: bindOrUnsupported(storage.addMonitoring?.bind(storage)),
50
- removeMonitoring: bindOrUnsupported(storage.removeMonitoring?.bind(storage)),
51
- stats: bindOrUnsupported(storage.stats?.bind(storage)),
52
- });
53
- },
54
- });
55
-
56
- export default TraceServiceTag;