@jini-ai/diagnostics 0.6.12 → 0.6.15-rc.2
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 +30 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/memory-growth.d.ts +57 -0
- package/dist/memory-growth.js +105 -0
- package/dist/observability/delivery.d.ts +44 -0
- package/dist/observability/delivery.js +65 -0
- package/dist/observability/errors.d.ts +15 -0
- package/dist/observability/errors.js +25 -0
- package/dist/observability/fanout.d.ts +18 -0
- package/dist/observability/fanout.js +165 -0
- package/dist/observability/hooks.d.ts +2 -2
- package/dist/observability/hooks.js +7 -2
- package/dist/observability/index.d.ts +6 -0
- package/dist/observability/index.js +4 -0
- package/dist/observability/node.d.ts +3 -0
- package/dist/observability/node.js +3 -0
- package/dist/observability/noop.js +5 -0
- package/dist/observability/otel.d.ts +22 -5
- package/dist/observability/otel.js +108 -25
- package/dist/observability/ports.d.ts +78 -0
- package/dist/observability/report-error.d.ts +59 -0
- package/dist/observability/report-error.js +81 -0
- package/dist/observability/telemetry-test.d.ts +28 -0
- package/dist/observability/telemetry-test.js +46 -0
- package/dist/observability/tracker-noop.d.ts +6 -0
- package/dist/observability/tracker-noop.js +10 -0
- package/dist/observability/tracker-types.d.ts +61 -0
- package/dist/observability/tracker-types.js +2 -0
- package/dist/observability/tracker.d.ts +13 -0
- package/dist/observability/tracker.js +114 -0
- package/dist/redaction.d.ts +11 -0
- package/dist/redaction.js +65 -0
- package/package.json +8 -3
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Tracker, TrackerOptions, TrackerProviders } from "./tracker-types.js";
|
|
2
|
+
/** Fixed diagnostic, once per facade; provider errors can contain credentials and are never logged.
|
|
3
|
+
* @complexity O(1) time/space. */
|
|
4
|
+
export declare function createTrackerWarning(_required: Record<string, never>, { warn }?: TrackerOptions): () => void;
|
|
5
|
+
/** One facade over existing ports: consent/identity remain on the composed providers, error
|
|
6
|
+
* deduplication/redaction stays with reportErrorOnce, scope containment stays with fanout.
|
|
7
|
+
* Missing providers do nothing; trace still runs work exactly once and preserves its result/error.
|
|
8
|
+
* @param required Optional, already-composed providers; an empty object disables telemetry.
|
|
9
|
+
* @param optional A warning sink, called once with a fixed message on any provider failure.
|
|
10
|
+
* @complexity O(1) facade state; delivery/redaction costs remain with the existing ports.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createTracker(required: TrackerProviders, optional?: TrackerOptions): Tracker;
|
|
13
|
+
//# sourceMappingURL=tracker.d.ts.map
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { isNoopProductAnalytics } from "@jini-ai/analytics/product";
|
|
2
|
+
import { createNoopTracker } from "./tracker-noop.js";
|
|
3
|
+
import { isNoopObservabilityPort } from "./noop.js";
|
|
4
|
+
import { combineObservabilityPorts } from "./fanout.js";
|
|
5
|
+
import { reportErrorOnce, runWithErrorReportScope } from "./report-error.js";
|
|
6
|
+
/** Fixed diagnostic, once per facade; provider errors can contain credentials and are never logged.
|
|
7
|
+
* @complexity O(1) time/space. */
|
|
8
|
+
export function createTrackerWarning(_required, { warn = (message) => console.warn(message) } = {}) {
|
|
9
|
+
let reported = false;
|
|
10
|
+
return () => {
|
|
11
|
+
if (reported)
|
|
12
|
+
return;
|
|
13
|
+
reported = true;
|
|
14
|
+
try {
|
|
15
|
+
warn("[tracker] a telemetry provider failed; application work continues");
|
|
16
|
+
}
|
|
17
|
+
catch { /* Logging must not fail application work either. */ }
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Select the existing lifecycle owner; overloads keep request/agent outcomes typed at callers.
|
|
21
|
+
* @complexity O(1) around the injected port. */
|
|
22
|
+
function startSpan({ observability, name, options }) {
|
|
23
|
+
if ("request" in options)
|
|
24
|
+
return observability.trackRequest({ method: options.request.method, path: options.request.path }, options.request.requestId === undefined ? {} : { requestId: options.request.requestId });
|
|
25
|
+
if ("agent" in options)
|
|
26
|
+
return observability.trackAgentRun({ runId: options.agent.runId }, {
|
|
27
|
+
...(options.agent.conversationId === undefined ? {} : { conversationId: options.agent.conversationId }),
|
|
28
|
+
...(options.agent.agentName === undefined ? {} : { agentName: options.agent.agentName }),
|
|
29
|
+
});
|
|
30
|
+
return observability.trackOperation({ name, ...(options.attributes ? { attributes: options.attributes } : {}) });
|
|
31
|
+
}
|
|
32
|
+
/** Choose the lifecycle's typed default or failure outcome. @complexity O(1). */
|
|
33
|
+
function spanOutcome({ options, failure }) {
|
|
34
|
+
if ("request" in options)
|
|
35
|
+
return { statusCode: 500, routePattern: "unmatched" };
|
|
36
|
+
if ("agent" in options)
|
|
37
|
+
return failure ? { status: "failed", error: failure.error } : { status: "succeeded" };
|
|
38
|
+
return { outcome: failure ? "error" : "completed", failed: failure !== undefined };
|
|
39
|
+
}
|
|
40
|
+
/** A throw replaces only an earlier success: cancellation, interruption and an explicit failure
|
|
41
|
+
* keep their more specific labels (a 503, `quota_exceeded`, `interrupted`).
|
|
42
|
+
* @returns The final lifecycle outcome, preserving a known request route. @complexity O(1).
|
|
43
|
+
*/
|
|
44
|
+
function thrownOutcome({ options, outcome, error }, _options = {}) {
|
|
45
|
+
if (!outcome)
|
|
46
|
+
return spanOutcome({ options, failure: { error } });
|
|
47
|
+
if ("statusCode" in outcome)
|
|
48
|
+
return outcome.statusCode >= 500 ? outcome : { ...outcome, statusCode: 500 };
|
|
49
|
+
if ("status" in outcome)
|
|
50
|
+
return outcome.status === "succeeded" ? { status: "failed", error } : outcome;
|
|
51
|
+
return outcome.failed || ["canceled", "cancelled"].includes(outcome.outcome) ? outcome : spanOutcome({ options, failure: { error } });
|
|
52
|
+
}
|
|
53
|
+
/** One facade over existing ports: consent/identity remain on the composed providers, error
|
|
54
|
+
* deduplication/redaction stays with reportErrorOnce, scope containment stays with fanout.
|
|
55
|
+
* Missing providers do nothing; trace still runs work exactly once and preserves its result/error.
|
|
56
|
+
* @param required Optional, already-composed providers; an empty object disables telemetry.
|
|
57
|
+
* @param optional A warning sink, called once with a fixed message on any provider failure.
|
|
58
|
+
* @complexity O(1) facade state; delivery/redaction costs remain with the existing ports.
|
|
59
|
+
*/
|
|
60
|
+
export function createTracker(required, optional = {}) {
|
|
61
|
+
if ((!required.observability || isNoopObservabilityPort(required.observability)) && (!required.productAnalytics || isNoopProductAnalytics(required.productAnalytics)))
|
|
62
|
+
return createNoopTracker({});
|
|
63
|
+
const failed = createTrackerWarning({}, optional);
|
|
64
|
+
const observability = combineObservabilityPorts({ ports: required.observability ? [required.observability] : [] }, { onFailure: failed });
|
|
65
|
+
// Takes unknown so trace hands a thrown non-Error over as-is: reportErrorOnce redacts it, and the
|
|
66
|
+
// same object then dedups as it propagates through nested traces (a fresh wrapper never would).
|
|
67
|
+
const report = ({ failure }, { context = {} } = {}) => {
|
|
68
|
+
try {
|
|
69
|
+
const attributes = context.route ? { ...context.attributes, route: context.route } : context.attributes;
|
|
70
|
+
reportErrorOnce({ observability, error: failure, operation: context.operation ?? "application.error" }, {
|
|
71
|
+
...(attributes ? { attributes } : {}),
|
|
72
|
+
...(context.exactSecrets === undefined ? {} : { exactSecrets: context.exactSecrets }),
|
|
73
|
+
...(context.level === undefined ? {} : { level: context.level }),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
failed();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const error = ({ error: failure }, options = {}) => report({ failure }, options);
|
|
81
|
+
async function trace({ name, run: work }, options = {}) {
|
|
82
|
+
return runWithErrorReportScope({ scope: { reported: false }, work: async () => {
|
|
83
|
+
const lifecycle = startSpan({ observability, name, options });
|
|
84
|
+
let outcome;
|
|
85
|
+
const handle = { setOutcome: (value) => { outcome ??= value; } };
|
|
86
|
+
const run = (fn) => lifecycle.run ? lifecycle.run(fn) : fn();
|
|
87
|
+
try {
|
|
88
|
+
return await run(() => work(handle));
|
|
89
|
+
}
|
|
90
|
+
catch (failure) {
|
|
91
|
+
run(() => report({ failure }, { context: { operation: name } }));
|
|
92
|
+
outcome = thrownOutcome({ options, outcome, error: failure });
|
|
93
|
+
throw failure;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
// Request callbacks normally settle with their response outcome, including disconnects.
|
|
97
|
+
lifecycle.end(outcome ?? spanOutcome({ options }));
|
|
98
|
+
}
|
|
99
|
+
} }, { reuseCurrent: true });
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
activeTraceIds: (_required = {}, _optional = {}) => observability.activeTraceIds?.(),
|
|
103
|
+
capture(input, options = {}) { try {
|
|
104
|
+
return Promise.resolve(required.productAnalytics?.capture({ ...input, ...options })).catch(failed);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
failed();
|
|
108
|
+
} },
|
|
109
|
+
metric(input, options = {}) { observability.metric(input, options); },
|
|
110
|
+
error,
|
|
111
|
+
trace: trace,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=tracker.js.map
|
package/dist/redaction.d.ts
CHANGED
|
@@ -13,4 +13,15 @@ export declare function redactText({ text }: {
|
|
|
13
13
|
export declare function redactJsonText({ text }: {
|
|
14
14
|
text: string;
|
|
15
15
|
}, opts?: RedactionOptions): string;
|
|
16
|
+
/**
|
|
17
|
+
* Mask local paths in error text; explicitly retained roots expose only app-relative filenames.
|
|
18
|
+
* Supports POSIX, home-relative, Windows, UNC and file URLs on every host OS. Never reads files.
|
|
19
|
+
* @returns Masked text, with stack line/column suffixes preserved. Malformed file URLs are masked.
|
|
20
|
+
* @complexity O(nr) time, O(n) output space for text length n and a fixed set of r retained roots.
|
|
21
|
+
*/
|
|
22
|
+
export declare function maskLocalPaths({ text }: {
|
|
23
|
+
text: string;
|
|
24
|
+
}, { keepRoots }?: {
|
|
25
|
+
keepRoots?: readonly string[];
|
|
26
|
+
}): string;
|
|
16
27
|
//# sourceMappingURL=redaction.d.ts.map
|
package/dist/redaction.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { SECRET_SHAPE_PATTERNS } from "@jini-ai/core";
|
|
2
|
+
import { pathContains } from "@jini-ai/core/primitives";
|
|
3
|
+
import { posix, win32 } from "node:path";
|
|
2
4
|
const SENSITIVE_KEY_RE = /token|password|secret|key|dsn|authorization|cookie/i;
|
|
3
5
|
const URL_QUERY_SECRET_RE = /([?&#])(token|password|secret|key|dsn|api[_-]?key|auth|access_token|refresh_token|id_token)(=)([^&\s#"']*)/gi;
|
|
4
6
|
// Catch loose key=value pairs in log lines that aren't inside a URL — e.g. env
|
|
@@ -75,4 +77,67 @@ export function redactJsonText({ text }, opts = {}) {
|
|
|
75
77
|
}
|
|
76
78
|
return JSON.stringify(redactJsonValue({ value: parsed }, opts), null, 2);
|
|
77
79
|
}
|
|
80
|
+
// Delimited stack/quoted paths may contain spaces. Other paths end at whitespace or punctuation.
|
|
81
|
+
// Each alternative consumes one path in a forward scan; no nested repetitions or wildcard retries.
|
|
82
|
+
// `<`/`>` stay inside a plain path: an upstream username redaction yields `/Users/<USER>/…`, whose
|
|
83
|
+
// tail would otherwise escape after a masked `/Users/` prefix.
|
|
84
|
+
const LOCAL_PATH_RE = /(["'(])((?:file:\/\/|[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)[^"'()\r\n]*)(["')])|(^|[\s="'(<[\]{},;`])((?:file:\/\/|[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)[^\s"'`()[\]{},;]*)/g;
|
|
85
|
+
const QUOTED_LOCAL_PATH_RE = /(["'])((?:file:\/\/|[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)[^"'\r\n]*)\1/g;
|
|
86
|
+
/** Decode local file URLs independently of the host OS; invalid URLs are always masked. O(n). */
|
|
87
|
+
function decodedLocalPath({ value }, _options = {}) {
|
|
88
|
+
// Treat ~ as a lexical root, never expand it using the current user's home directory.
|
|
89
|
+
if (value.startsWith('~/'))
|
|
90
|
+
return `/${value}`;
|
|
91
|
+
// A home-relative Windows path (`~\…`, as a host's home redaction writes it) gets a UNC-shaped root.
|
|
92
|
+
if (value.startsWith('~\\'))
|
|
93
|
+
return `\\\\${value}`;
|
|
94
|
+
if (!value.startsWith('file://'))
|
|
95
|
+
return value;
|
|
96
|
+
try {
|
|
97
|
+
const url = new URL(value);
|
|
98
|
+
const pathname = decodeURIComponent(url.pathname);
|
|
99
|
+
if (url.hostname && url.hostname !== 'localhost')
|
|
100
|
+
return `\\\\${url.hostname}${pathname.replace(/\//g, '\\')}`;
|
|
101
|
+
return pathname.replace(/^\/([A-Za-z]:\/)/, '$1');
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** Keep only a lexically contained app-relative path; no filesystem or cwd is consulted. O(nr). */
|
|
108
|
+
function maskedLocalPath({ value, keepRoots }, _options = {}) {
|
|
109
|
+
const coordinates = /(?::\d+){1,2}$/.exec(value)?.[0] ?? '';
|
|
110
|
+
const path = decodedLocalPath({ value: value.slice(0, value.length - coordinates.length) });
|
|
111
|
+
if (path === undefined)
|
|
112
|
+
return `<path>${coordinates}`;
|
|
113
|
+
return `${retainedPath({ path, keepRoots }) ?? '<path>'}${coordinates}`;
|
|
114
|
+
}
|
|
115
|
+
/** The first retained root containing `path`, as `app:///<relative>`; undefined outside all roots. O(r). */
|
|
116
|
+
function retainedPath({ path, keepRoots }, _options = {}) {
|
|
117
|
+
const windows = /^(?:[A-Za-z]:[\\/]|\\\\)/.test(path);
|
|
118
|
+
const paths = windows ? win32 : posix;
|
|
119
|
+
for (const entry of keepRoots) {
|
|
120
|
+
const root = decodedLocalPath({ value: entry });
|
|
121
|
+
if (root === undefined || !paths.isAbsolute(root))
|
|
122
|
+
continue;
|
|
123
|
+
if (pathContains({ root, target: path }, { separator: windows ? '\\' : '/', caseSensitive: !windows })) {
|
|
124
|
+
return `app:///${paths.relative(root, path).split(paths.sep).join('/')}`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Mask local paths in error text; explicitly retained roots expose only app-relative filenames.
|
|
131
|
+
* Supports POSIX, home-relative, Windows, UNC and file URLs on every host OS. Never reads files.
|
|
132
|
+
* @returns Masked text, with stack line/column suffixes preserved. Malformed file URLs are masked.
|
|
133
|
+
* @complexity O(nr) time, O(n) output space for text length n and a fixed set of r retained roots.
|
|
134
|
+
*/
|
|
135
|
+
export function maskLocalPaths({ text }, { keepRoots = [] } = {}) {
|
|
136
|
+
// Consume quoted filenames first: parentheses and spaces are legal filename characters.
|
|
137
|
+
const quotedText = text.replace(QUOTED_LOCAL_PATH_RE, (_match, quote, value) => `${quote}${maskedLocalPath({ value, keepRoots })}${quote}`);
|
|
138
|
+
return quotedText.replace(LOCAL_PATH_RE, (_match, open, quoted, close, lead, plain) => {
|
|
139
|
+
const masked = maskedLocalPath({ value: quoted ?? plain, keepRoots });
|
|
140
|
+
return quoted === undefined ? `${lead}${masked}` : `${open}${masked}${close}`;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
78
143
|
//# sourceMappingURL=redaction.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/diagnostics",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.15-rc.2",
|
|
4
4
|
"description": "Diagnostics-bundle tooling: JSON/text secret redaction, log-source collection, manifest building, and zip packaging for support exports.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -82,16 +82,21 @@
|
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@vitest/coverage-v8": "^2.1.9",
|
|
84
84
|
"jszip": "^3.10.1",
|
|
85
|
-
"@jini-ai/core": "^0.6.
|
|
85
|
+
"@jini-ai/core": "^0.6.15-rc.2",
|
|
86
|
+
"@jini-ai/analytics": "^0.6.15-rc.2"
|
|
86
87
|
},
|
|
87
88
|
"dependencies": {
|
|
88
89
|
"js-tokens": "^9.0.1",
|
|
89
|
-
"@jini-ai/core": "^0.6.
|
|
90
|
+
"@jini-ai/core": "^0.6.15-rc.2"
|
|
90
91
|
},
|
|
91
92
|
"peerDependencies": {
|
|
93
|
+
"@jini-ai/analytics": "^0.6.15-rc.2",
|
|
92
94
|
"jszip": "^3.10.1"
|
|
93
95
|
},
|
|
94
96
|
"peerDependenciesMeta": {
|
|
97
|
+
"@jini-ai/analytics": {
|
|
98
|
+
"optional": true
|
|
99
|
+
},
|
|
95
100
|
"jszip": {
|
|
96
101
|
"optional": true
|
|
97
102
|
}
|