@adea-ai/telemetry 4.1.3 → 4.2.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/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export type { OperationsMetricEmitter, OperationsMetricName, OperationsMetricPoi
9
9
  export { OperationsMeasurementLifecycle } from './operations-lifecycle.js';
10
10
  export { DEFAULT_OPERATIONS_MEASUREMENT_CLOSE_TIMEOUT_MS, DEFAULT_OPERATIONS_MEASUREMENT_PASS_TIMEOUT_MS, } from './operations-lifecycle.js';
11
11
  export type { OperationsMeasurementContext, OperationsMeasurementLifecycleOptions, } from './operations-lifecycle.js';
12
- export { redactDiagnostics, redactTelemetryValue, sanitizeAttributes } from './redaction.js';
12
+ export { redactDiagnostics, redactTelemetryValue, registerTelemetryTextRedactor, sanitizeAttributes, } from './redaction.js';
13
13
  export { createTelemetry, Telemetry } from './telemetry.js';
14
14
  export { createLangSmithTraceAdapter } from './langsmith.js';
15
15
  export type { LangSmithClientPort, LangSmithRunPort } from './langsmith.js';
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ export { createStructuredLogger, jsonLogger } from './logger.js';
5
5
  export { createOperationsMetricEmitter, isOperationsMetricCataloged, operationsMetricNames, operationsStorageNamespaces, } from './operations.js';
6
6
  export { OperationsMeasurementLifecycle } from './operations-lifecycle.js';
7
7
  export { DEFAULT_OPERATIONS_MEASUREMENT_CLOSE_TIMEOUT_MS, DEFAULT_OPERATIONS_MEASUREMENT_PASS_TIMEOUT_MS, } from './operations-lifecycle.js';
8
- export { redactDiagnostics, redactTelemetryValue, sanitizeAttributes } from './redaction.js';
8
+ export { redactDiagnostics, redactTelemetryValue, registerTelemetryTextRedactor, sanitizeAttributes, } from './redaction.js';
9
9
  export { createTelemetry, Telemetry } from './telemetry.js';
10
10
  export { createLangSmithTraceAdapter } from './langsmith.js';
11
11
  export { createDeterministicSamplingPolicy } from './sampling.js';
@@ -1,4 +1,5 @@
1
1
  import type { SpanOutcome } from './types.js';
2
+ export declare function registerTelemetryTextRedactor(redactor: (text: string) => string): () => void;
2
3
  export declare function redactTelemetryValue(value: unknown): unknown;
3
4
  export declare function sanitizeSpanOutcome(outcome: SpanOutcome): SpanOutcome;
4
5
  export declare function sanitizeAttributes(attributes: Readonly<Record<string, unknown>>): Readonly<Record<string, boolean | number | string>>;
package/dist/redaction.js CHANGED
@@ -63,7 +63,23 @@ const secretsInText = [
63
63
  },
64
64
  ];
65
65
  const mayContainSecretText = /[:=/]|bearer|gh[pousr]_|github_pat_|akia|asia|xox[baprs]-|_live_|aiza|-----begin|localhost|127/i;
66
- function redactText(value) {
66
+ const textRedactors = new Set();
67
+ export function registerTelemetryTextRedactor(redactor) {
68
+ textRedactors.add(redactor);
69
+ return () => {
70
+ textRedactors.delete(redactor);
71
+ };
72
+ }
73
+ function redactText(input) {
74
+ let value = input;
75
+ for (const redactor of textRedactors) {
76
+ try {
77
+ value = redactor(value);
78
+ }
79
+ catch {
80
+ return '[REDACTED]';
81
+ }
82
+ }
67
83
  if (!mayContainSecretText.test(value))
68
84
  return value;
69
85
  return secretsInText.reduce((redacted, { pattern, replacement }) => redacted.replace(pattern, replacement), value);
@@ -100,7 +116,7 @@ function redact(value, seen) {
100
116
  else {
101
117
  const record = {};
102
118
  for (const [key, nested] of Object.entries(value)) {
103
- record[key] = isSensitiveKey(key) ? '[REDACTED]' : redact(nested, seen);
119
+ setOwn(record, key, isSensitiveKey(key) ? '[REDACTED]' : redact(nested, seen));
104
120
  }
105
121
  result = record;
106
122
  }
@@ -111,14 +127,25 @@ export function sanitizeAttributes(attributes) {
111
127
  const sanitized = {};
112
128
  for (const [key, value] of Object.entries(attributes)) {
113
129
  if (isSensitiveKey(key))
114
- sanitized[key] = '[REDACTED]';
130
+ setOwn(sanitized, key, '[REDACTED]');
115
131
  else if (typeof value === 'boolean' || typeof value === 'number')
116
- sanitized[key] = value;
132
+ setOwn(sanitized, key, value);
117
133
  else if (typeof value === 'string')
118
- sanitized[key] = redactText(value);
134
+ setOwn(sanitized, key, redactText(value));
119
135
  }
120
136
  return sanitized;
121
137
  }
138
+ function setOwn(record, key, value) {
139
+ if (key === '__proto__')
140
+ Object.defineProperty(record, key, {
141
+ value,
142
+ enumerable: true,
143
+ writable: true,
144
+ configurable: true,
145
+ });
146
+ else
147
+ record[key] = value;
148
+ }
122
149
  const diagnosticRedactedValue = '[REDACTED]';
123
150
  const diagnosticCircularValue = '[Circular]';
124
151
  const diagnosticSensitiveKey = /authorization|cookie|credential|password|private.?key|secret|token|api.?key/i;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adea-ai/telemetry",
3
- "version": "4.1.3",
3
+ "version": "4.2.1",
4
4
  "description": "Fail-open observability toolkit: structured logging, secret redaction, trace-context propagation, deterministic sampling, and pluggable OpenTelemetry, Sentry, and LangSmith adapters.",
5
5
  "keywords": [
6
6
  "langsmith",
@@ -23,6 +23,7 @@
23
23
  "dist"
24
24
  ],
25
25
  "type": "module",
26
+ "sideEffects": false,
26
27
  "browser": false,
27
28
  "types": "./dist/index.d.ts",
28
29
  "exports": {