@adea-ai/telemetry 1.6.0 → 1.8.0
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 +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/operations-lifecycle.d.ts +62 -0
- package/dist/operations-lifecycle.d.ts.map +1 -0
- package/dist/operations-lifecycle.js +149 -0
- package/dist/operations-lifecycle.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,9 @@ export { createStructuredLogger, jsonLogger } from './logger.js';
|
|
|
6
6
|
export type { StructuredLoggerOptions } from './logger.js';
|
|
7
7
|
export { createOperationsMetricEmitter, isOperationsMetricCataloged, operationsMetricNames, operationsStorageNamespaces, } from './operations.js';
|
|
8
8
|
export type { OperationsMetricEmitter, OperationsMetricName, OperationsMetricPoint, OperationsStorageNamespace, } from './operations.js';
|
|
9
|
+
export { OperationsMeasurementLifecycle } from './operations-lifecycle.js';
|
|
10
|
+
export { DEFAULT_OPERATIONS_MEASUREMENT_CLOSE_TIMEOUT_MS, DEFAULT_OPERATIONS_MEASUREMENT_PASS_TIMEOUT_MS, } from './operations-lifecycle.js';
|
|
11
|
+
export type { OperationsMeasurementContext, OperationsMeasurementLifecycleOptions, } from './operations-lifecycle.js';
|
|
9
12
|
export { redactDiagnostics, redactTelemetryValue, sanitizeAttributes } from './redaction.js';
|
|
10
13
|
export { createTelemetry, Telemetry } from './telemetry.js';
|
|
11
14
|
export { createLangSmithTraceAdapter } from './langsmith.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,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AAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,8 @@ export { consistencyMetricNames, createConsistencyMetricEmitter } from './consis
|
|
|
3
3
|
export { extractTraceContext, injectTraceContext, semanticAttributes, traceIdFromContext, } from './context.js';
|
|
4
4
|
export { createStructuredLogger, jsonLogger } from './logger.js';
|
|
5
5
|
export { createOperationsMetricEmitter, isOperationsMetricCataloged, operationsMetricNames, operationsStorageNamespaces, } from './operations.js';
|
|
6
|
+
export { OperationsMeasurementLifecycle } from './operations-lifecycle.js';
|
|
7
|
+
export { DEFAULT_OPERATIONS_MEASUREMENT_CLOSE_TIMEOUT_MS, DEFAULT_OPERATIONS_MEASUREMENT_PASS_TIMEOUT_MS, } from './operations-lifecycle.js';
|
|
6
8
|
export { redactDiagnostics, redactTelemetryValue, sanitizeAttributes } from './redaction.js';
|
|
7
9
|
export { createTelemetry, Telemetry } from './telemetry.js';
|
|
8
10
|
export { createLangSmithTraceAdapter } from './langsmith.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAA;AAEzF,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAEhE,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,iBAAiB,CAAA;AAOxB,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAC5F,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAA;AAE5D,OAAO,EAAE,iCAAiC,EAAE,MAAM,eAAe,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAA;AAEzF,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAEhE,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,iBAAiB,CAAA;AAOxB,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAA;AAC1E,OAAO,EACL,+CAA+C,EAC/C,8CAA8C,GAC/C,MAAM,2BAA2B,CAAA;AAKlC,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAC5F,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAA;AAE5D,OAAO,EAAE,iCAAiC,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type OperationsMetricPoint } from './operations.js';
|
|
2
|
+
import type { MetricAdapter } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Handed to every producer pass. The signal aborts when the pass exceeds its
|
|
5
|
+
* deadline or the lifecycle gives up draining at close. A producer should stop
|
|
6
|
+
* issuing work and settle promptly; whatever it returns after abort is discarded.
|
|
7
|
+
*/
|
|
8
|
+
export interface OperationsMeasurementContext {
|
|
9
|
+
readonly signal: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
export declare const DEFAULT_OPERATIONS_MEASUREMENT_PASS_TIMEOUT_MS = 60000;
|
|
12
|
+
export declare const DEFAULT_OPERATIONS_MEASUREMENT_CLOSE_TIMEOUT_MS = 5000;
|
|
13
|
+
export interface OperationsMeasurementLifecycleOptions {
|
|
14
|
+
readonly adapter: MetricAdapter;
|
|
15
|
+
readonly serviceName: string;
|
|
16
|
+
/** Explicitly scoped producer; undefined means the substrate is unavailable. */
|
|
17
|
+
readonly measure: (context: OperationsMeasurementContext) => readonly OperationsMetricPoint[] | undefined | Promise<readonly OperationsMetricPoint[] | undefined>;
|
|
18
|
+
readonly intervalMs: number;
|
|
19
|
+
readonly maxPoints?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Longest a single pass may run before it is aborted and abandoned (its late
|
|
22
|
+
* result is discarded). Default 60 s; 10 ms to 10 minutes.
|
|
23
|
+
*/
|
|
24
|
+
readonly passTimeoutMs?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Longest `close()` waits for an active pass to drain before aborting it and
|
|
27
|
+
* returning anyway. Default 5 s; 10 ms to 60 s.
|
|
28
|
+
*/
|
|
29
|
+
readonly closeTimeoutMs?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Opt-in runtime observations. The producer owns workspace scope and source
|
|
33
|
+
* quality; only its already-filtered points reach the bounded metric emitter.
|
|
34
|
+
* Never forwards reports, identifiers, payloads or producer/exporter errors.
|
|
35
|
+
* One pass at a time, including manual samples, with bounded emission volume.
|
|
36
|
+
*
|
|
37
|
+
* Passes and shutdown are time-bounded. A pass past `passTimeoutMs` is aborted
|
|
38
|
+
* and abandoned: its late result is never emitted. A stalled producer is not
|
|
39
|
+
* stacked on: no new pass starts until it actually settles, so metrics pause
|
|
40
|
+
* rather than leaking work. `close()` drains an active pass for at most
|
|
41
|
+
* `closeTimeoutMs`, then aborts it and returns; repeated closes share one
|
|
42
|
+
* completion and nothing is emitted after close resolves.
|
|
43
|
+
*/
|
|
44
|
+
export declare class OperationsMeasurementLifecycle {
|
|
45
|
+
#private;
|
|
46
|
+
constructor(options: OperationsMeasurementLifecycleOptions);
|
|
47
|
+
/** Start only after persistence is ready; the initial pass is non-blocking. */
|
|
48
|
+
start(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Concurrent callers share the active pass rather than queueing scans. The
|
|
51
|
+
* returned promise settles when the pass does or its deadline passes,
|
|
52
|
+
* whichever is first; it never rejects.
|
|
53
|
+
*/
|
|
54
|
+
sample(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Drain an active pass for at most `closeTimeoutMs`, then abort it and
|
|
57
|
+
* return. Idempotent: repeated calls share one completion. After it resolves
|
|
58
|
+
* no further observation is emitted, even if the producer settles late.
|
|
59
|
+
*/
|
|
60
|
+
close(): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=operations-lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations-lifecycle.d.ts","sourceRoot":"","sources":["../src/operations-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAC3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAC7B;AAED,eAAO,MAAM,8CAA8C,QAAS,CAAA;AACpE,eAAO,MAAM,+CAA+C,OAAQ,CAAA;AAEpE,MAAM,WAAW,qCAAqC;IACpD,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAA;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,CAChB,OAAO,EAAE,4BAA4B,KAEnC,SAAS,qBAAqB,EAAE,GAChC,SAAS,GACT,OAAO,CAAC,SAAS,qBAAqB,EAAE,GAAG,SAAS,CAAC,CAAA;IACzD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B;;;OAGG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;IAC/B;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CACjC;AAyBD;;;;;;;;;;;;GAYG;AACH,qBAAa,8BAA8B;;IAWzC,YAAY,OAAO,EAAE,qCAAqC,EA6BzD;IAED,+EAA+E;IAC/E,KAAK,IAAI,IAAI,CAQZ;IAED;;;;OAIG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAwCtB;IAED;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAoBrB;CAOF"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { createOperationsMetricEmitter } from './operations.js';
|
|
2
|
+
export const DEFAULT_OPERATIONS_MEASUREMENT_PASS_TIMEOUT_MS = 60_000;
|
|
3
|
+
export const DEFAULT_OPERATIONS_MEASUREMENT_CLOSE_TIMEOUT_MS = 5_000;
|
|
4
|
+
function boundedOption(value, fallback, min, max, code) {
|
|
5
|
+
const resolved = value ?? fallback;
|
|
6
|
+
if (!Number.isSafeInteger(resolved) || resolved < min || resolved > max)
|
|
7
|
+
throw new Error(code);
|
|
8
|
+
return resolved;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Opt-in runtime observations. The producer owns workspace scope and source
|
|
12
|
+
* quality; only its already-filtered points reach the bounded metric emitter.
|
|
13
|
+
* Never forwards reports, identifiers, payloads or producer/exporter errors.
|
|
14
|
+
* One pass at a time, including manual samples, with bounded emission volume.
|
|
15
|
+
*
|
|
16
|
+
* Passes and shutdown are time-bounded. A pass past `passTimeoutMs` is aborted
|
|
17
|
+
* and abandoned: its late result is never emitted. A stalled producer is not
|
|
18
|
+
* stacked on: no new pass starts until it actually settles, so metrics pause
|
|
19
|
+
* rather than leaking work. `close()` drains an active pass for at most
|
|
20
|
+
* `closeTimeoutMs`, then aborts it and returns; repeated closes share one
|
|
21
|
+
* completion and nothing is emitted after close resolves.
|
|
22
|
+
*/
|
|
23
|
+
export class OperationsMeasurementLifecycle {
|
|
24
|
+
#options;
|
|
25
|
+
#maxPoints;
|
|
26
|
+
#passTimeoutMs;
|
|
27
|
+
#closeTimeoutMs;
|
|
28
|
+
#emitter;
|
|
29
|
+
#timer;
|
|
30
|
+
#active;
|
|
31
|
+
#closing;
|
|
32
|
+
#state = 'idle';
|
|
33
|
+
constructor(options) {
|
|
34
|
+
if (!Number.isSafeInteger(options.intervalMs) ||
|
|
35
|
+
options.intervalMs < 1000 ||
|
|
36
|
+
options.intervalMs > 86_400_000) {
|
|
37
|
+
throw new Error('OPERATIONS_MEASUREMENT_INTERVAL_INVALID');
|
|
38
|
+
}
|
|
39
|
+
const maxPoints = options.maxPoints ?? 512;
|
|
40
|
+
if (!Number.isSafeInteger(maxPoints) || maxPoints < 1 || maxPoints > 1024) {
|
|
41
|
+
throw new Error('OPERATIONS_MEASUREMENT_POINT_LIMIT_INVALID');
|
|
42
|
+
}
|
|
43
|
+
this.#passTimeoutMs = boundedOption(options.passTimeoutMs, DEFAULT_OPERATIONS_MEASUREMENT_PASS_TIMEOUT_MS, 10, 600_000, 'OPERATIONS_MEASUREMENT_PASS_TIMEOUT_INVALID');
|
|
44
|
+
this.#closeTimeoutMs = boundedOption(options.closeTimeoutMs, DEFAULT_OPERATIONS_MEASUREMENT_CLOSE_TIMEOUT_MS, 10, 60_000, 'OPERATIONS_MEASUREMENT_CLOSE_TIMEOUT_INVALID');
|
|
45
|
+
this.#options = { ...options };
|
|
46
|
+
this.#maxPoints = maxPoints;
|
|
47
|
+
this.#emitter = createOperationsMetricEmitter(options.adapter, options.serviceName);
|
|
48
|
+
}
|
|
49
|
+
/** Start only after persistence is ready; the initial pass is non-blocking. */
|
|
50
|
+
start() {
|
|
51
|
+
if (this.#state !== 'idle')
|
|
52
|
+
return;
|
|
53
|
+
this.#state = 'running';
|
|
54
|
+
this.#timer = setInterval(() => {
|
|
55
|
+
void this.sample();
|
|
56
|
+
}, this.#options.intervalMs);
|
|
57
|
+
this.#timer.unref();
|
|
58
|
+
void this.sample();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Concurrent callers share the active pass rather than queueing scans. The
|
|
62
|
+
* returned promise settles when the pass does or its deadline passes,
|
|
63
|
+
* whichever is first; it never rejects.
|
|
64
|
+
*/
|
|
65
|
+
sample() {
|
|
66
|
+
if (this.#state !== 'running')
|
|
67
|
+
return Promise.resolve();
|
|
68
|
+
const existing = this.#active;
|
|
69
|
+
if (existing !== undefined)
|
|
70
|
+
return existing.bounded;
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
const active = {
|
|
73
|
+
controller,
|
|
74
|
+
settled: Promise.resolve(),
|
|
75
|
+
bounded: Promise.resolve(),
|
|
76
|
+
abandoned: false,
|
|
77
|
+
done: false,
|
|
78
|
+
};
|
|
79
|
+
// Defer the producer until the in-flight fence has been installed.
|
|
80
|
+
const settled = Promise.resolve().then(async () => {
|
|
81
|
+
try {
|
|
82
|
+
const points = await this.#options.measure({ signal: controller.signal });
|
|
83
|
+
// A late result after the deadline or close is discarded, never emitted.
|
|
84
|
+
if (points === undefined || active.abandoned)
|
|
85
|
+
return;
|
|
86
|
+
for (const point of points.slice(0, this.#maxPoints))
|
|
87
|
+
this.#emitter.record(point);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// A missing/degraded source or failed exporter cannot change runtime state.
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
let deadlineTimer;
|
|
94
|
+
const deadline = new Promise((resolve) => {
|
|
95
|
+
deadlineTimer = setTimeout(() => {
|
|
96
|
+
this.#abandon(active);
|
|
97
|
+
resolve();
|
|
98
|
+
}, this.#passTimeoutMs);
|
|
99
|
+
deadlineTimer.unref();
|
|
100
|
+
});
|
|
101
|
+
active.settled = settled;
|
|
102
|
+
active.bounded = Promise.race([settled, deadline]);
|
|
103
|
+
this.#active = active;
|
|
104
|
+
void settled.then(() => {
|
|
105
|
+
active.done = true;
|
|
106
|
+
clearTimeout(deadlineTimer);
|
|
107
|
+
if (this.#active === active)
|
|
108
|
+
this.#active = undefined;
|
|
109
|
+
});
|
|
110
|
+
return active.bounded;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Drain an active pass for at most `closeTimeoutMs`, then abort it and
|
|
114
|
+
* return. Idempotent: repeated calls share one completion. After it resolves
|
|
115
|
+
* no further observation is emitted, even if the producer settles late.
|
|
116
|
+
*/
|
|
117
|
+
close() {
|
|
118
|
+
if (this.#closing !== undefined)
|
|
119
|
+
return this.#closing;
|
|
120
|
+
this.#state = 'closed';
|
|
121
|
+
if (this.#timer !== undefined)
|
|
122
|
+
clearInterval(this.#timer);
|
|
123
|
+
this.#timer = undefined;
|
|
124
|
+
const active = this.#active;
|
|
125
|
+
this.#closing = (async () => {
|
|
126
|
+
if (active === undefined)
|
|
127
|
+
return;
|
|
128
|
+
let closeTimer;
|
|
129
|
+
const deadline = new Promise((resolve) => {
|
|
130
|
+
closeTimer = setTimeout(resolve, this.#closeTimeoutMs);
|
|
131
|
+
});
|
|
132
|
+
try {
|
|
133
|
+
await Promise.race([active.settled, deadline]);
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
clearTimeout(closeTimer);
|
|
137
|
+
this.#abandon(active);
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
return this.#closing;
|
|
141
|
+
}
|
|
142
|
+
#abandon(active) {
|
|
143
|
+
if (active.done || active.abandoned)
|
|
144
|
+
return;
|
|
145
|
+
active.abandoned = true;
|
|
146
|
+
active.controller.abort();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=operations-lifecycle.js.map
|
|
@@ -0,0 +1 @@
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CAAC,SAAS;YAAE,OAAM;QAC3C,MAAM,CAAC,SAAS,GAAG,IAAI,CAAA;QACvB,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,CAAA;IAC3B,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adea-ai/telemetry",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
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",
|