@jini-ai/diagnostics 0.7.2 → 0.7.3-next.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/CHANGELOG.md +2 -8
- package/dist/agent-logs/amr/index.d.ts +8 -0
- package/dist/agent-logs/amr/index.js +16 -0
- package/dist/agent-logs/claude/index.d.ts +8 -0
- package/dist/agent-logs/claude/index.js +8 -0
- package/dist/agent-logs/codex/index.d.ts +8 -0
- package/dist/agent-logs/codex/index.js +8 -0
- package/dist/agent-logs/opencode/index.d.ts +8 -0
- package/dist/agent-logs/opencode/index.js +10 -0
- package/dist/agent-logs.js +12 -39
- package/dist/console-tee.d.ts +83 -0
- package/dist/console-tee.js +108 -0
- package/dist/local-text.d.ts +21 -0
- package/dist/local-text.js +30 -0
- package/dist/observability/delivery.js +4 -3
- package/dist/observability/errors.d.ts +4 -1
- package/dist/observability/errors.js +2 -2
- package/dist/observability/fanout.d.ts +1 -1
- package/dist/observability/fanout.js +1 -1
- package/dist/observability/hooks.d.ts +2 -1
- package/dist/observability/hooks.js +1 -1
- package/dist/observability/index.d.ts +2 -12
- package/dist/observability/index.js +2 -11
- package/dist/observability/instrumentation.d.ts +4 -4
- package/dist/observability/instrumentation.js +1 -1
- package/dist/observability/node.d.ts +4 -0
- package/dist/observability/node.js +2 -0
- package/dist/observability/otel.d.ts +19 -25
- package/dist/observability/otel.js +20 -195
- package/dist/observability/ports.d.ts +1 -184
- package/dist/observability/provider-contract.d.ts +22 -0
- package/dist/observability/provider-contract.js +19 -0
- package/dist/observability/report-error.d.ts +1 -1
- package/dist/observability/tracker-types.d.ts +2 -2
- package/dist/observability/tracker.js +3 -2
- package/dist/sources.js +2 -1
- package/dist/web-evidence/bounded-body.d.ts +22 -0
- package/dist/web-evidence/bounded-body.js +60 -0
- package/dist/web-evidence/capture-budget.d.ts +29 -0
- package/dist/web-evidence/capture-budget.js +14 -0
- package/dist/web-evidence/capture-clock.d.ts +12 -0
- package/dist/web-evidence/capture-clock.js +8 -0
- package/dist/web-evidence/cookie-shapes.d.ts +22 -0
- package/dist/web-evidence/cookie-shapes.js +26 -0
- package/dist/web-evidence/index.d.ts +3 -0
- package/dist/web-evidence/index.js +3 -0
- package/dist/web-evidence/page-body.d.ts +37 -0
- package/dist/web-evidence/page-body.js +112 -0
- package/dist/web-evidence/page-work-budget.d.ts +17 -1
- package/dist/web-evidence/page-work-budget.js +30 -8
- package/dist/web-evidence/path-guard.d.ts +119 -0
- package/dist/web-evidence/path-guard.js +200 -0
- package/dist/web-evidence/playwright-browser.js +18 -15
- package/dist/web-evidence/playwright-runtime.d.ts +0 -45
- package/dist/web-evidence/playwright-runtime.js +48 -2
- package/dist/web-evidence/render-page.d.ts +14 -0
- package/dist/web-evidence/render-page.js +65 -20
- package/dist/web-evidence/request-guard.js +19 -15
- package/dist/web-evidence/same-origin.d.ts +1 -1
- package/dist/web-evidence/same-origin.js +4 -4
- package/dist/web-evidence/testing/fake-clock.d.ts +19 -0
- package/dist/web-evidence/testing/fake-clock.js +47 -0
- package/package.json +54 -6
- package/dist/observability/noop.d.ts +0 -7
- package/dist/observability/noop.js +0 -27
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { ExporterFactory, TracerProviderFactory, ObservabilityPort, SpanScopePort } from './ports.js';
|
|
3
|
-
export interface OtelAdapterDependencies {
|
|
4
|
-
config: ObservabilityConfigEnabled;
|
|
5
|
-
exporterFactory: ExporterFactory;
|
|
6
|
-
tracerProviderFactory: TracerProviderFactory;
|
|
7
|
-
}
|
|
8
|
-
export interface OtelAdapterOptions {
|
|
9
|
-
scope?: SpanScopePort;
|
|
10
|
-
}
|
|
1
|
+
import { type ErrorDescriber } from '@jini-ai/core';
|
|
11
2
|
type Attributes = Record<string, string | number>;
|
|
12
|
-
|
|
3
|
+
/** A low-cardinality error label: an approved code (`ECONNREFUSED`, `SQLITE_CONSTRAINT`), else the
|
|
4
|
+
* fixed class label (`TypeError`, a label from a describer the package built), both from core's `describeErrorParts`.
|
|
5
|
+
* This is the shape hosts' dashboards and alerts match on (review jini-batch1 M2: `Error(ECONNREFUSED)`
|
|
6
|
+
* silently broke them). Messages are never exported: they carry SQL fragments, hostnames, emails, even
|
|
7
|
+
* credentials. Both `error.code` and `Error.name` are writable secret channels (review 2026-10-25 #2),
|
|
8
|
+
* so an unapproved code or an unregistered class name is never printed (it reads as the class label,
|
|
9
|
+
* often `Error`; a package names its own through core's `createErrorDescriber`). The label is still
|
|
10
|
+
* redacted and capped to {@link MAX_ERROR_TYPE} (redact first: a cut could leave a secret prefix too
|
|
11
|
+
* short to match). */
|
|
12
|
+
export declare function errorType({ error }: {
|
|
13
|
+
error: unknown;
|
|
14
|
+
}, { describer }?: {
|
|
15
|
+
describer?: Pick<ErrorDescriber, 'describeErrorParts'>;
|
|
16
|
+
}): string;
|
|
17
|
+
/** The secret-shape redaction every adapter applies to a label before export. */
|
|
18
|
+
export declare function redactLabel({ text }: {
|
|
19
|
+
text: string;
|
|
20
|
+
}, _optional?: Record<string, never>): string;
|
|
13
21
|
/** Feature attributes are documented as ids and fixed labels, but a caller can still hand over a
|
|
14
22
|
* secret-shaped value (an unknown tool id straight from a request, review #1). Every string is
|
|
15
23
|
* redacted and capped before any SDK sees it; numbers pass. Every adapter applies this, so one careless
|
|
@@ -18,19 +26,5 @@ export declare function errorType(error: unknown): string;
|
|
|
18
26
|
export declare function redactOperationAttributes({ attributes }: {
|
|
19
27
|
attributes: Readonly<Record<string, string | number>>;
|
|
20
28
|
}): Attributes;
|
|
21
|
-
export declare function redactRequestTarget({ path }: {
|
|
22
|
-
path: string;
|
|
23
|
-
}, { routePattern }?: {
|
|
24
|
-
routePattern?: string;
|
|
25
|
-
}): string;
|
|
26
|
-
/** Scheme, host and explicit port only. Paths carry bot tokens and signed-URL keys; userinfo carries passwords. */
|
|
27
|
-
export declare function outboundTargetAttributes(url: string): Attributes;
|
|
28
|
-
/** Builds request, DB, outbound, agent-run and operation spans, and exception events for reported errors, through injected provider/exporter factories.
|
|
29
|
-
* @param required Explicit config and structural factories. Hosts wrap their SDK here.
|
|
30
|
-
* @param options Optional host scope storage; with it, spans started inside a tracker's run() are its children.
|
|
31
|
-
* @returns One adapter whose spans end once, with final names, redacted attributes and error status.
|
|
32
|
-
* @throws Provider/exporter errors propagate during setup. No globals or SDK imports are used.
|
|
33
|
-
*/
|
|
34
|
-
export declare function createOtelObservabilityPort({ config, exporterFactory, tracerProviderFactory }: OtelAdapterDependencies, { scope }?: OtelAdapterOptions): ObservabilityPort;
|
|
35
29
|
export {};
|
|
36
30
|
//# sourceMappingURL=otel.d.ts.map
|
|
@@ -1,22 +1,26 @@
|
|
|
1
|
+
import { describeErrorParts } from '@jini-ai/core';
|
|
1
2
|
import { redactSecretShapes } from '../core/secrets-only.js';
|
|
2
|
-
/** A low-cardinality error label:
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const label
|
|
13
|
-
return redactLabel(label).slice(0, MAX_ERROR_TYPE) || 'Error';
|
|
14
|
-
}
|
|
3
|
+
/** A low-cardinality error label: an approved code (`ECONNREFUSED`, `SQLITE_CONSTRAINT`), else the
|
|
4
|
+
* fixed class label (`TypeError`, a label from a describer the package built), both from core's `describeErrorParts`.
|
|
5
|
+
* This is the shape hosts' dashboards and alerts match on (review jini-batch1 M2: `Error(ECONNREFUSED)`
|
|
6
|
+
* silently broke them). Messages are never exported: they carry SQL fragments, hostnames, emails, even
|
|
7
|
+
* credentials. Both `error.code` and `Error.name` are writable secret channels (review 2026-10-25 #2),
|
|
8
|
+
* so an unapproved code or an unregistered class name is never printed (it reads as the class label,
|
|
9
|
+
* often `Error`; a package names its own through core's `createErrorDescriber`). The label is still
|
|
10
|
+
* redacted and capped to {@link MAX_ERROR_TYPE} (redact first: a cut could leave a secret prefix too
|
|
11
|
+
* short to match). */
|
|
12
|
+
export function errorType({ error }, { describer = BUILT_IN_DESCRIBER } = {}) {
|
|
13
|
+
const { label, code } = describer.describeErrorParts({ err: error });
|
|
14
|
+
return redactLabel({ text: code ?? label }).slice(0, MAX_ERROR_TYPE) || 'Error';
|
|
15
|
+
}
|
|
16
|
+
/** Core's built-in-only describer (pure); a host passes one from `createErrorDescriber` for its own vocabulary. */
|
|
17
|
+
const BUILT_IN_DESCRIBER = { describeErrorParts };
|
|
15
18
|
const MAX_ERROR_TYPE = 64;
|
|
16
19
|
const MAX_ATTRIBUTE_TEXT = 256;
|
|
17
20
|
const MAX_ATTRIBUTES = 64;
|
|
18
21
|
const ATTRIBUTE_KEY = /^[a-zA-Z][a-zA-Z0-9_.-]{0,63}$/;
|
|
19
|
-
|
|
22
|
+
/** The secret-shape redaction every adapter applies to a label before export. */
|
|
23
|
+
export function redactLabel({ text }, _optional = {}) {
|
|
20
24
|
return redactSecretShapes({ text, policy: {} }).text;
|
|
21
25
|
}
|
|
22
26
|
/** Feature attributes are documented as ids and fixed labels, but a caller can still hand over a
|
|
@@ -27,190 +31,11 @@ function redactLabel(text) {
|
|
|
27
31
|
export function redactOperationAttributes({ attributes }) {
|
|
28
32
|
const safe = {};
|
|
29
33
|
// Keys are a bounded label allow-list too: never export emails, URLs or credential-shaped keys.
|
|
30
|
-
const names = Object.keys(attributes).filter(name => ATTRIBUTE_KEY.test(name) && redactLabel(name) === name);
|
|
34
|
+
const names = Object.keys(attributes).filter(name => ATTRIBUTE_KEY.test(name) && redactLabel({ text: name }) === name);
|
|
31
35
|
for (const name of names.slice(0, MAX_ATTRIBUTES)) {
|
|
32
36
|
const value = attributes[name];
|
|
33
|
-
safe[name] = typeof value === 'string' ? redactLabel(value).slice(0, MAX_ATTRIBUTE_TEXT) : value;
|
|
37
|
+
safe[name] = typeof value === 'string' ? redactLabel({ text: value }).slice(0, MAX_ATTRIBUTE_TEXT) : value;
|
|
34
38
|
}
|
|
35
39
|
return safe;
|
|
36
40
|
}
|
|
37
|
-
/** Decode before classifying; malformed encodings and non-label segments fail closed.
|
|
38
|
-
* Only short alphabetic route words survive; ids, emails and opaque tokens become placeholders.
|
|
39
|
-
* @returns A safe path segment. @complexity O(s) segment text.
|
|
40
|
-
*/
|
|
41
|
-
function safePathSegment({ segment }, _options = {}) {
|
|
42
|
-
let decoded;
|
|
43
|
-
try {
|
|
44
|
-
decoded = decodeURIComponent(segment);
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return ':param';
|
|
48
|
-
}
|
|
49
|
-
if (decoded === '')
|
|
50
|
-
return '';
|
|
51
|
-
if (!/^[a-zA-Z-]{1,24}$/.test(decoded))
|
|
52
|
-
return ':param';
|
|
53
|
-
if (/^[a-fA-F]{8,}$/.test(decoded) || decoded.length >= 16)
|
|
54
|
-
return ':param';
|
|
55
|
-
return decoded;
|
|
56
|
-
}
|
|
57
|
-
/** Prefer a router-owned template. Otherwise drop query/fragment and replace sensitive-looking
|
|
58
|
-
* segments; raw ids no longer cross the export boundary (correlation belongs on explicit ids).
|
|
59
|
-
* @returns A bounded request target. @complexity O(p) path text.
|
|
60
|
-
*/
|
|
61
|
-
/** Cuts at the first `?` or `#`, as /[?#][\s\S]*$/ did, without its backtracking. */
|
|
62
|
-
function withoutQueryOrFragment(target) {
|
|
63
|
-
const cut = target.search(/[?#]/);
|
|
64
|
-
return cut === -1 ? target : target.slice(0, cut);
|
|
65
|
-
}
|
|
66
|
-
export function redactRequestTarget({ path }, { routePattern } = {}) {
|
|
67
|
-
if (routePattern && routePattern !== 'unmatched')
|
|
68
|
-
return withoutQueryOrFragment(routePattern).slice(0, 1024);
|
|
69
|
-
return withoutQueryOrFragment(path).split('/').map(segment => safePathSegment({ segment })).join('/').slice(0, 1024);
|
|
70
|
-
}
|
|
71
|
-
/** Scheme, host and explicit port only. Paths carry bot tokens and signed-URL keys; userinfo carries passwords. */
|
|
72
|
-
export function outboundTargetAttributes(url) {
|
|
73
|
-
let parsed;
|
|
74
|
-
try {
|
|
75
|
-
parsed = new URL(url);
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
78
|
-
return { 'server.address': 'invalid-url' };
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
'url.scheme': parsed.protocol.replace(/:$/, ''), 'server.address': parsed.hostname,
|
|
82
|
-
...(parsed.port ? { 'server.port': Number(parsed.port) } : {}),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
// Interrupted means the run died with its process; canceled and abandoned are not proven failures.
|
|
86
|
-
const FAILED_RUN_STATUSES = new Set(['failed', 'interrupted']);
|
|
87
|
-
/** Wraps an end handler so a second end() is ignored. */
|
|
88
|
-
function once(handler) {
|
|
89
|
-
let ended = false;
|
|
90
|
-
return (outcome) => {
|
|
91
|
-
if (ended)
|
|
92
|
-
return;
|
|
93
|
-
ended = true;
|
|
94
|
-
handler(outcome);
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/** Builds request, DB, outbound, agent-run and operation spans, and exception events for reported errors, through injected provider/exporter factories.
|
|
98
|
-
* @param required Explicit config and structural factories. Hosts wrap their SDK here.
|
|
99
|
-
* @param options Optional host scope storage; with it, spans started inside a tracker's run() are its children.
|
|
100
|
-
* @returns One adapter whose spans end once, with final names, redacted attributes and error status.
|
|
101
|
-
* @throws Provider/exporter errors propagate during setup. No globals or SDK imports are used.
|
|
102
|
-
*/
|
|
103
|
-
export function createOtelObservabilityPort({ config, exporterFactory, tracerProviderFactory }, { scope } = {}) {
|
|
104
|
-
const exporter = exporterFactory.create({ endpoint: config.endpoint });
|
|
105
|
-
const provider = tracerProviderFactory.create({ serviceName: config.serviceName, exporter });
|
|
106
|
-
const tracer = provider.getTracer({ name: config.tracerName });
|
|
107
|
-
const reportedSpans = new WeakSet();
|
|
108
|
-
/** Sets final attributes and ends, preserving an exception already recorded by reportError.
|
|
109
|
-
* Sink errors propagate to the caller. @complexity O(a) time/space for a attributes. */
|
|
110
|
-
function finish({ span, attributes }, { failure, error } = {}) {
|
|
111
|
-
for (const [name, value] of Object.entries(attributes))
|
|
112
|
-
span.setAttribute({ name, value });
|
|
113
|
-
if (failure !== undefined && !reportedSpans.has(span)) {
|
|
114
|
-
span.setAttribute({ name: 'error.type', value: failure });
|
|
115
|
-
span.setStatus({ code: 'error', description: failure });
|
|
116
|
-
if (error !== undefined)
|
|
117
|
-
span.addEvent({ name: 'exception', attributes: { 'exception.type': failure } });
|
|
118
|
-
}
|
|
119
|
-
span.end({});
|
|
120
|
-
}
|
|
121
|
-
function start({ name, kind, attributes }, { root = false } = {}) {
|
|
122
|
-
const parent = root ? undefined : scope?.active();
|
|
123
|
-
return tracer.startSpan({ name, kind, attributes }, parent ? { parent } : {});
|
|
124
|
-
}
|
|
125
|
-
function runIn(span) {
|
|
126
|
-
return (fn) => (scope ? scope.run({ span, fn }) : fn());
|
|
127
|
-
}
|
|
128
|
-
return {
|
|
129
|
-
supportsMetric: false,
|
|
130
|
-
activeTraceIds: (_required = {}, _optional = {}) => scope?.active()?.ids?.(),
|
|
131
|
-
// This structural tracing adapter has no metrics exporter; the provider plugin supplies it.
|
|
132
|
-
metric() { },
|
|
133
|
-
trackRequest(input, { requestId } = {}) {
|
|
134
|
-
// The id the response echoes is recorded on the span, so a reported id finds its trace.
|
|
135
|
-
const span = start({ name: input.method, kind: 'server', attributes: {
|
|
136
|
-
'http.method': input.method, 'http.target': redactRequestTarget({ path: input.path }), ...(requestId ? { 'http.request.id': requestId } : {}),
|
|
137
|
-
} });
|
|
138
|
-
return { ...(requestId ? { requestId } : {}), run: runIn(span), end: once((outcome) => {
|
|
139
|
-
// Routing finishes after startSpan, so open with a provisional name and assign the final
|
|
140
|
-
// pattern at end. The consumer port needs no separate rename operation to express that timing.
|
|
141
|
-
span.updateName({ name: `${input.method} ${outcome.routePattern}` });
|
|
142
|
-
span.setAttribute({ name: 'http.route', value: outcome.routePattern });
|
|
143
|
-
span.setAttribute({ name: 'http.target', value: redactRequestTarget({ path: input.path }, { routePattern: outcome.routePattern }) });
|
|
144
|
-
span.setAttribute({ name: 'http.status_code', value: outcome.statusCode });
|
|
145
|
-
if (outcome.statusCode >= 500 && !reportedSpans.has(span))
|
|
146
|
-
span.setStatus({ code: 'error' });
|
|
147
|
-
span.end({});
|
|
148
|
-
}) };
|
|
149
|
-
},
|
|
150
|
-
trackDbQuery({ system }) {
|
|
151
|
-
const span = start({ name: 'db', kind: 'client', attributes: { 'db.system.name': system } });
|
|
152
|
-
return { run: runIn(span), end: once(({ operation, table, error }) => {
|
|
153
|
-
// Same provisional-name timing as requests: the query is built inside the tracked body.
|
|
154
|
-
const op = operation.toUpperCase();
|
|
155
|
-
span.updateName({ name: table ? `${op} ${table}` : op });
|
|
156
|
-
finish({ span, attributes: { 'db.operation.name': op, ...(table ? { 'db.collection.name': table } : {}) } }, error !== undefined ? { failure: errorType(error), error } : {});
|
|
157
|
-
}) };
|
|
158
|
-
},
|
|
159
|
-
trackOutboundCall({ method, url }) {
|
|
160
|
-
const target = outboundTargetAttributes(url);
|
|
161
|
-
const span = start({ name: `${method} ${target['server.address']}`, kind: 'client', attributes: { 'http.request.method': method, ...target } });
|
|
162
|
-
return { run: runIn(span), end: once(({ statusCode, error }) => {
|
|
163
|
-
const attributes = statusCode !== undefined ? { 'http.response.status_code': statusCode } : {};
|
|
164
|
-
if (error !== undefined) {
|
|
165
|
-
finish({ span, attributes }, { failure: errorType(error), error });
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
// Client-span semantics: a 4xx is this caller's failure, unlike a server span's 4xx.
|
|
169
|
-
finish({ span, attributes }, statusCode !== undefined && statusCode >= 400 ? { failure: String(statusCode) } : {});
|
|
170
|
-
}) };
|
|
171
|
-
},
|
|
172
|
-
trackOperation({ name, attributes = {} }) {
|
|
173
|
-
const span = start({ name, kind: 'internal', attributes: redactOperationAttributes({ attributes }) });
|
|
174
|
-
return { run: runIn(span), end: once(({ outcome, failed, attributes: settled = {} }) => {
|
|
175
|
-
// The feature decides what counts as failure; its outcome label doubles as the error type.
|
|
176
|
-
finish({ span, attributes: redactOperationAttributes({ attributes: { ...settled, 'operation.outcome': outcome } }) }, failed ? { failure: redactLabel(outcome) } : {});
|
|
177
|
-
}) };
|
|
178
|
-
},
|
|
179
|
-
reportError({ error, context }) {
|
|
180
|
-
try {
|
|
181
|
-
// Inside a tracker's run() the exception lands on that tracker's span; elsewhere it is its own
|
|
182
|
-
// short root span. Type only, never the message: the same export rule errorType documents.
|
|
183
|
-
const active = scope?.active();
|
|
184
|
-
const span = active ?? start({ name: `error ${context.operation}`, kind: 'internal', attributes: redactOperationAttributes({ attributes: context.attributes ?? {} }) }, { root: true });
|
|
185
|
-
const type = errorType(error);
|
|
186
|
-
span.addEvent({ name: 'exception', attributes: { 'exception.type': type, 'operation.name': context.operation } });
|
|
187
|
-
span.setAttribute({ name: 'error.type', value: type });
|
|
188
|
-
span.setStatus({ code: 'error', description: type });
|
|
189
|
-
reportedSpans.add(span);
|
|
190
|
-
if (!active)
|
|
191
|
-
span.end({});
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
|
-
catch {
|
|
195
|
-
// Reporting is best-effort: a broken exporter must not turn an already-handled failure into a crash.
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
trackAgentRun({ runId }, { conversationId, agentName } = {}) {
|
|
200
|
-
// A run outlives the request that started it, so it is its own trace rather than a long child.
|
|
201
|
-
const span = start({ name: agentName ? `invoke_agent ${agentName}` : 'invoke_agent', kind: 'internal', attributes: {
|
|
202
|
-
'gen_ai.operation.name': 'invoke_agent', ...(agentName ? { 'gen_ai.agent.name': agentName } : {}),
|
|
203
|
-
...(conversationId ? { 'gen_ai.conversation.id': conversationId } : {}), 'agent.run.id': runId,
|
|
204
|
-
} }, { root: true });
|
|
205
|
-
return { run: runIn(span), end: once(({ status, error }) => {
|
|
206
|
-
const attributes = { 'agent.run.status': status };
|
|
207
|
-
if (error !== undefined) {
|
|
208
|
-
finish({ span, attributes }, { failure: errorType(error), error });
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
finish({ span, attributes }, FAILED_RUN_STATUSES.has(status) ? { failure: status } : {});
|
|
212
|
-
}) };
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
41
|
//# sourceMappingURL=otel.js.map
|
|
@@ -1,153 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Consumers speak in request lifecycle terms rather than Span/Tracer SDK types. That permits
|
|
4
|
-
* replacing the instrumentation system itself, not merely its exporter backend. Add signals
|
|
5
|
-
* only against real instrumentation call sites; guessed DB/outbound/agent shapes would couple
|
|
6
|
-
* consumers to contracts whose lifecycle has not yet been established.
|
|
7
|
-
* The DB/outbound/agent signals below were each shaped after their first real call site: the
|
|
8
|
-
* storage kernel's run/transaction body, the guarded HTTP client's send, and a host's agent-run
|
|
9
|
-
* watcher. Inputs carry ids and fixed labels only; adapters own redaction of anything raw.
|
|
10
|
-
*/
|
|
11
|
-
export interface RequestTrackingInput {
|
|
12
|
-
method: string;
|
|
13
|
-
path: string;
|
|
14
|
-
}
|
|
15
|
-
export interface RequestTrackingOptions {
|
|
16
|
-
requestId?: string;
|
|
17
|
-
}
|
|
18
|
-
/** The mount-aware pattern is available only after routing; raw paths are known at request start.
|
|
19
|
-
* Use a fixed 'unmatched' label for misses: attacker-controlled paths would make grouping unbounded. */
|
|
20
|
-
export interface RequestTrackingOutcome {
|
|
21
|
-
statusCode: number;
|
|
22
|
-
routePattern: string;
|
|
23
|
-
}
|
|
24
|
-
/** Runs work inside a tracker's scope, so signals that work starts are attributed to it. */
|
|
25
|
-
export interface TrackerScope {
|
|
26
|
-
run<T>(fn: () => T): T;
|
|
27
|
-
}
|
|
28
|
-
export interface RequestTracker {
|
|
29
|
-
readonly requestId?: string;
|
|
30
|
-
end(outcome: RequestTrackingOutcome): void;
|
|
31
|
-
/** Optional so adapters written before scoping still satisfy the port; callers fall back to fn(). */
|
|
32
|
-
run?<T>(fn: () => T): T;
|
|
33
|
-
}
|
|
34
|
-
/** `system` is the engine family (`sqlite`, `postgresql`); statement text never crosses the port. */
|
|
35
|
-
export interface DbQueryTrackingInput {
|
|
36
|
-
system: string;
|
|
37
|
-
}
|
|
38
|
-
/** Like a route pattern, the operation and table are known only once the query has been built. */
|
|
39
|
-
export interface DbQueryTrackingOutcome {
|
|
40
|
-
operation: string;
|
|
41
|
-
table?: string;
|
|
42
|
-
error?: unknown;
|
|
43
|
-
}
|
|
44
|
-
export interface DbQueryTracker extends TrackerScope {
|
|
45
|
-
end(outcome: DbQueryTrackingOutcome): void;
|
|
46
|
-
}
|
|
47
|
-
/** The raw URL is handed over whole; adapters keep scheme/host/port and drop path, query and userinfo. */
|
|
48
|
-
export interface OutboundCallTrackingInput {
|
|
49
|
-
method: string;
|
|
50
|
-
url: string;
|
|
51
|
-
}
|
|
52
|
-
/** `statusCode` when a response arrived, `error` when the call failed before one did. */
|
|
53
|
-
export interface OutboundCallTrackingOutcome {
|
|
54
|
-
statusCode?: number;
|
|
55
|
-
error?: unknown;
|
|
56
|
-
}
|
|
57
|
-
export interface OutboundCallTracker extends TrackerScope {
|
|
58
|
-
end(outcome: OutboundCallTrackingOutcome): void;
|
|
59
|
-
}
|
|
60
|
-
export interface AgentRunTrackingInput {
|
|
61
|
-
runId: string;
|
|
62
|
-
}
|
|
63
|
-
export interface AgentRunTrackingOptions {
|
|
64
|
-
conversationId?: string;
|
|
65
|
-
agentName?: string;
|
|
66
|
-
}
|
|
67
|
-
/** `interrupted`: the run vanished (its process restarted). `abandoned`: the watcher gave up unproven. */
|
|
68
|
-
export type AgentRunStatus = 'succeeded' | 'failed' | 'canceled' | 'interrupted' | 'abandoned';
|
|
69
|
-
export interface AgentRunTrackingOutcome {
|
|
70
|
-
status: AgentRunStatus;
|
|
71
|
-
error?: unknown;
|
|
72
|
-
}
|
|
73
|
-
export interface AgentRunTracker extends TrackerScope {
|
|
74
|
-
end(outcome: AgentRunTrackingOutcome): void;
|
|
75
|
-
}
|
|
76
|
-
/** Fixed labels and ids only (a tool id, a run id): never user text, paths, or values a caller sent. */
|
|
77
|
-
export type OperationAttributes = Readonly<Record<string, string | number>>;
|
|
78
|
-
/**
|
|
79
|
-
* A feature-level unit of work (one tool call, one publish, one backup) that no transport signal
|
|
80
|
-
* names: the HTTP request, DB queries and outbound calls it makes nest under it. `name` is a fixed
|
|
81
|
-
* dotted label (`tool.call`), never per-call text, so grouping stays bounded.
|
|
82
|
-
*/
|
|
83
|
-
export interface OperationTrackingInput {
|
|
84
|
-
name: string;
|
|
85
|
-
attributes?: OperationAttributes;
|
|
86
|
-
}
|
|
87
|
-
/** `outcome` is the feature's own fixed label (`completed`, `denied`, `timed-out`); `failed` says
|
|
88
|
-
* whether that outcome is a failure, which only the feature can judge (a denial is not one). */
|
|
89
|
-
export interface OperationTrackingOutcome {
|
|
90
|
-
outcome: string;
|
|
91
|
-
failed: boolean;
|
|
92
|
-
attributes?: OperationAttributes;
|
|
93
|
-
}
|
|
94
|
-
export interface OperationTracker extends TrackerScope {
|
|
95
|
-
end(outcome: OperationTrackingOutcome): void;
|
|
96
|
-
}
|
|
97
|
-
/** Correlation assigned by an active tracing implementation; readers never generate IDs. */
|
|
98
|
-
export interface TraceIds {
|
|
99
|
-
readonly traceId: string;
|
|
100
|
-
readonly spanId: string;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* An error worth an incident report (an error tracker's issue; a trace's exception event), as
|
|
104
|
-
* opposed to an expected failure a tracker's outcome already records. `error` is handed over raw:
|
|
105
|
-
* adapters own redaction (see `describeReportedError`), exactly as they do for request targets.
|
|
106
|
-
*/
|
|
107
|
-
export interface ErrorReport {
|
|
108
|
-
error: unknown;
|
|
109
|
-
context: {
|
|
110
|
-
operation: string;
|
|
111
|
-
attributes?: OperationAttributes;
|
|
112
|
-
level?: 'warning' | 'error';
|
|
113
|
-
trace?: TraceIds;
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
/** Native crash upload configuration. Provider-specific field names stay opaque to hosts. */
|
|
117
|
-
export interface CrashUpload {
|
|
118
|
-
submitURL: string;
|
|
119
|
-
globalExtra: Readonly<Record<string, string>>;
|
|
120
|
-
}
|
|
121
|
-
/** Vendor-neutral numeric measurement; names and units are fixed labels, never user text. */
|
|
122
|
-
export interface MetricInput {
|
|
123
|
-
name: string;
|
|
124
|
-
value: number;
|
|
125
|
-
}
|
|
126
|
-
export interface MetricOptions {
|
|
127
|
-
kind?: 'counter' | 'gauge' | 'histogram';
|
|
128
|
-
unit?: string;
|
|
129
|
-
attributes?: OperationAttributes;
|
|
130
|
-
}
|
|
131
|
-
export interface ObservabilityPort {
|
|
132
|
-
/** Current structural tracing scope, absent outside a trace. Never generates an ID. */
|
|
133
|
-
activeTraceIds?(required?: Record<string, never>, optional?: Record<string, never>): TraceIds | undefined;
|
|
134
|
-
/** Explicit capability: a callable noop metric does not imply local metric admission. */
|
|
135
|
-
readonly supportsMetric?: boolean;
|
|
136
|
-
/** Records one measurement; adapters without a metrics backend use a no-op. */
|
|
137
|
-
metric(input: MetricInput, options?: MetricOptions): void | Promise<void>;
|
|
138
|
-
trackRequest(input: RequestTrackingInput, options?: RequestTrackingOptions): RequestTracker;
|
|
139
|
-
trackDbQuery(input: DbQueryTrackingInput): DbQueryTracker;
|
|
140
|
-
trackOutboundCall(input: OutboundCallTrackingInput): OutboundCallTracker;
|
|
141
|
-
trackAgentRun(input: AgentRunTrackingInput, options?: AgentRunTrackingOptions): AgentRunTracker;
|
|
142
|
-
trackOperation(input: OperationTrackingInput): OperationTracker;
|
|
143
|
-
/** Called inside a tracker's run() it is attributed to that tracker's work. False refuses local admission; void accepts it. */
|
|
144
|
-
reportError(report: ErrorReport): boolean | void | Promise<boolean | void>;
|
|
145
|
-
/** Configuration only; the host owns crash collection, consent and upload lifecycle. */
|
|
146
|
-
crashUpload?(required: {
|
|
147
|
-
release: string;
|
|
148
|
-
environment: string;
|
|
149
|
-
}, optional?: Record<string, never>): CrashUpload;
|
|
150
|
-
}
|
|
1
|
+
import type { RequestTrackingOutcome, TraceIds } from '@jini-ai/core/contracts/observability';
|
|
151
2
|
export interface RequestObservation extends RequestTrackingOutcome {
|
|
152
3
|
requestId: string;
|
|
153
4
|
method: string;
|
|
@@ -183,17 +34,6 @@ export interface TraceSpanPort {
|
|
|
183
34
|
}): void;
|
|
184
35
|
end(required: Record<string, never>): void;
|
|
185
36
|
}
|
|
186
|
-
export type TraceSpanKind = 'server' | 'client' | 'internal';
|
|
187
|
-
export interface TracerPort {
|
|
188
|
-
/** `parent` is a span this tracer returned earlier; absent means a root span. */
|
|
189
|
-
startSpan(required: {
|
|
190
|
-
name: string;
|
|
191
|
-
kind: TraceSpanKind;
|
|
192
|
-
attributes: Record<string, string | number>;
|
|
193
|
-
}, optional?: {
|
|
194
|
-
parent?: TraceSpanPort;
|
|
195
|
-
}): TraceSpanPort;
|
|
196
|
-
}
|
|
197
37
|
/** Host-owned active-span storage (Node: AsyncLocalStorage). Without one, every span is a root. */
|
|
198
38
|
export interface SpanScopePort {
|
|
199
39
|
active(): TraceSpanPort | undefined;
|
|
@@ -202,27 +42,4 @@ export interface SpanScopePort {
|
|
|
202
42
|
fn: () => T;
|
|
203
43
|
}): T;
|
|
204
44
|
}
|
|
205
|
-
export interface TracerProviderPort {
|
|
206
|
-
getTracer(required: {
|
|
207
|
-
name: string;
|
|
208
|
-
}): TracerPort;
|
|
209
|
-
}
|
|
210
|
-
export interface ExporterFactory {
|
|
211
|
-
create(required: {
|
|
212
|
-
endpoint: string;
|
|
213
|
-
}): unknown;
|
|
214
|
-
}
|
|
215
|
-
export interface TracerProviderFactory {
|
|
216
|
-
create(required: {
|
|
217
|
-
serviceName: string;
|
|
218
|
-
exporter: unknown;
|
|
219
|
-
}): TracerProviderPort;
|
|
220
|
-
}
|
|
221
|
-
/** What a vendor provider subpath returns: the port plus the host-owned lifecycle hook. The host
|
|
222
|
-
* registers `dispose` with its teardown (a closed site, a stopped process) so SDK clients, timers
|
|
223
|
-
* and exit listeners are released (review 2026-10-25 #6). `dispose` never throws. */
|
|
224
|
-
export interface ObservabilityAdapter {
|
|
225
|
-
port: ObservabilityPort;
|
|
226
|
-
dispose(): Promise<void>;
|
|
227
|
-
}
|
|
228
45
|
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The observability domain's provider contract descriptor: the port check plus the helper values every
|
|
2
|
+
* observability provider receives as its factory's `optional.context`. Hosts register it with their
|
|
3
|
+
* provider host; plugins never supply or replace the validator. */
|
|
4
|
+
import { resolveObservabilityConfig } from './config.js';
|
|
5
|
+
import { describeTelemetryFailure } from './delivery.js';
|
|
6
|
+
import { describeReportedError } from './errors.js';
|
|
7
|
+
import { errorType, redactLabel, redactOperationAttributes } from './otel.js';
|
|
8
|
+
export declare const observabilityProviderContract: {
|
|
9
|
+
readonly contract: 'observability';
|
|
10
|
+
readonly validate: (required: {
|
|
11
|
+
provider: unknown;
|
|
12
|
+
}, optional?: Record<string, never>) => string | undefined;
|
|
13
|
+
readonly context: {
|
|
14
|
+
readonly redactOperationAttributes: typeof redactOperationAttributes;
|
|
15
|
+
readonly errorType: typeof errorType;
|
|
16
|
+
readonly redactLabel: typeof redactLabel;
|
|
17
|
+
readonly describeReportedError: typeof describeReportedError;
|
|
18
|
+
readonly describeTelemetryFailure: typeof describeTelemetryFailure;
|
|
19
|
+
readonly resolveObservabilityConfig: typeof resolveObservabilityConfig;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=provider-contract.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** The observability domain's provider contract descriptor: the port check plus the helper values every
|
|
2
|
+
* observability provider receives as its factory's `optional.context`. Hosts register it with their
|
|
3
|
+
* provider host; plugins never supply or replace the validator. */
|
|
4
|
+
import { resolveObservabilityConfig } from './config.js';
|
|
5
|
+
import { describeTelemetryFailure } from './delivery.js';
|
|
6
|
+
import { describeReportedError } from './errors.js';
|
|
7
|
+
import { errorType, redactLabel, redactOperationAttributes } from './otel.js';
|
|
8
|
+
const PORT_METHODS = ['trackRequest', 'trackDbQuery', 'trackOutboundCall', 'trackAgentRun', 'trackOperation', 'reportError'];
|
|
9
|
+
/** `metric` is not required: contract v1 providers predate it, and callers route a missing method to the noop. */
|
|
10
|
+
function observabilityPortProblem({ provider }, _optional = {}) {
|
|
11
|
+
const record = typeof provider === 'object' && provider !== null ? provider : undefined;
|
|
12
|
+
return record && PORT_METHODS.every(name => typeof record[name] === 'function') ? undefined : 'not an ObservabilityPort';
|
|
13
|
+
}
|
|
14
|
+
export const observabilityProviderContract = {
|
|
15
|
+
contract: 'observability',
|
|
16
|
+
validate: observabilityPortProblem,
|
|
17
|
+
context: { redactOperationAttributes, errorType, redactLabel, describeReportedError, describeTelemetryFailure, resolveObservabilityConfig },
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=provider-contract.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ObservabilityPort } from "
|
|
1
|
+
import type { ObservabilityPort } from "@jini-ai/core/contracts/observability";
|
|
2
2
|
/**
|
|
3
3
|
* @file The shared way a host hands an error to `ObservabilityPort.reportError` (provider wave 2,
|
|
4
4
|
* 2026-10-25): request 5xx, process guards, assistant failures and `trackAsyncOperation` all come
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentRunTrackingInput, AgentRunTrackingOptions, AgentRunTrackingOutcome, ObservabilityPort, OperationAttributes, OperationTrackingOutcome, RequestTrackingInput, RequestTrackingOptions, RequestTrackingOutcome, MetricInput, MetricOptions } from "
|
|
1
|
+
import type { AgentRunTrackingInput, AgentRunTrackingOptions, AgentRunTrackingOutcome, ObservabilityPort, OperationAttributes, OperationTrackingOutcome, RequestTrackingInput, RequestTrackingOptions, RequestTrackingOutcome, MetricInput, MetricOptions } from "@jini-ai/core/contracts/observability";
|
|
2
2
|
/** Capture-only consumer port; higher-layer analytics adapters satisfy it structurally. */
|
|
3
3
|
interface CaptureEvent {
|
|
4
4
|
name: string;
|
|
@@ -40,7 +40,7 @@ export interface AgentSpanOptions {
|
|
|
40
40
|
* Required fields precede optional settings; no provider-specific types cross this boundary. */
|
|
41
41
|
export interface Tracker {
|
|
42
42
|
/** Current tracing IDs, absent without an active span; optional for older host facades. */
|
|
43
|
-
activeTraceIds?(required?: Record<string, never>, optional?: Record<string, never>): import('
|
|
43
|
+
activeTraceIds?(required?: Record<string, never>, optional?: Record<string, never>): import('@jini-ai/core/contracts/observability').TraceIds | undefined;
|
|
44
44
|
/** Awaitable local admission; does not wait for remote delivery. */
|
|
45
45
|
capture(input: Pick<CaptureEvent, "name" | "userId">, options?: Pick<CaptureEvent, "properties">): void | Promise<void>;
|
|
46
46
|
error(input: {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createNoopTracker } from "./tracker-noop.js";
|
|
2
|
-
import { isNoopObservabilityPort } from "
|
|
2
|
+
import { isNoopObservabilityPort } from "@jini-ai/core/contracts/observability";
|
|
3
3
|
import { combineObservabilityPorts } from "./fanout.js";
|
|
4
4
|
import { reportErrorOnce, runWithErrorReportScope } from "./report-error.js";
|
|
5
|
+
import { createConsoleLogger } from '@jini-ai/core/primitives';
|
|
5
6
|
/** Fixed diagnostic, once per facade; provider errors can contain credentials and are never logged.
|
|
6
7
|
* @complexity O(1) time/space. */
|
|
7
|
-
export function createTrackerWarning(_required, { warn = (message) =>
|
|
8
|
+
export function createTrackerWarning(_required, { warn = (message) => createConsoleLogger({ prefix: '' }).warn({ message }) } = {}) {
|
|
8
9
|
let reported = false;
|
|
9
10
|
return () => {
|
|
10
11
|
if (reported)
|
package/dist/sources.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describeErrorForLog } from "@jini-ai/core";
|
|
1
2
|
import { join } from "node:path";
|
|
2
3
|
import { readDirectorySafe, statSafe } from "./discovery-filesystem.js";
|
|
3
4
|
import { redactJsonText, redactText } from "./redaction.js";
|
|
@@ -16,7 +17,7 @@ export async function collectLogSource({ source, filesystem }, opts = {}) {
|
|
|
16
17
|
absolutePath: source.absolutePath,
|
|
17
18
|
content: null,
|
|
18
19
|
bytes: 0,
|
|
19
|
-
error:
|
|
20
|
+
error: describeErrorForLog({ err: error }),
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads at most `maxBytes` from a fetch response body, stopping the stream once the cap is hit.
|
|
3
|
+
*
|
|
4
|
+
* Stops rather than buffering-then-slicing so an unexpectedly large route cannot be used to
|
|
5
|
+
* exhaust memory. Decoding is UTF-8 and non-strict, so a multi-byte character split by the cap
|
|
6
|
+
* degrades to a replacement character instead of throwing.
|
|
7
|
+
*
|
|
8
|
+
* @param required.response - The fetch response.
|
|
9
|
+
* @param required.maxBytes - Cap, already clamped by the caller.
|
|
10
|
+
* @returns The decoded text, how many bytes were read, and whether the cap stopped the read.
|
|
11
|
+
* @complexity O(min(B, maxBytes)) in the response size.
|
|
12
|
+
* @example await readBoundedBody({ response: res, maxBytes: 200_000 });
|
|
13
|
+
*/
|
|
14
|
+
export declare function readBoundedBody({ response, maxBytes }: {
|
|
15
|
+
response: Response;
|
|
16
|
+
maxBytes: number;
|
|
17
|
+
}, _optional?: {}): Promise<{
|
|
18
|
+
body: string;
|
|
19
|
+
bodyBytes: number;
|
|
20
|
+
truncated: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
//# sourceMappingURL=bounded-body.d.ts.map
|