@adea-ai/telemetry 4.1.1 → 4.1.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.
package/README.md CHANGED
@@ -41,19 +41,19 @@ import { createSentryErrorTracker } from '@adea-ai/telemetry/sentry'
41
41
 
42
42
  ## What's inside
43
43
 
44
- - **Structured logging** — `createStructuredLogger` / `jsonLogger` emit
44
+ - **Structured logging**: `createStructuredLogger` / `jsonLogger` emit
45
45
  redacted JSON lines to stdout/stderr.
46
- - **Redaction** — `redactTelemetryValue` scrubs sensitive keys, bearer
46
+ - **Redaction**: `redactTelemetryValue` scrubs sensitive keys, bearer
47
47
  tokens, GitHub/AWS/Slack/Stripe/Google credentials, URL credentials, and PEM
48
48
  blocks from arbitrary values; `redactDiagnostics` applies substring-based
49
49
  key matching with an explicit allowlist for diagnostics payloads.
50
- - **Trace context** — W3C-style `traceparent` extraction/injection for
50
+ - **Trace context**: W3C-style `traceparent` extraction/injection for
51
51
  cross-service correlation.
52
- - **Sampling** — `createDeterministicSamplingPolicy` for stable,
52
+ - **Sampling**: `createDeterministicSamplingPolicy` for stable,
53
53
  hash-based span sampling.
54
- - **Adapters** — OpenTelemetry metrics/traces, Sentry error tracking, and a
54
+ - **Adapters**: OpenTelemetry metrics/traces, Sentry error tracking, and a
55
55
  LangSmith trace adapter (port-injected, dependency-free).
56
- - **Catalog** (`@adea-ai/telemetry/catalog`) — the Control Plane's canonical
56
+ - **Catalog** (`@adea-ai/telemetry/catalog`): the Control Plane's canonical
57
57
  execution-trace span names, operational metric names, and diagnostic
58
58
  queries.
59
59
 
package/dist/catalog.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare const executionTraceSpans: readonly ['execution.root', 'plan.compile', 'workflow.run', 'runtime.route', 'runtime.start', 'model.call', 'tool.authorize', 'tool.execute', 'sandbox.execute', 'approval.wait', 'artifact.promote', 'usage.settle', 'execution.cleanup'];
2
- export declare const operationalMetrics: readonly ['control.api.request.duration', 'control.api.error.count', 'control.command_inbox.duplicate.count', 'control.command_inbox.conflict.count', 'workflow.backlog.count', 'workflow.replay.count', 'runtime.available.count', 'model.call.duration', 'model.call.error.count', 'tool.call.duration', 'tool.call.error.count', 'execution.reconciliation.count', 'execution.manual_intervention.count', 'context.provider_resolution.count', 'memory.write.decision.count', 'usage.cost.usd', 'execution.queue.latency', 'execution.human.latency', 'execution.retry.age', 'execution.reconciliation.age', 'storage.retained.bytes', 'storage.rewritten.bytes', 'storage.growth.bytes', 'runtime.active_object.count', 'operations.operating_cost.usd'];
2
+ export declare const operationalMetrics: readonly ['control.api.request.duration', 'control.api.error.count', 'control.command_inbox.duplicate.count', 'control.command_inbox.conflict.count', 'workflow.backlog.count', 'workflow.replay.count', 'runtime.available.count', 'model.call.duration', 'model.call.error.count', 'tool.call.duration', 'tool.call.error.count', 'execution.reconciliation.count', 'execution.manual_intervention.count', 'context.provider_resolution.count', 'context.provider_read.count', 'context.provider_read.duration', 'context.contribution.count', 'memory.write.decision.count', 'memory.write.outcome.count', 'runtime.progress.sequence_gap.count', 'usage.cost.usd', 'execution.queue.latency', 'execution.human.latency', 'execution.retry.age', 'execution.reconciliation.age', 'storage.retained.bytes', 'storage.rewritten.bytes', 'storage.growth.bytes', 'runtime.active_object.count', 'operations.operating_cost.usd'];
3
3
  export type ExecutionTraceSpanName = (typeof executionTraceSpans)[number];
4
4
  export type OperationalMetricName = (typeof operationalMetrics)[number];
5
5
  export interface DiagnosticQuery {
package/dist/catalog.js CHANGED
@@ -28,7 +28,12 @@ export const operationalMetrics = [
28
28
  'execution.reconciliation.count',
29
29
  'execution.manual_intervention.count',
30
30
  'context.provider_resolution.count',
31
+ 'context.provider_read.count',
32
+ 'context.provider_read.duration',
33
+ 'context.contribution.count',
31
34
  'memory.write.decision.count',
35
+ 'memory.write.outcome.count',
36
+ 'runtime.progress.sequence_gap.count',
32
37
  'usage.cost.usd',
33
38
  'execution.queue.latency',
34
39
  'execution.human.latency',
@@ -4,14 +4,27 @@ export declare const consistencyMetricNames: {
4
4
  readonly commandInboxConflict: 'control.command_inbox.conflict.count';
5
5
  readonly contextProviderResolution: 'context.provider_resolution.count';
6
6
  readonly memoryWriteDecision: 'memory.write.decision.count';
7
+ readonly contextProviderRead: 'context.provider_read.count';
8
+ readonly contextProviderReadDuration: 'context.provider_read.duration';
9
+ readonly contextContribution: 'context.contribution.count';
10
+ readonly memoryWriteOutcome: 'memory.write.outcome.count';
11
+ readonly runtimeProgressSequenceGap: 'runtime.progress.sequence_gap.count';
7
12
  readonly executionReconciliation: 'execution.reconciliation.count';
8
13
  readonly executionManualIntervention: 'execution.manual_intervention.count';
9
14
  };
10
15
  export type CommandInboxAcceptanceOutcome = 'accepted' | 'duplicate' | 'conflict';
16
+ export type ContextProviderReadOutcome = 'ok' | 'timeout' | 'error' | 'scope_denied' | 'rejected' | 'revoked' | 'unavailable';
17
+ export type ContextContributionOutcome = 'cache_hit' | 'rebuilt' | 'fetched' | 'rejected';
18
+ export type MemoryWriteOutcome = 'duplicate' | 'conflict' | 'committed' | 'reconciled' | 'rejected' | 'ambiguous';
19
+ export type RuntimeProgressSequenceAnomaly = 'gap' | 'regression';
11
20
  export interface ConsistencyMetricEmitter {
12
21
  recordAcceptanceOutcome(outcome: CommandInboxAcceptanceOutcome): void;
13
22
  recordResolution(outcome: string, reasonCategory: string): void;
14
23
  recordApprovalDecision(decision: string): void;
24
+ recordProviderRead(outcome: ContextProviderReadOutcome, durationMs: number): void;
25
+ recordContribution(outcome: ContextContributionOutcome): void;
26
+ recordMemoryWriteOutcome(outcome: MemoryWriteOutcome): void;
27
+ recordSequenceAnomaly(kind: RuntimeProgressSequenceAnomaly): void;
15
28
  recordCheckpoint(input: {
16
29
  readonly reason: string;
17
30
  readonly state: string;
@@ -4,6 +4,11 @@ export const consistencyMetricNames = {
4
4
  commandInboxConflict: 'control.command_inbox.conflict.count',
5
5
  contextProviderResolution: 'context.provider_resolution.count',
6
6
  memoryWriteDecision: 'memory.write.decision.count',
7
+ contextProviderRead: 'context.provider_read.count',
8
+ contextProviderReadDuration: 'context.provider_read.duration',
9
+ contextContribution: 'context.contribution.count',
10
+ memoryWriteOutcome: 'memory.write.outcome.count',
11
+ runtimeProgressSequenceGap: 'runtime.progress.sequence_gap.count',
7
12
  executionReconciliation: 'execution.reconciliation.count',
8
13
  executionManualIntervention: 'execution.manual_intervention.count',
9
14
  };
@@ -28,6 +33,25 @@ const providerResolutionReasonCategories = new Set([
28
33
  'PROVIDER_BUDGET_EXCEEDED',
29
34
  ]);
30
35
  const memoryWriteDecisions = new Set(['approved', 'denied', 'expired']);
36
+ const providerReadOutcomes = new Set([
37
+ 'ok',
38
+ 'timeout',
39
+ 'error',
40
+ 'scope_denied',
41
+ 'rejected',
42
+ 'revoked',
43
+ 'unavailable',
44
+ ]);
45
+ const contributionOutcomes = new Set(['cache_hit', 'rebuilt', 'fetched', 'rejected']);
46
+ const memoryWriteOutcomes = new Set([
47
+ 'duplicate',
48
+ 'conflict',
49
+ 'committed',
50
+ 'reconciled',
51
+ 'rejected',
52
+ 'ambiguous',
53
+ ]);
54
+ const sequenceGapKinds = new Set(['gap', 'regression']);
31
55
  const reconciliationReasons = new Set([
32
56
  'accepted_unstarted',
33
57
  'stale_heartbeat',
@@ -50,6 +74,15 @@ export function createConsistencyMetricEmitter(adapter, serviceName) {
50
74
  catch {
51
75
  }
52
76
  }
77
+ function record(name, value, labels) {
78
+ if (!Number.isFinite(value) || value < 0)
79
+ return;
80
+ try {
81
+ adapter.record(name, value, sanitizeAttributes({ 'service.name': serviceName, ...labels }));
82
+ }
83
+ catch {
84
+ }
85
+ }
53
86
  return {
54
87
  recordAcceptanceOutcome(outcome) {
55
88
  if (!commandInboxOutcomes.has(outcome) || outcome === 'accepted')
@@ -69,6 +102,26 @@ export function createConsistencyMetricEmitter(adapter, serviceName) {
69
102
  decision: boundedLabel(decision, memoryWriteDecisions),
70
103
  });
71
104
  },
105
+ recordProviderRead(outcome, durationMs) {
106
+ const label = boundedLabel(outcome, providerReadOutcomes);
107
+ add(consistencyMetricNames.contextProviderRead, { outcome: label });
108
+ record(consistencyMetricNames.contextProviderReadDuration, durationMs, { outcome: label });
109
+ },
110
+ recordContribution(outcome) {
111
+ add(consistencyMetricNames.contextContribution, {
112
+ outcome: boundedLabel(outcome, contributionOutcomes),
113
+ });
114
+ },
115
+ recordMemoryWriteOutcome(outcome) {
116
+ add(consistencyMetricNames.memoryWriteOutcome, {
117
+ outcome: boundedLabel(outcome, memoryWriteOutcomes),
118
+ });
119
+ },
120
+ recordSequenceAnomaly(kind) {
121
+ add(consistencyMetricNames.runtimeProgressSequenceGap, {
122
+ kind: boundedLabel(kind, sequenceGapKinds),
123
+ });
124
+ },
72
125
  recordCheckpoint(input) {
73
126
  const reason = boundedLabel(input.reason, reconciliationReasons);
74
127
  add(consistencyMetricNames.executionReconciliation, {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { createConsoleMetricAdapter, createConsoleTraceAdapter, DEFAULT_CONSOLE_SLOW_SPAN_MS, type ConsoleTraceAdapterOptions, } from './console.js';
2
2
  export { consistencyMetricNames, createConsistencyMetricEmitter } from './consistency.js';
3
- export type { CommandInboxAcceptanceOutcome, ConsistencyMetricEmitter } from './consistency.js';
3
+ export type { CommandInboxAcceptanceOutcome, ConsistencyMetricEmitter, ContextContributionOutcome, ContextProviderReadOutcome, MemoryWriteOutcome, RuntimeProgressSequenceAnomaly, } from './consistency.js';
4
4
  export { extractTraceContext, injectTraceContext, semanticAttributes, traceIdFromContext, } from './context.js';
5
5
  export { createStructuredLogger, jsonLogger } from './logger.js';
6
6
  export type { StructuredLoggerOptions } from './logger.js';
package/dist/redaction.js CHANGED
@@ -27,7 +27,7 @@ const sensitiveKeys = new Set([
27
27
  ]);
28
28
  const secretsInText = [
29
29
  {
30
- pattern: /(access[_-]?token|api[_-]?key|authorization|client[_-]?secret|cookie|credential(?:[_-]?ref)?|encryption[_-]?key|file[_-]?contents?|id[_-]?token|model[_-]?input|passw(?:or)?d|private[_-]?key|prompt|refresh[_-]?token|secret(?:[_-]?(?:access[_-]?key|key|value))?|signing[_-]?key|token|tool[_-]?input)\s*[:=]\s*(?:Bearer\s+)?[^\s,;]+/gi,
30
+ pattern: /(access[_-]?token|api[_-]?key|authorization|client[_-]?secret|cookie|credential(?:[_-]?ref)?|encryption[_-]?key|file[_-]?contents?|id[_-]?token|model[_-]?input|passw(?:or)?d|passphrase|private[_-]?key|prompt|refresh[_-]?token|secret(?:[_-]?(?:access[_-]?key|key|value))?|signing[_-]?key|token|tool[_-]?input)\s*[:=]\s*(?:Bearer\s+)?[^\s,;]+/gi,
31
31
  replacement: '$1=[REDACTED]',
32
32
  },
33
33
  { pattern: /\bBearer\s+[^\s,;]+/gi, replacement: 'Bearer [REDACTED]' },
@@ -62,11 +62,16 @@ const secretsInText = [
62
62
  replacement: '[REDACTED_PATH]',
63
63
  },
64
64
  ];
65
+ const mayContainSecretText = /[:=/]|bearer|gh[pousr]_|github_pat_|akia|asia|xox[baprs]-|_live_|aiza|-----begin|localhost|127/i;
65
66
  function redactText(value) {
67
+ if (!mayContainSecretText.test(value))
68
+ return value;
66
69
  return secretsInText.reduce((redacted, { pattern, replacement }) => redacted.replace(pattern, replacement), value);
67
70
  }
71
+ const sensitiveKeySuffix = /(?:token|secret|password|passwd|passphrase|credentials?|apikey|privatekey|accesskey|secretkey|signingkey|encryptionkey|cookie|authorization)$/;
68
72
  function isSensitiveKey(key) {
69
- return sensitiveKeys.has(key.replace(/[^a-z0-9]/gi, '').toLowerCase());
73
+ const normalized = key.replace(/[^a-z0-9]/gi, '').toLowerCase();
74
+ return sensitiveKeys.has(normalized) || sensitiveKeySuffix.test(normalized);
70
75
  }
71
76
  export function redactTelemetryValue(value) {
72
77
  return redact(value, new WeakSet());
@@ -89,12 +94,17 @@ function redact(value, seen) {
89
94
  if (seen.has(value))
90
95
  return '[Circular]';
91
96
  seen.add(value);
97
+ let result;
92
98
  if (Array.isArray(value))
93
- return value.map((item) => redact(item, seen));
94
- const result = {};
95
- for (const [key, nested] of Object.entries(value)) {
96
- result[key] = isSensitiveKey(key) ? '[REDACTED]' : redact(nested, seen);
99
+ result = value.map((item) => redact(item, seen));
100
+ else {
101
+ const record = {};
102
+ for (const [key, nested] of Object.entries(value)) {
103
+ record[key] = isSensitiveKey(key) ? '[REDACTED]' : redact(nested, seen);
104
+ }
105
+ result = record;
97
106
  }
107
+ seen.delete(value);
98
108
  return result;
99
109
  }
100
110
  export function sanitizeAttributes(attributes) {
@@ -124,14 +134,16 @@ function redactDiagnosticValue(value, explicitKeys, seen) {
124
134
  if (seen.has(value))
125
135
  return diagnosticCircularValue;
126
136
  seen.add(value);
127
- if (Array.isArray(value))
128
- return value.map((item) => redactDiagnosticValue(item, explicitKeys, seen));
129
- return Object.fromEntries(Object.entries(value).map(([key, item]) => [
130
- key,
131
- isSensitiveDiagnosticKey(key, explicitKeys)
132
- ? diagnosticRedactedValue
133
- : redactDiagnosticValue(item, explicitKeys, seen),
134
- ]));
137
+ const result = Array.isArray(value)
138
+ ? value.map((item) => redactDiagnosticValue(item, explicitKeys, seen))
139
+ : Object.fromEntries(Object.entries(value).map(([key, item]) => [
140
+ key,
141
+ isSensitiveDiagnosticKey(key, explicitKeys)
142
+ ? diagnosticRedactedValue
143
+ : redactDiagnosticValue(item, explicitKeys, seen),
144
+ ]));
145
+ seen.delete(value);
146
+ return result;
135
147
  }
136
148
  function isSensitiveDiagnosticKey(key, explicitKeys) {
137
149
  return diagnosticSensitiveKey.test(key) || explicitKeys.has(normalizeDiagnosticKey(key));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adea-ai/telemetry",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
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",
@@ -58,8 +58,8 @@
58
58
  },
59
59
  "devDependencies": {
60
60
  "@opentelemetry/api": "1.10.0",
61
- "@opentelemetry/sdk-metrics": "3.0.0",
62
- "@sentry/node": "11.4.0"
61
+ "@opentelemetry/sdk-metrics": "3.1.1",
62
+ "@sentry/node": "11.12.0"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "@opentelemetry/api": "^1.9.0",