@zintrust/trace 0.4.79 → 0.4.82

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,22 +1,35 @@
1
1
  /**
2
- * MailWatcher — records mail dispatch intent.
3
- * Body is never captured; only to/subject/template.
2
+ * MailWatcher — records mail dispatch intent and rendered content.
4
3
  */
5
4
  import { TraceContext } from '../context';
6
5
  import type { ITraceWatcher, ITraceWatcherConfig, MailContent } from '../types';
7
6
  import { EntryType } from '../types';
7
+ import { redactUnknown } from '../utils/redact';
8
8
  import { RequestFilter } from '../utils/requestFilter';
9
9
 
10
10
  let _storage: ITraceWatcherConfig['storage'] | null = null;
11
+ let _redactionFields: string[] = [];
11
12
  let _ignoreRoutes: string[] = [];
12
13
 
13
- const emit = (to: string, subject: string, template?: string): void => {
14
+ const emit = (
15
+ to: string,
16
+ subject: string,
17
+ template?: string,
18
+ text?: string,
19
+ html?: string
20
+ ): void => {
14
21
  if (!_storage) return;
15
22
  if (RequestFilter.shouldIgnoreCurrentRequest(_ignoreRoutes)) return;
16
23
  const content: MailContent = {
17
24
  to,
18
25
  subject,
19
26
  template,
27
+ ...(typeof text === 'string' && text !== ''
28
+ ? { text: redactUnknown(text, _redactionFields) as string }
29
+ : {}),
30
+ ...(typeof html === 'string' && html !== ''
31
+ ? { html: redactUnknown(html, _redactionFields) as string }
32
+ : {}),
20
33
  hostname: TraceContext.getHostname(),
21
34
  };
22
35
  _storage
@@ -38,9 +51,11 @@ export const MailWatcher: ITraceWatcher & { emit: typeof emit } = Object.freeze(
38
51
  register({ storage, config }: ITraceWatcherConfig): () => void {
39
52
  if (config.watchers.mail === false) return () => undefined;
40
53
  _storage = storage;
54
+ _redactionFields = [...config.redaction.keys, ...config.redaction.body];
41
55
  _ignoreRoutes = config.ignoreRoutes;
42
56
  return () => {
43
57
  _storage = null;
58
+ _redactionFields = [];
44
59
  _ignoreRoutes = [];
45
60
  };
46
61
  },
@@ -2,18 +2,30 @@ import { TraceContext } from '../context';
2
2
  import type { ITraceWatcher, ITraceWatcherConfig, NotificationContent } from '../types';
3
3
  import { EntryType } from '../types';
4
4
  import { AuthTag } from '../utils/authTag';
5
+ import { redactUnknown } from '../utils/redact';
5
6
  import { RequestFilter } from '../utils/requestFilter';
6
7
 
7
8
  let _storage: ITraceWatcherConfig['storage'] | null = null;
9
+ let _redactionFields: string[] = [];
8
10
  let _ignoreRoutes: string[] = [];
9
11
 
10
- const emit = (notification: string, channels: string[], notifiable?: string): void => {
12
+ const emit = (
13
+ notification: string,
14
+ channels: string[],
15
+ notifiable?: string,
16
+ message?: string,
17
+ payload?: unknown
18
+ ): void => {
11
19
  if (!_storage) return;
12
20
  if (RequestFilter.shouldIgnoreCurrentRequest(_ignoreRoutes)) return;
13
21
  const content: NotificationContent = {
14
22
  notification,
15
23
  channels,
16
24
  notifiable,
25
+ ...(typeof message === 'string' && message !== ''
26
+ ? { message: redactUnknown(message, _redactionFields) as string }
27
+ : {}),
28
+ ...(payload === undefined ? {} : { payload: redactUnknown(payload, _redactionFields) }),
17
29
  hostname: TraceContext.getHostname(),
18
30
  };
19
31
  _storage
@@ -34,9 +46,11 @@ export const NotificationWatcher: ITraceWatcher & { emit: typeof emit } = Object
34
46
  register({ storage, config }: ITraceWatcherConfig): () => void {
35
47
  if (config.watchers.notification === false) return () => undefined;
36
48
  _storage = storage;
49
+ _redactionFields = [...config.redaction.keys, ...config.redaction.body];
37
50
  _ignoreRoutes = config.ignoreRoutes;
38
51
  return () => {
39
52
  _storage = null;
53
+ _redactionFields = [];
40
54
  _ignoreRoutes = [];
41
55
  };
42
56
  },
@@ -36,7 +36,8 @@ export const QueryWatcher: ITraceWatcher = Object.freeze({
36
36
  if (isTraceStorageQuery(query)) return;
37
37
 
38
38
  const batchId = TraceContext.getBatchId();
39
- const sql = bindingsInterpolated(query, params);
39
+ const includeBindings = config.captureQueryBindings !== false;
40
+ const sql = includeBindings ? bindingsInterpolated(query, params) : query;
40
41
  const roundedDuration = Math.round(duration * 100) / 100;
41
42
  const hash = TraceStorage.familyHash(query);
42
43
  const slow = roundedDuration >= config.slowQueryThreshold;
@@ -44,6 +45,9 @@ export const QueryWatcher: ITraceWatcher = Object.freeze({
44
45
  const content: QueryContent = {
45
46
  connection: 'default',
46
47
  sql,
48
+ statement: query,
49
+ ...(includeBindings ? { bindings: [...params] } : {}),
50
+ bindingsIncluded: includeBindings,
47
51
  time: roundedDuration,
48
52
  duration: roundedDuration,
49
53
  slow,