@jini-ai/diagnostics 0.7.2 → 0.7.3-next.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 +2 -2
- 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 +15 -1
- package/dist/observability/hooks.d.ts +2 -1
- package/dist/observability/hooks.js +2 -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 +55 -7
- package/dist/observability/noop.d.ts +0 -7
- package/dist/observability/noop.js +0 -27
package/CHANGELOG.md
CHANGED
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
consent is unchanged. `combineObservabilityPorts` now wraps a
|
|
65
65
|
single enabled adapter too, so its throws never reach the caller.
|
|
66
66
|
- 0b413ae: PROTOTYPE (cloud/observability-1025, not for release): `ObservabilityPort` gains `trackOperation` (feature-level unit of work) and `reportError` (incident report, adapter-redacted). Breaking for hand-written port implementations: both methods are required. Noop stays zero-allocation; `combineObservabilityPorts` fans out to several enabled adapters (none → noop; one or more → each adapter isolated); `describeReportedError` gives error-tracker adapters a redacted, capped type/message/stack.
|
|
67
|
-
- 803a949: Observability vendor adapters as provider subpaths: `@jini-ai/diagnostics/observability/opentelemetry` (moved from
|
|
67
|
+
- 803a949: Observability vendor adapters as provider subpaths: `@jini-ai/diagnostics/observability/opentelemetry` (moved from the first host's core) and `@jini-ai/diagnostics/observability/sentry`, each returning `{ port, dispose }` with optional peer SDKs. Review fixes: attribute strings and `Error.name` redacted and capped; fan-out isolates each adapter's tracker creation and end; Sentry root operations start fresh traces and never call `NodeClient#init()` or channel injection. `withToolCallObservability` exports a fixed label for unregistered tool ids and adds `user.id` (pseudonymous principal).
|
|
68
68
|
- 63bacc5: OpenTelemetry and Sentry observability adapters moved out of `@jini-ai/diagnostics` into the `observability-opentelemetry` and `observability-sentry` provider plugins of `@jini-ai/provider-plugins`. Removed: the `@jini-ai/diagnostics/observability/opentelemetry` and `/observability/sentry` subpaths and every `@opentelemetry/*` / `@sentry/node` dev and optional peer dependency. The OTel plugin accepts any OTLP/HTTP endpoint plus generic request headers. Packages bundled into plugin artifacts now ship their LICENSE file.
|
|
69
69
|
- Updated dependencies [7479159]
|
|
70
70
|
- Updated dependencies [c31264d]
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
|
|
114
114
|
### Patch Changes
|
|
115
115
|
|
|
116
|
-
-
|
|
116
|
+
- Host clean-up release (2026-10-08): code the first host moved into Jini, plus the Jini clean-up (see the commit log since 0.5.0).
|
|
117
117
|
|
|
118
118
|
## 0.5.0 — 2026-10-05
|
|
119
119
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
export function amrLogDirectories(_input, options) {
|
|
3
|
+
// An AMR-style runtime drives a private OpenCode under OPENCODE_TEST_HOME;
|
|
4
|
+
// its session logs land under that home's XDG data dir, where provider
|
|
5
|
+
// failures are recorded. Prefer the effective home a real run resolves
|
|
6
|
+
// (honoring a user override) and fall back to the default
|
|
7
|
+
// `<dataDir>/amr/opencode-home` so the bundle does not silently drop the
|
|
8
|
+
// very logs this is meant to surface.
|
|
9
|
+
const amrHome = options.amrOpenCodeHome?.trim();
|
|
10
|
+
const dataDir = options.dataDir?.trim();
|
|
11
|
+
const amrOpenCodeHome = amrHome || (dataDir ? join(dataDir, "amr", "opencode-home") : "");
|
|
12
|
+
return amrOpenCodeHome
|
|
13
|
+
? [{ agent: "amr", dir: join(amrOpenCodeHome, ".local", "share", "opencode", "log") }]
|
|
14
|
+
: [];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
export function claudeLogDirectories({ home }, options) {
|
|
3
|
+
// Honor the effective CLI home so relocated configurations are not missed.
|
|
4
|
+
const claudeDir = options.claudeConfigDir?.trim() || join(home, ".claude");
|
|
5
|
+
// Claude Code operational logs (bash-commands / cost-tracker / daemon).
|
|
6
|
+
return [{ agent: "claude", dir: claudeDir }];
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
export function codexLogDirectories({ home }, options) {
|
|
3
|
+
// Honor the effective CLI home so relocated configurations are not missed.
|
|
4
|
+
const codexHome = options.codexHome?.trim() || join(home, ".codex");
|
|
5
|
+
// Codex tracing logs (codex-tui.log can be very large — tail-bounded).
|
|
6
|
+
return [{ agent: "codex", dir: join(codexHome, "log") }];
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
export function openCodeLogDirectories({ home }, options) {
|
|
3
|
+
const xdg = options.xdgDataHome?.trim();
|
|
4
|
+
const openCodeUserLogDir = xdg
|
|
5
|
+
? join(xdg, "opencode", "log")
|
|
6
|
+
: join(home, ".local", "share", "opencode", "log");
|
|
7
|
+
// OpenCode session logs (provider errors live here in headless mode).
|
|
8
|
+
return [{ agent: "opencode", dir: openCodeUserLogDir }];
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
package/dist/agent-logs.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { readDirectorySafe, statSafe } from "./discovery-filesystem.js";
|
|
3
|
+
import { claudeLogDirectories } from "./agent-logs/claude/index.js";
|
|
4
|
+
import { codexLogDirectories } from "./agent-logs/codex/index.js";
|
|
5
|
+
import { openCodeLogDirectories } from "./agent-logs/opencode/index.js";
|
|
6
|
+
import { amrLogDirectories } from "./agent-logs/amr/index.js";
|
|
3
7
|
const DEFAULT_RUN_EVENT_TAIL_BYTES = 2 * 1024 * 1024;
|
|
4
8
|
const DEFAULT_MAX_RUN_EVENT_LOGS = 20;
|
|
5
9
|
// CLI session logs can be large (e.g. Codex's `codex-tui.log` grows into the
|
|
@@ -49,46 +53,15 @@ async function latestLogFilesIn(dir, max, filesystem) {
|
|
|
49
53
|
candidates.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
50
54
|
return candidates.slice(0, max).map(({ name, absolutePath }) => ({ name, absolutePath }));
|
|
51
55
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// same fix as the AMR-style runtime's `OPENCODE_TEST_HOME` so relocated
|
|
60
|
-
// homes are not missed.
|
|
61
|
-
const claudeDir = options.claudeConfigDir?.trim() || join(home, ".claude");
|
|
62
|
-
const codexHome = options.codexHome?.trim() || join(home, ".codex");
|
|
63
|
-
// Per-agent log directories. `*.log` only; secret files (auth.json,
|
|
64
|
-
// config.json) live outside these dirs and are never swept.
|
|
65
|
-
return [
|
|
66
|
-
// Claude Code operational logs (bash-commands / cost-tracker / daemon).
|
|
67
|
-
{ agent: "claude", dir: claudeDir },
|
|
68
|
-
// Codex tracing logs (codex-tui.log can be very large — tail-bounded).
|
|
69
|
-
{ agent: "codex", dir: join(codexHome, "log") },
|
|
70
|
-
// OpenCode session logs (provider errors live here in headless mode).
|
|
71
|
-
{ agent: "opencode", dir: openCodeUserLogDir },
|
|
72
|
-
];
|
|
73
|
-
}
|
|
56
|
+
// Effective CLI homes honor the user's app-config overrides
|
|
57
|
+
// (`CLAUDE_CONFIG_DIR` / `CODEX_HOME`), falling back to the defaults — the
|
|
58
|
+
// same fix as the AMR-style runtime's `OPENCODE_TEST_HOME` so relocated
|
|
59
|
+
// homes are not missed.
|
|
60
|
+
// Per-agent log directories. `*.log` only; secret files (auth.json,
|
|
61
|
+
// config.json) live outside these dirs and are never swept.
|
|
62
|
+
const AGENT_LOG_DIRECTORIES = [claudeLogDirectories, codexLogDirectories, openCodeLogDirectories, amrLogDirectories];
|
|
74
63
|
function agentLogDirectories({ home }, options = {}) {
|
|
75
|
-
|
|
76
|
-
// An AMR-style runtime drives a private OpenCode under OPENCODE_TEST_HOME;
|
|
77
|
-
// its session logs land under that home's XDG data dir, where provider
|
|
78
|
-
// failures are recorded. Prefer the effective home a real run resolves
|
|
79
|
-
// (honoring a user override) and fall back to the default
|
|
80
|
-
// `<dataDir>/amr/opencode-home` so the bundle does not silently drop the
|
|
81
|
-
// very logs this is meant to surface.
|
|
82
|
-
const amrHome = options.amrOpenCodeHome?.trim();
|
|
83
|
-
const dataDir = options.dataDir?.trim();
|
|
84
|
-
const amrOpenCodeHome = amrHome || (dataDir ? join(dataDir, "amr", "opencode-home") : "");
|
|
85
|
-
if (amrOpenCodeHome) {
|
|
86
|
-
agentDirs.push({
|
|
87
|
-
agent: "amr",
|
|
88
|
-
dir: join(amrOpenCodeHome, ".local", "share", "opencode", "log"),
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return agentDirs;
|
|
64
|
+
return AGENT_LOG_DIRECTORIES.flatMap((directories) => directories({ home }, options));
|
|
92
65
|
}
|
|
93
66
|
/**
|
|
94
67
|
* Collect the native on-disk logs of the coding-agent CLIs a host application
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Writable } from "node:stream";
|
|
2
|
+
/**
|
|
3
|
+
* @file Formats console output once and redacts it before either the terminal or buffer sees it.
|
|
4
|
+
* Generic (no host-product concepts): the capture target is the structural `ConsoleTeeBuffer` port, so a host
|
|
5
|
+
* passes its own log buffer without this module knowing its source vocabulary.
|
|
6
|
+
*
|
|
7
|
+
* Capture must never break logging: a failing redactor emits a safe placeholder, never raw text;
|
|
8
|
+
* a failing or full buffer can only lose the captured copy, never the original console call.
|
|
9
|
+
*/
|
|
10
|
+
type ConsoleMethod = "debug" | "log" | "info" | "warn" | "error";
|
|
11
|
+
/**
|
|
12
|
+
* A capture step that failed and was replaced by a safe fallback. The `error` may quote the text that
|
|
13
|
+
* was being redacted, so a reporter must treat it like the raw output: count it or log its class,
|
|
14
|
+
* never print its message to an unredacted sink.
|
|
15
|
+
*/
|
|
16
|
+
export interface CaptureFailure {
|
|
17
|
+
readonly stage: "redact" | "format" | "append";
|
|
18
|
+
readonly error: unknown;
|
|
19
|
+
}
|
|
20
|
+
/** Receives each {@link CaptureFailure}; must not throw. Defaults to ignoring them (the output still degrades safely). */
|
|
21
|
+
export type CaptureFailureReporter = (failure: CaptureFailure) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Frames child output before invoking the caller's existing redactor, including an unterminated
|
|
24
|
+
* final line. Never closes the parent sink. Oversized lines are discarded whole so cutting a
|
|
25
|
+
* credential before redaction cannot expose a fragment. Redactor failures emit fixed copy.
|
|
26
|
+
* @param required Parent sink and redaction policy; no process globals are read.
|
|
27
|
+
* @param optional Input-line and rendered-line limits, in characters; `onFailure` hears each redactor failure.
|
|
28
|
+
* @returns A writable for one child stream; ending it, or its source unpiping at EOF, flushes the last line.
|
|
29
|
+
* @complexity O(n) time for n input characters; O(maxLineLength) retained space.
|
|
30
|
+
* @example child.stderr.pipe(createRedactedOutputSink({ sink: process.stderr, redact }));
|
|
31
|
+
*/
|
|
32
|
+
export declare function createRedactedOutputSink({ sink, redact }: {
|
|
33
|
+
sink: Pick<Writable, "write">;
|
|
34
|
+
redact: (required: {
|
|
35
|
+
text: string;
|
|
36
|
+
}) => string;
|
|
37
|
+
}, { maxLineLength, maxLength, onFailure }?: {
|
|
38
|
+
maxLineLength?: number;
|
|
39
|
+
maxLength?: number;
|
|
40
|
+
onFailure?: CaptureFailureReporter;
|
|
41
|
+
}): Writable;
|
|
42
|
+
/** Severity of a captured line; `log` and `info` both map to `info`. */
|
|
43
|
+
export type ConsoleTeeLevel = "debug" | "info" | "warn" | "error";
|
|
44
|
+
/**
|
|
45
|
+
* The capture target. `append` is declared as a method so a host buffer whose `source` is a narrower
|
|
46
|
+
* union than `string` is still assignable (method parameters are compared bivariantly).
|
|
47
|
+
*/
|
|
48
|
+
export interface ConsoleTeeBuffer {
|
|
49
|
+
append(input: {
|
|
50
|
+
readonly level: ConsoleTeeLevel;
|
|
51
|
+
readonly source: string;
|
|
52
|
+
readonly message: string;
|
|
53
|
+
}): unknown;
|
|
54
|
+
}
|
|
55
|
+
/** The slice of `console` the tee replaces; injectable so tests never patch the real console. */
|
|
56
|
+
export type TeeableConsole = Record<ConsoleMethod, (...args: unknown[]) => void>;
|
|
57
|
+
export interface InstallConsoleTeeRequired {
|
|
58
|
+
readonly buffer: ConsoleTeeBuffer;
|
|
59
|
+
}
|
|
60
|
+
export interface InstallConsoleTeeOptional {
|
|
61
|
+
/** Defaults to the global `console`. */
|
|
62
|
+
readonly target?: TeeableConsole;
|
|
63
|
+
/** Tag stored with each line; defaults to `"server"`. */
|
|
64
|
+
readonly source?: string;
|
|
65
|
+
/** Applied before both copies; defaults to identity. Redactor failure never exposes raw text. */
|
|
66
|
+
readonly redact?: (required: {
|
|
67
|
+
text: string;
|
|
68
|
+
}, optional?: Record<string, never>) => string;
|
|
69
|
+
/** Hears each formatting, redaction or buffer failure; the console call is never interrupted by it. */
|
|
70
|
+
readonly onFailure?: CaptureFailureReporter;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Wraps console.debug/log/info/warn/error so each call is also appended to the buffer.
|
|
74
|
+
* The original method receives the formatted, redacted string before the buffer copy is appended.
|
|
75
|
+
* @param required The buffer to append to.
|
|
76
|
+
* @param optional Console to patch (tests), source tag and injected redactor.
|
|
77
|
+
* @returns Uninstall, restoring exactly the methods this call replaced.
|
|
78
|
+
* @complexity O(n) formatting space/time for n output characters, plus the injected redactor and buffer.
|
|
79
|
+
* @example const uninstall = installConsoleTee({ buffer });
|
|
80
|
+
*/
|
|
81
|
+
export declare function installConsoleTee(required: InstallConsoleTeeRequired, optional?: InstallConsoleTeeOptional): () => void;
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=console-tee.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { format } from "node:util";
|
|
2
|
+
import { Writable } from "node:stream";
|
|
3
|
+
import { StringDecoder } from "node:string_decoder";
|
|
4
|
+
const ignoreFailure = () => undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Frames child output before invoking the caller's existing redactor, including an unterminated
|
|
7
|
+
* final line. Never closes the parent sink. Oversized lines are discarded whole so cutting a
|
|
8
|
+
* credential before redaction cannot expose a fragment. Redactor failures emit fixed copy.
|
|
9
|
+
* @param required Parent sink and redaction policy; no process globals are read.
|
|
10
|
+
* @param optional Input-line and rendered-line limits, in characters; `onFailure` hears each redactor failure.
|
|
11
|
+
* @returns A writable for one child stream; ending it, or its source unpiping at EOF, flushes the last line.
|
|
12
|
+
* @complexity O(n) time for n input characters; O(maxLineLength) retained space.
|
|
13
|
+
* @example child.stderr.pipe(createRedactedOutputSink({ sink: process.stderr, redact }));
|
|
14
|
+
*/
|
|
15
|
+
export function createRedactedOutputSink({ sink, redact }, { maxLineLength = 65_536, maxLength = 2_000, onFailure = ignoreFailure } = {}) {
|
|
16
|
+
const decoder = new StringDecoder("utf8");
|
|
17
|
+
let pending = "";
|
|
18
|
+
let oversized = false;
|
|
19
|
+
const emit = () => {
|
|
20
|
+
let safe = "[output redaction failed]";
|
|
21
|
+
try {
|
|
22
|
+
safe = oversized ? "[oversized output line omitted]" : redact({ text: pending });
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
onFailure({ stage: "redact", error });
|
|
26
|
+
} // Raw child bytes must never be the fallback.
|
|
27
|
+
if (safe)
|
|
28
|
+
sink.write(`${safe.slice(0, maxLength)}\n`);
|
|
29
|
+
pending = "";
|
|
30
|
+
oversized = false;
|
|
31
|
+
};
|
|
32
|
+
const append = ({ text }, _optional = {}) => {
|
|
33
|
+
let start = 0;
|
|
34
|
+
while (start < text.length) {
|
|
35
|
+
const newline = text.indexOf("\n", start);
|
|
36
|
+
const end = newline === -1 ? text.length : newline;
|
|
37
|
+
if (!oversized && pending.length + end - start > maxLineLength) {
|
|
38
|
+
pending = "";
|
|
39
|
+
oversized = true;
|
|
40
|
+
}
|
|
41
|
+
if (!oversized)
|
|
42
|
+
pending += text.slice(start, end);
|
|
43
|
+
if (newline === -1)
|
|
44
|
+
return;
|
|
45
|
+
emit();
|
|
46
|
+
start = newline + 1;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const flush = () => { append({ text: decoder.end() }); if (pending || oversized)
|
|
50
|
+
emit(); };
|
|
51
|
+
const writable = new Writable({
|
|
52
|
+
write(chunk, _encoding, done) { append({ text: decoder.write(chunk) }); done(); },
|
|
53
|
+
final(done) { flush(); done(); },
|
|
54
|
+
});
|
|
55
|
+
// A source piped with { end: false } (Jini's daemon adapter keeps host sinks open across respawns)
|
|
56
|
+
// never calls end(); its EOF only unpipes, and the unterminated last line is often the native crash.
|
|
57
|
+
writable.on("unpipe", flush);
|
|
58
|
+
return writable;
|
|
59
|
+
}
|
|
60
|
+
const LEVEL_BY_METHOD = {
|
|
61
|
+
debug: "debug", log: "info", info: "info", warn: "warn", error: "error",
|
|
62
|
+
};
|
|
63
|
+
function safeAppend({ buffer, level, source, message }, { onFailure = ignoreFailure } = {}) {
|
|
64
|
+
try {
|
|
65
|
+
buffer.append({ level, source, message });
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
// Losing one captured line is acceptable; throwing out of console.error is not.
|
|
69
|
+
onFailure({ stage: "append", error });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Wraps console.debug/log/info/warn/error so each call is also appended to the buffer.
|
|
74
|
+
* The original method receives the formatted, redacted string before the buffer copy is appended.
|
|
75
|
+
* @param required The buffer to append to.
|
|
76
|
+
* @param optional Console to patch (tests), source tag and injected redactor.
|
|
77
|
+
* @returns Uninstall, restoring exactly the methods this call replaced.
|
|
78
|
+
* @complexity O(n) formatting space/time for n output characters, plus the injected redactor and buffer.
|
|
79
|
+
* @example const uninstall = installConsoleTee({ buffer });
|
|
80
|
+
*/
|
|
81
|
+
export function installConsoleTee(required, optional = {}) {
|
|
82
|
+
const target = optional.target ?? console;
|
|
83
|
+
const source = optional.source ?? "server";
|
|
84
|
+
const redact = optional.redact ?? (({ text }) => text);
|
|
85
|
+
const onFailure = optional.onFailure ?? ignoreFailure;
|
|
86
|
+
const originals = new Map();
|
|
87
|
+
for (const method of Object.keys(LEVEL_BY_METHOD)) {
|
|
88
|
+
const original = target[method];
|
|
89
|
+
originals.set(method, original);
|
|
90
|
+
target[method] = (...args) => {
|
|
91
|
+
let message = "[log redaction failed]";
|
|
92
|
+
try {
|
|
93
|
+
message = redact({ text: format(...args) });
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
// Formatting or redaction failure must never send the raw arguments to a log shipper.
|
|
97
|
+
onFailure({ stage: "format", error });
|
|
98
|
+
}
|
|
99
|
+
original.call(target, message);
|
|
100
|
+
safeAppend({ buffer: required.buffer, level: LEVEL_BY_METHOD[method], source, message }, { onFailure });
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return () => {
|
|
104
|
+
for (const [method, original] of originals)
|
|
105
|
+
target[method] = original;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=console-tee.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* Credential and home-path redaction for local child, native and gate output before it is shown or stored.
|
|
4
|
+
* Jini's username policy masks only `/Users/<u>`, `/home/<u>` and `\Users\<u>`; a home outside those
|
|
5
|
+
* roots (root's `/root`, a service account's custom HOME) would otherwise pass through verbatim,
|
|
6
|
+
* so the literal home directory is masked as `~` after the shared redactor runs.
|
|
7
|
+
* @param required.text Untrusted text to redact.
|
|
8
|
+
* @param optional.homeDir Home directory to mask; `os.homedir()` by default.
|
|
9
|
+
* @param optional.platformPath Path flavour used to read the home's basename and root; the host's by
|
|
10
|
+
* default, injectable so a Windows home (`C:\Users\ada`, `C:\`) is exercised on any host.
|
|
11
|
+
* @returns The redacted text; a filesystem-root home is left to the username policy alone,
|
|
12
|
+
* since masking it would erase every absolute path.
|
|
13
|
+
* @complexity O(n) time and space for n text characters.
|
|
14
|
+
*/
|
|
15
|
+
export declare function redactLocalText({ text }: {
|
|
16
|
+
text: string;
|
|
17
|
+
}, { homeDir, platformPath }?: {
|
|
18
|
+
homeDir?: string;
|
|
19
|
+
platformPath?: Pick<typeof path, "basename" | "parse">;
|
|
20
|
+
}): string;
|
|
21
|
+
//# sourceMappingURL=local-text.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { redactText } from "./redaction.js";
|
|
4
|
+
/** Path-name characters: a home followed by one of these is a sibling path (`/rootfs`), not the home. */
|
|
5
|
+
const NOT_PATH_CONTINUATION = "(?![A-Za-z0-9._-])";
|
|
6
|
+
/**
|
|
7
|
+
* Credential and home-path redaction for local child, native and gate output before it is shown or stored.
|
|
8
|
+
* Jini's username policy masks only `/Users/<u>`, `/home/<u>` and `\Users\<u>`; a home outside those
|
|
9
|
+
* roots (root's `/root`, a service account's custom HOME) would otherwise pass through verbatim,
|
|
10
|
+
* so the literal home directory is masked as `~` after the shared redactor runs.
|
|
11
|
+
* @param required.text Untrusted text to redact.
|
|
12
|
+
* @param optional.homeDir Home directory to mask; `os.homedir()` by default.
|
|
13
|
+
* @param optional.platformPath Path flavour used to read the home's basename and root; the host's by
|
|
14
|
+
* default, injectable so a Windows home (`C:\Users\ada`, `C:\`) is exercised on any host.
|
|
15
|
+
* @returns The redacted text; a filesystem-root home is left to the username policy alone,
|
|
16
|
+
* since masking it would erase every absolute path.
|
|
17
|
+
* @complexity O(n) time and space for n text characters.
|
|
18
|
+
*/
|
|
19
|
+
export function redactLocalText({ text }, { homeDir = os.homedir(), platformPath = path } = {}) {
|
|
20
|
+
const redacted = redactText({ text }, { username: platformPath.basename(homeDir) });
|
|
21
|
+
let end = homeDir.length;
|
|
22
|
+
while (end > 0 && (homeDir[end - 1] === "/" || homeDir[end - 1] === "\\"))
|
|
23
|
+
end -= 1;
|
|
24
|
+
const home = homeDir.slice(0, end);
|
|
25
|
+
if (!home || platformPath.parse(homeDir).root === homeDir)
|
|
26
|
+
return redacted;
|
|
27
|
+
const escaped = home.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
28
|
+
return redacted.replace(new RegExp(`${escaped}${NOT_PATH_CONTINUATION}`, "g"), "~");
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=local-text.js.map
|
|
@@ -13,9 +13,10 @@ export function describeTelemetryFailure({ error }, _options = {}) {
|
|
|
13
13
|
if (typeof error !== "object" || error === null)
|
|
14
14
|
return { errorClass: "Error" };
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
16
|
+
// Each field is read once: a getter cannot pass the check with one value and be stored with another.
|
|
17
|
+
const { name, statusCode: statusField, status, code } = error;
|
|
18
|
+
const errorClass = typeof name === "string" && ERROR_CLASSES.has(name) ? name : "Error";
|
|
19
|
+
const statusCode = httpStatus(statusField ?? status ?? code);
|
|
19
20
|
return { errorClass, ...(statusCode === undefined ? {} : { statusCode }) };
|
|
20
21
|
}
|
|
21
22
|
catch {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ErrorDescriber } from '@jini-ai/core';
|
|
1
2
|
export interface ReportedErrorDescription {
|
|
2
3
|
type: string;
|
|
3
4
|
message: string;
|
|
@@ -5,5 +6,7 @@ export interface ReportedErrorDescription {
|
|
|
5
6
|
}
|
|
6
7
|
export declare function describeReportedError({ error }: {
|
|
7
8
|
error: unknown;
|
|
8
|
-
},
|
|
9
|
+
}, { describer }?: {
|
|
10
|
+
describer?: Pick<ErrorDescriber, 'describeErrorParts'>;
|
|
11
|
+
}): ReportedErrorDescription;
|
|
9
12
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -20,8 +20,8 @@ function rawMessage({ error, type }) {
|
|
|
20
20
|
return error.message;
|
|
21
21
|
return typeof error === 'string' ? error : type;
|
|
22
22
|
}
|
|
23
|
-
export function describeReportedError({ error },
|
|
24
|
-
const type = errorType(error);
|
|
23
|
+
export function describeReportedError({ error }, { describer } = {}) {
|
|
24
|
+
const type = errorType({ error }, describer ? { describer } : {});
|
|
25
25
|
const raw = rawMessage({ error, type });
|
|
26
26
|
const stack = error instanceof Error && typeof error.stack === 'string'
|
|
27
27
|
? redact(error.stack).split('\n').slice(0, MAX_STACK_LINES).join('\n') : undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ObservabilityPort } from '
|
|
1
|
+
import type { ObservabilityPort } from '@jini-ai/core/contracts/observability';
|
|
2
2
|
/**
|
|
3
3
|
* Sends every signal to each enabled adapter: the "both configured" answer (say OpenTelemetry for
|
|
4
4
|
* traces and an error tracker for incidents), with no adapter knowing about the other. Noop ports are
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createNoopObservabilityPort, isNoopObservabilityPort } from '
|
|
1
|
+
import { createNoopObservabilityPort, isNoopObservabilityPort, } from '@jini-ai/core/contracts/observability';
|
|
2
2
|
const NOOP = createNoopObservabilityPort({});
|
|
3
3
|
/** One adapter's tracker, isolated (review 2026-10-25 #3): an adapter that throws while CREATING its
|
|
4
4
|
* tracker gets the shared noop tracker for this signal instead of failing the caller's work, so the
|
|
@@ -128,8 +128,22 @@ export function combineObservabilityPorts({ ports }, { onFailure } = {}) {
|
|
|
128
128
|
}
|
|
129
129
|
return undefined;
|
|
130
130
|
};
|
|
131
|
+
const activeTraceparent = () => {
|
|
132
|
+
for (const port of live) {
|
|
133
|
+
try {
|
|
134
|
+
const traceparent = port.activeTraceparent?.();
|
|
135
|
+
if (traceparent)
|
|
136
|
+
return traceparent;
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
failed();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return undefined;
|
|
143
|
+
};
|
|
131
144
|
return {
|
|
132
145
|
activeTraceIds,
|
|
146
|
+
activeTraceparent,
|
|
133
147
|
get supportsMetric() { return live.some(port => port.supportsMetric === true); },
|
|
134
148
|
trackRequest: (...args) => fanOut(live, 'trackRequest', args, failed),
|
|
135
149
|
trackDbQuery: (...args) => fanOut(live, 'trackDbQuery', args, failed),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Clock } from "@jini-ai/core/primitives";
|
|
2
|
-
import type { RequestIdGenerator, RequestLogPort, RequestMetricsPort
|
|
2
|
+
import type { RequestIdGenerator, RequestLogPort, RequestMetricsPort } from './ports.js';
|
|
3
|
+
import type { ObservabilityPort } from '@jini-ai/core/contracts/observability';
|
|
3
4
|
export interface RequestHookOptions {
|
|
4
5
|
logger?: RequestLogPort;
|
|
5
6
|
metrics?: RequestMetricsPort;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createNoopObservabilityPort } from '
|
|
1
|
+
import { createNoopObservabilityPort } from '@jini-ai/core/contracts/observability';
|
|
2
2
|
/** Adds request correlation and completed-request hooks using explicit ID and clock ports.
|
|
3
3
|
* @param required Clock and request ID generator, scoped by the host.
|
|
4
4
|
* @param options Optional logging, metrics and tracing adapters.
|
|
@@ -11,6 +11,7 @@ export function createHookObservabilityPort({ clock, requestIdGenerator }, { log
|
|
|
11
11
|
return {
|
|
12
12
|
get supportsMetric() { return signals.supportsMetric === true; },
|
|
13
13
|
activeTraceIds: (_required = {}, _optional = {}) => signals.activeTraceIds?.(),
|
|
14
|
+
activeTraceparent: () => signals.activeTraceparent?.(),
|
|
14
15
|
trackRequest(input, options = {}) {
|
|
15
16
|
const requestId = options.requestId ?? requestIdGenerator.generate({});
|
|
16
17
|
const startedAt = clock.nowMs();
|
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
import type { ObservabilityConfig } from './config.js';
|
|
2
|
-
import type { ExporterFactory, TracerProviderFactory, ObservabilityPort } from './ports.js';
|
|
3
|
-
import { type OtelAdapterOptions } from './otel.js';
|
|
4
1
|
export * from './config.js';
|
|
5
2
|
export * from './export-policy.js';
|
|
6
3
|
export * from './ports.js';
|
|
7
|
-
export
|
|
8
|
-
export * from './otel.js';
|
|
4
|
+
export { redactOperationAttributes, errorType, redactLabel } from './otel.js';
|
|
9
5
|
export * from './errors.js';
|
|
10
6
|
export * from './fanout.js';
|
|
11
7
|
export * from './hooks.js';
|
|
12
8
|
export * from './instrumentation.js';
|
|
13
9
|
export * from './delivery.js';
|
|
10
|
+
export { observabilityProviderContract } from './provider-contract.js';
|
|
14
11
|
export type { TelemetryTestResult, TelemetryTestSignal } from './telemetry-test.js';
|
|
15
|
-
/** Selects an adapter from explicit config; disabled telemetry never invokes either factory.
|
|
16
|
-
* @param options Adapter options (host span scope); ignored when telemetry is disabled. */
|
|
17
|
-
export declare function createObservabilityPort({ config, exporterFactory, tracerProviderFactory }: {
|
|
18
|
-
config: ObservabilityConfig;
|
|
19
|
-
exporterFactory: ExporterFactory;
|
|
20
|
-
tracerProviderFactory: TracerProviderFactory;
|
|
21
|
-
}, options?: OtelAdapterOptions): ObservabilityPort;
|
|
22
12
|
export type * from "./tracker-types.js";
|
|
23
13
|
export { createNoopTracker } from "./tracker-noop.js";
|
|
24
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
import { createNoopObservabilityPort } from './noop.js';
|
|
2
|
-
import { createOtelObservabilityPort } from './otel.js';
|
|
3
1
|
export * from './config.js';
|
|
4
2
|
export * from './export-policy.js';
|
|
5
3
|
export * from './ports.js';
|
|
6
|
-
export
|
|
7
|
-
export * from './otel.js';
|
|
4
|
+
export { redactOperationAttributes, errorType, redactLabel } from './otel.js';
|
|
8
5
|
export * from './errors.js';
|
|
9
6
|
export * from './fanout.js';
|
|
10
7
|
export * from './hooks.js';
|
|
11
8
|
export * from './instrumentation.js';
|
|
12
9
|
export * from './delivery.js';
|
|
13
|
-
|
|
14
|
-
* @param options Adapter options (host span scope); ignored when telemetry is disabled. */
|
|
15
|
-
export function createObservabilityPort({ config, exporterFactory, tracerProviderFactory }, options = {}) {
|
|
16
|
-
if (!config.enabled)
|
|
17
|
-
return createNoopObservabilityPort({});
|
|
18
|
-
return createOtelObservabilityPort({ config, exporterFactory, tracerProviderFactory }, options);
|
|
19
|
-
}
|
|
10
|
+
export { observabilityProviderContract } from './provider-contract.js';
|
|
20
11
|
export { createNoopTracker } from "./tracker-noop.js";
|
|
21
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HttpClientPort } from "@jini-ai/core/primitives";
|
|
2
|
-
import type { ObservabilityPort } from '
|
|
2
|
+
import type { ObservabilityPort } from '@jini-ai/core/contracts/observability';
|
|
3
3
|
/**
|
|
4
4
|
* @file Decorators that put a host's existing chokepoints on the observability port: the storage
|
|
5
5
|
* kernel (every repo query, on every dialect) and the guarded HTTP client (every vetted egress call).
|
|
@@ -19,10 +19,10 @@ export declare function describeQueryNode({ node }: {
|
|
|
19
19
|
/** The kernel surface the decorator replaces; `StorageKernel<DB>` from `@jini-ai/db/kernel` fits it. */
|
|
20
20
|
export interface InstrumentableKernel {
|
|
21
21
|
readonly dialect: string;
|
|
22
|
-
run(fn: (db:
|
|
22
|
+
run(fn: (db: unknown) => unknown): Promise<unknown>;
|
|
23
23
|
transaction(fn: () => Promise<unknown>): Promise<unknown>;
|
|
24
|
-
query(statement:
|
|
25
|
-
execute(statement:
|
|
24
|
+
query(statement: unknown): Promise<unknown>;
|
|
25
|
+
execute(statement: unknown): Promise<unknown>;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Tracks every kernel `run`/`transaction`/`query`/`execute` as one DB span, decorating the kernel
|
|
@@ -12,4 +12,8 @@ export declare function createAsyncLocalSpanScope(_required: Record<string, neve
|
|
|
12
12
|
export { reportErrorOnce, redactedError, runWithErrorReportScope, type ErrorReportScope } from './report-error.js';
|
|
13
13
|
export { createTracker, createTrackerWarning } from "./tracker.js";
|
|
14
14
|
export { createTelemetryTestProbe } from "./telemetry-test.js";
|
|
15
|
+
/** Node-only helper values for observability providers; a host merges them into the contract's `context`. */
|
|
16
|
+
export declare const observabilityNodeProviderContext: {
|
|
17
|
+
readonly createAsyncLocalSpanScope: typeof createAsyncLocalSpanScope;
|
|
18
|
+
};
|
|
15
19
|
//# sourceMappingURL=node.d.ts.map
|
|
@@ -15,4 +15,6 @@ export function createAsyncLocalSpanScope(_required) {
|
|
|
15
15
|
export { reportErrorOnce, redactedError, runWithErrorReportScope } from './report-error.js';
|
|
16
16
|
export { createTracker, createTrackerWarning } from "./tracker.js";
|
|
17
17
|
export { createTelemetryTestProbe } from "./telemetry-test.js";
|
|
18
|
+
/** Node-only helper values for observability providers; a host merges them into the contract's `context`. */
|
|
19
|
+
export const observabilityNodeProviderContext = { createAsyncLocalSpanScope };
|
|
18
20
|
//# sourceMappingURL=node.js.map
|