@vymalo/opencode-otel 0.12.0 → 0.14.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/README.md +20 -1
- package/dist/config.d.ts +29 -17
- package/dist/config.js +210 -197
- package/dist/config.js.map +1 -1
- package/dist/deferred.d.ts +22 -0
- package/dist/deferred.js +29 -0
- package/dist/deferred.js.map +1 -0
- package/dist/export-logging.d.ts +28 -0
- package/dist/export-logging.js +74 -0
- package/dist/export-logging.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/instruments.d.ts +22 -22
- package/dist/instruments.js +95 -94
- package/dist/instruments.js.map +1 -1
- package/dist/lib.d.ts +5 -1
- package/dist/lib.js +6 -1
- package/dist/lib.js.map +1 -1
- package/dist/logging.d.ts +6 -6
- package/dist/logging.js +59 -62
- package/dist/logging.js.map +1 -1
- package/dist/opencode.d.ts +16 -14
- package/dist/opencode.js +165 -122
- package/dist/opencode.js.map +1 -1
- package/dist/propagation.d.ts +13 -13
- package/dist/propagation.js +50 -48
- package/dist/propagation.js.map +1 -1
- package/dist/providers.d.ts +46 -35
- package/dist/providers.js +217 -158
- package/dist/providers.js.map +1 -1
- package/dist/recorder.d.ts +150 -69
- package/dist/recorder.js +788 -539
- package/dist/recorder.js.map +1 -1
- package/dist/token-source.d.ts +59 -0
- package/dist/token-source.js +125 -0
- package/dist/token-source.js.map +1 -0
- package/dist/types.d.ts +92 -64
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/dist/vcs.d.ts +63 -0
- package/dist/vcs.js +188 -0
- package/dist/vcs.js.map +1 -0
- package/package.json +3 -3
package/dist/deferred.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const DEFAULT_DEFERRED_TIMEOUT_MS = 2e3;
|
|
2
|
+
export function deferredAttribute(timeoutMs = DEFAULT_DEFERRED_TIMEOUT_MS, schedule = setTimeout) {
|
|
3
|
+
let resolve = () => {};
|
|
4
|
+
let settled = false;
|
|
5
|
+
const value = new Promise((r) => {
|
|
6
|
+
resolve = r;
|
|
7
|
+
});
|
|
8
|
+
const finish = (next) => {
|
|
9
|
+
if (settled) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
settled = true;
|
|
13
|
+
resolve(next);
|
|
14
|
+
};
|
|
15
|
+
const timer = schedule(() => finish(undefined), timeoutMs);
|
|
16
|
+
// Never hold a short CLI invocation open just to wait for an attribute.
|
|
17
|
+
timer.unref?.();
|
|
18
|
+
return {
|
|
19
|
+
value,
|
|
20
|
+
settle: (next) => {
|
|
21
|
+
if (next !== undefined && next !== "") {
|
|
22
|
+
finish(next);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
abandon: () => finish(undefined)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=deferred.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAqBA,OAAO,MAAM,8BAA8B;AAE3C,OAAO,SAAS,kBACd,YAAoB,6BACpB,WAA8B,YACX;CACnB,IAAI,gBAAqD,CAAC;CAC1D,IAAI,UAAU;CACd,MAAM,QAAQ,IAAI,SAA6B,MAAM;EACnD,UAAU;CACZ,CAAC;CAED,MAAM,UAAU,SAAmC;EACjD,IAAI,SAAS;GACX;EACF;EACA,UAAU;EACV,QAAQ,IAAI;CACd;CAEA,MAAM,QAAQ,eAAe,OAAO,SAAS,GAAG,SAAS;;CAEzD,AAAC,MAAiC,QAAQ;CAE1C,OAAO;EACL;EACA,SAAS,SAAS;GAChB,IAAI,SAAS,aAAa,SAAS,IAAI;IACrC,OAAO,IAAI;GACb;EACF;EACA,eAAe,OAAO,SAAS;CACjC;AACF","names":[],"sources":["../src/deferred.ts"],"version":3,"file":"deferred.js","sourceRoot":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ExportResult } from "@opentelemetry/core";
|
|
2
|
+
import type { Logger } from "./logging.js";
|
|
3
|
+
import type { SignalName } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* The shape all three OTel exporters share: `export(items, resultCallback)`.
|
|
6
|
+
* Typed structurally rather than against `SpanExporter | PushMetricExporter |
|
|
7
|
+
* LogRecordExporter`, whose item types are unrelated.
|
|
8
|
+
*/
|
|
9
|
+
export interface ExporterLike {
|
|
10
|
+
export(items: never, resultCallback: (result: ExportResult) => void): void;
|
|
11
|
+
shutdown(): Promise<void>;
|
|
12
|
+
forceFlush?(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Wrap an exporter so a failed export reaches the host log stream.
|
|
16
|
+
*
|
|
17
|
+
* Without this, a rejected OTLP request — an expired credential, a wrong
|
|
18
|
+
* audience, an unreachable collector — is reported only through the OTel SDK's
|
|
19
|
+
* own `diag` channel, which nothing here subscribes to. The visible symptom is
|
|
20
|
+
* that telemetry silently stops while the session looks entirely healthy.
|
|
21
|
+
*
|
|
22
|
+
* Deliberately not `diag.setLogger`: that is process-global and would hijack
|
|
23
|
+
* the channel for the host and every other plugin. Decorating our own exporters
|
|
24
|
+
* observes exactly the failures we caused and nothing else.
|
|
25
|
+
*/
|
|
26
|
+
export declare function withFailureLogging<T extends ExporterLike>(exporter: T, signal: SignalName, logger: Logger, options?: {
|
|
27
|
+
onFailure?: () => void;
|
|
28
|
+
}): T;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ExportResultCode } from "@opentelemetry/core";
|
|
2
|
+
/**
|
|
3
|
+
* Wrap an exporter so a failed export reaches the host log stream.
|
|
4
|
+
*
|
|
5
|
+
* Without this, a rejected OTLP request — an expired credential, a wrong
|
|
6
|
+
* audience, an unreachable collector — is reported only through the OTel SDK's
|
|
7
|
+
* own `diag` channel, which nothing here subscribes to. The visible symptom is
|
|
8
|
+
* that telemetry silently stops while the session looks entirely healthy.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately not `diag.setLogger`: that is process-global and would hijack
|
|
11
|
+
* the channel for the host and every other plugin. Decorating our own exporters
|
|
12
|
+
* observes exactly the failures we caused and nothing else.
|
|
13
|
+
*/
|
|
14
|
+
export function withFailureLogging(exporter, signal, logger, options = {}) {
|
|
15
|
+
let consecutiveFailures = 0;
|
|
16
|
+
const wrapped = {
|
|
17
|
+
export(items, resultCallback) {
|
|
18
|
+
exporter.export(items, (result) => {
|
|
19
|
+
if (result.code === ExportResultCode.SUCCESS) {
|
|
20
|
+
if (consecutiveFailures > 0) {
|
|
21
|
+
logger.info("otel_export_recovered", {
|
|
22
|
+
signal,
|
|
23
|
+
afterFailures: consecutiveFailures
|
|
24
|
+
});
|
|
25
|
+
consecutiveFailures = 0;
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
consecutiveFailures += 1;
|
|
29
|
+
logger.warn("otel_export_failed", {
|
|
30
|
+
signal,
|
|
31
|
+
consecutiveFailures,
|
|
32
|
+
// `error` may carry an HTTP status; the message is the actionable
|
|
33
|
+
// part (e.g. "authentication didn't succeed" from an OIDC gate).
|
|
34
|
+
error: describeExportError(result.error),
|
|
35
|
+
status: readStatus(result.error)
|
|
36
|
+
});
|
|
37
|
+
options.onFailure?.();
|
|
38
|
+
}
|
|
39
|
+
resultCallback(result);
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
shutdown: () => exporter.shutdown(),
|
|
43
|
+
...exporter.forceFlush ? { forceFlush: () => exporter.forceFlush?.() } : {}
|
|
44
|
+
};
|
|
45
|
+
// Preserve the prototype and any extra members the concrete exporter exposes.
|
|
46
|
+
return Object.assign(Object.create(Object.getPrototypeOf(exporter)), exporter, wrapped);
|
|
47
|
+
}
|
|
48
|
+
function describeExportError(error) {
|
|
49
|
+
if (!error) {
|
|
50
|
+
return "unknown";
|
|
51
|
+
}
|
|
52
|
+
if (error instanceof Error) {
|
|
53
|
+
return error.message;
|
|
54
|
+
}
|
|
55
|
+
return String(error);
|
|
56
|
+
}
|
|
57
|
+
/** OTLP exporter errors carry the HTTP status as `code` or `statusCode`. */
|
|
58
|
+
function readStatus(error) {
|
|
59
|
+
if (!error || typeof error !== "object") {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
const candidate = error;
|
|
63
|
+
for (const value of [candidate.statusCode, candidate.code]) {
|
|
64
|
+
if (typeof value === "number") {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
if (typeof value === "string" && /^\d{3}$/.test(value)) {
|
|
68
|
+
return Number(value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=export-logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAAA,SAA4B,wBAAwB;;;;;;;;;;;;;AA4BpD,OAAO,SAAS,mBACd,UACA,QACA,QACA,UAAsC,CAAC,GACpC;CACH,IAAI,sBAAsB;CAE1B,MAAM,UAAwB;EAC5B,OAAO,OAAO,gBAAgB;GAC5B,SAAS,OAAO,QAAQ,WAAW;IACjC,IAAI,OAAO,SAAS,iBAAiB,SAAS;KAC5C,IAAI,sBAAsB,GAAG;MAC3B,OAAO,KAAK,yBAAyB;OAAE;OAAQ,eAAe;MAAoB,CAAC;MACnF,sBAAsB;KACxB;IACF,OAAO;KACL,uBAAuB;KACvB,OAAO,KAAK,sBAAsB;MAChC;MACA;;;MAGA,OAAO,oBAAoB,OAAO,KAAK;MACvC,QAAQ,WAAW,OAAO,KAAK;KACjC,CAAC;KACD,QAAQ,YAAY;IACtB;IACA,eAAe,MAAM;GACvB,CAAC;EACH;EACA,gBAAgB,SAAS,SAAS;EAClC,GAAI,SAAS,aAAa,EAAE,kBAAkB,SAAS,aAAa,EAAmB,IAAI,CAAC;CAC9F;;CAGA,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,eAAe,QAAQ,CAAC,GAAG,UAAU,OAAO;AACxF;AAEA,SAAS,oBAAoB,OAAwB;CACnD,IAAI,CAAC,OAAO;EACV,OAAO;CACT;CACA,IAAI,iBAAiB,OAAO;EAC1B,OAAO,MAAM;CACf;CACA,OAAO,OAAO,KAAK;AACrB;;AAGA,SAAS,WAAW,OAAoC;CACtD,IAAI,CAAC,SAAS,OAAO,UAAU,UAAU;EACvC,OAAO;CACT;CACA,MAAM,YAAY;CAClB,KAAK,MAAM,SAAS,CAAC,UAAU,YAAY,UAAU,IAAI,GAAG;EAC1D,IAAI,OAAO,UAAU,UAAU;GAC7B,OAAO;EACT;EACA,IAAI,OAAO,UAAU,YAAY,UAAU,KAAK,KAAK,GAAG;GACtD,OAAO,OAAO,KAAK;EACrB;CACF;CACA,OAAO;AACT","names":[],"sources":["../src/export-logging.ts"],"version":3,"file":"export-logging.js","sourceRoot":""}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":";;;;AAIA,SAAS,eAAe","names":[],"sources":["../src/index.ts"],"version":3,"file":"index.js","sourceRoot":""}
|
package/dist/instruments.d.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import type { Counter, Histogram, Meter } from "@opentelemetry/api";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
* Every metric this plugin emits, created once per plugin instance.
|
|
4
|
+
*
|
|
5
|
+
* Naming follows the GenAI semantic conventions where one exists
|
|
6
|
+
* (`gen_ai.client.*`) and `opencode.*` otherwise — deliberately matching the
|
|
7
|
+
* vocabulary `opencode-otel-plugin` already established, so both plugins' data
|
|
8
|
+
* lands on the same dashboards. See `plans/otel.md`.
|
|
9
|
+
*/
|
|
10
10
|
export interface Instruments {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
/** Real USD, straight from `AssistantMessage.cost` — no price table involved. */
|
|
12
|
+
cost: Counter;
|
|
13
|
+
/** All five token types, discriminated by `gen_ai.token.type`. */
|
|
14
|
+
tokens: Histogram;
|
|
15
|
+
/** Assistant-message wall time, seconds. */
|
|
16
|
+
duration: Histogram;
|
|
17
|
+
sessions: Counter;
|
|
18
|
+
requests: Counter;
|
|
19
|
+
compactions: Counter;
|
|
20
|
+
/** Wall time a session spent `busy`, seconds. */
|
|
21
|
+
activeTime: Counter;
|
|
22
|
+
linesOfCode: Counter;
|
|
23
|
+
toolInvocations: Counter;
|
|
24
|
+
permissionDecisions: Counter;
|
|
25
|
+
commands: Counter;
|
|
26
26
|
}
|
|
27
27
|
export declare function createInstruments(meter: Meter): Instruments;
|
|
28
28
|
/** Best-effort language for a path, by extension. `undefined` when unknown. */
|
package/dist/instruments.js
CHANGED
|
@@ -1,102 +1,103 @@
|
|
|
1
1
|
export function createInstruments(meter) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
2
|
+
return {
|
|
3
|
+
cost: meter.createCounter("opencode.cost.usage", {
|
|
4
|
+
description: "Cost of model usage, as reported by the OpenCode host",
|
|
5
|
+
unit: "USD"
|
|
6
|
+
}),
|
|
7
|
+
tokens: meter.createHistogram("gen_ai.client.token.usage", {
|
|
8
|
+
description: "Tokens consumed per assistant message, by token type",
|
|
9
|
+
unit: "{token}"
|
|
10
|
+
}),
|
|
11
|
+
duration: meter.createHistogram("gen_ai.client.operation.duration", {
|
|
12
|
+
description: "Duration of a model operation",
|
|
13
|
+
unit: "s"
|
|
14
|
+
}),
|
|
15
|
+
sessions: meter.createCounter("opencode.session.count", {
|
|
16
|
+
description: "Sessions started",
|
|
17
|
+
unit: "{session}"
|
|
18
|
+
}),
|
|
19
|
+
requests: meter.createCounter("opencode.session.request.count", {
|
|
20
|
+
description: "Assistant messages completed",
|
|
21
|
+
unit: "{request}"
|
|
22
|
+
}),
|
|
23
|
+
compactions: meter.createCounter("opencode.session.compaction.count", {
|
|
24
|
+
description: "Context compactions performed",
|
|
25
|
+
unit: "{compaction}"
|
|
26
|
+
}),
|
|
27
|
+
activeTime: meter.createCounter("opencode.active_time.total", {
|
|
28
|
+
description: "Wall time sessions spent busy",
|
|
29
|
+
unit: "s"
|
|
30
|
+
}),
|
|
31
|
+
linesOfCode: meter.createCounter("opencode.lines_of_code.count", {
|
|
32
|
+
description: "Lines added or removed across session diffs",
|
|
33
|
+
unit: "{line}"
|
|
34
|
+
}),
|
|
35
|
+
toolInvocations: meter.createCounter("opencode.tool.invocations", {
|
|
36
|
+
description: "Tool executions",
|
|
37
|
+
unit: "{invocation}"
|
|
38
|
+
}),
|
|
39
|
+
permissionDecisions: meter.createCounter("opencode.permission.decision.count", {
|
|
40
|
+
description: "Permission prompts resolved",
|
|
41
|
+
unit: "{decision}"
|
|
42
|
+
}),
|
|
43
|
+
commands: meter.createCounter("opencode.command.executed.count", {
|
|
44
|
+
description: "Slash commands executed",
|
|
45
|
+
unit: "{command}"
|
|
46
|
+
})
|
|
47
|
+
};
|
|
48
48
|
}
|
|
49
49
|
const EXTENSION_LANGUAGES = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
50
|
+
ts: "typescript",
|
|
51
|
+
tsx: "typescript",
|
|
52
|
+
mts: "typescript",
|
|
53
|
+
cts: "typescript",
|
|
54
|
+
js: "javascript",
|
|
55
|
+
jsx: "javascript",
|
|
56
|
+
mjs: "javascript",
|
|
57
|
+
cjs: "javascript",
|
|
58
|
+
py: "python",
|
|
59
|
+
rs: "rust",
|
|
60
|
+
go: "go",
|
|
61
|
+
java: "java",
|
|
62
|
+
kt: "kotlin",
|
|
63
|
+
kts: "kotlin",
|
|
64
|
+
swift: "swift",
|
|
65
|
+
dart: "dart",
|
|
66
|
+
rb: "ruby",
|
|
67
|
+
php: "php",
|
|
68
|
+
cs: "csharp",
|
|
69
|
+
c: "c",
|
|
70
|
+
h: "c",
|
|
71
|
+
cc: "cpp",
|
|
72
|
+
cpp: "cpp",
|
|
73
|
+
hpp: "cpp",
|
|
74
|
+
m: "objective-c",
|
|
75
|
+
mm: "objective-c",
|
|
76
|
+
scala: "scala",
|
|
77
|
+
ex: "elixir",
|
|
78
|
+
exs: "elixir",
|
|
79
|
+
sh: "shell",
|
|
80
|
+
bash: "shell",
|
|
81
|
+
zsh: "shell",
|
|
82
|
+
sql: "sql",
|
|
83
|
+
html: "html",
|
|
84
|
+
css: "css",
|
|
85
|
+
scss: "scss",
|
|
86
|
+
json: "json",
|
|
87
|
+
yaml: "yaml",
|
|
88
|
+
yml: "yaml",
|
|
89
|
+
toml: "toml",
|
|
90
|
+
md: "markdown",
|
|
91
|
+
tf: "terraform"
|
|
92
92
|
};
|
|
93
93
|
/** Best-effort language for a path, by extension. `undefined` when unknown. */
|
|
94
94
|
export function detectLanguage(file) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
const base = file.slice(file.lastIndexOf("/") + 1);
|
|
96
|
+
const dot = base.lastIndexOf(".");
|
|
97
|
+
if (dot <= 0) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
return EXTENSION_LANGUAGES[base.slice(dot + 1).toLowerCase()];
|
|
101
101
|
}
|
|
102
|
+
|
|
102
103
|
//# sourceMappingURL=instruments.js.map
|
package/dist/instruments.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AA4BA,OAAO,SAAS,kBAAkB,OAA2B;CAC3D,OAAO;EACL,MAAM,MAAM,cAAc,uBAAuB;GAC/C,aAAa;GACb,MAAM;EACR,CAAC;EACD,QAAQ,MAAM,gBAAgB,6BAA6B;GACzD,aAAa;GACb,MAAM;EACR,CAAC;EACD,UAAU,MAAM,gBAAgB,oCAAoC;GAClE,aAAa;GACb,MAAM;EACR,CAAC;EACD,UAAU,MAAM,cAAc,0BAA0B;GACtD,aAAa;GACb,MAAM;EACR,CAAC;EACD,UAAU,MAAM,cAAc,kCAAkC;GAC9D,aAAa;GACb,MAAM;EACR,CAAC;EACD,aAAa,MAAM,cAAc,qCAAqC;GACpE,aAAa;GACb,MAAM;EACR,CAAC;EACD,YAAY,MAAM,cAAc,8BAA8B;GAC5D,aAAa;GACb,MAAM;EACR,CAAC;EACD,aAAa,MAAM,cAAc,gCAAgC;GAC/D,aAAa;GACb,MAAM;EACR,CAAC;EACD,iBAAiB,MAAM,cAAc,6BAA6B;GAChE,aAAa;GACb,MAAM;EACR,CAAC;EACD,qBAAqB,MAAM,cAAc,sCAAsC;GAC7E,aAAa;GACb,MAAM;EACR,CAAC;EACD,UAAU,MAAM,cAAc,mCAAmC;GAC/D,aAAa;GACb,MAAM;EACR,CAAC;CACH;AACF;AAEA,MAAM,sBAA8C;CAClD,IAAI;CACJ,KAAK;CACL,KAAK;CACL,KAAK;CACL,IAAI;CACJ,KAAK;CACL,KAAK;CACL,KAAK;CACL,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,IAAI;CACJ,KAAK;CACL,OAAO;CACP,MAAM;CACN,IAAI;CACJ,KAAK;CACL,IAAI;CACJ,GAAG;CACH,GAAG;CACH,IAAI;CACJ,KAAK;CACL,KAAK;CACL,GAAG;CACH,IAAI;CACJ,OAAO;CACP,IAAI;CACJ,KAAK;CACL,IAAI;CACJ,MAAM;CACN,KAAK;CACL,KAAK;CACL,MAAM;CACN,KAAK;CACL,MAAM;CACN,MAAM;CACN,MAAM;CACN,KAAK;CACL,MAAM;CACN,IAAI;CACJ,IAAI;AACN;;AAGA,OAAO,SAAS,eAAe,MAAkC;CAC/D,MAAM,OAAO,KAAK,MAAM,KAAK,YAAY,GAAG,IAAI,CAAC;CACjD,MAAM,MAAM,KAAK,YAAY,GAAG;CAChC,IAAI,OAAO,GAAG;EACZ,OAAO;CACT;CACA,OAAO,oBAAoB,KAAK,MAAM,MAAM,CAAC,CAAC,CAAC,YAAY;AAC7D","names":[],"sources":["../src/instruments.ts"],"version":3,"file":"instruments.js","sourceRoot":""}
|
package/dist/lib.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export { createOtelPlugin, OpencodeOtelPlugin, type OtelPluginFactoryOptions } from "./opencode.js";
|
|
2
|
-
export { type EnvSource, parseKeyValueList, resolveOtelConfig, signalUrl, SIGNALS } from "./config.js";
|
|
2
|
+
export { type EnvSource, parseCommand, parseKeyValueList, resolveOtelConfig, signalUrl, SIGNALS } from "./config.js";
|
|
3
3
|
export { buildResource, createProviders, type ExporterFactories, type TelemetryProviders } from "./providers.js";
|
|
4
4
|
export { createInstruments, detectLanguage, type Instruments } from "./instruments.js";
|
|
5
5
|
export { type RecorderDeps, TelemetryRecorder } from "./recorder.js";
|
|
6
|
+
export { createTokenSource, DEFAULT_REFRESH_MS, EXPIRY_SKEW_MS, readJwtExpiry, type CommandRunner, type TokenSource, type TokenSourceOptions } from "./token-source.js";
|
|
7
|
+
export { type ExporterLike, withFailureLogging } from "./export-logging.js";
|
|
8
|
+
export { describeRemote, type FileReader, parseRemoteFromConfig, readVcsInfo, resolveGitDirs, sanitizeRemoteUrl, type VcsInfo } from "./vcs.js";
|
|
9
|
+
export { DEFAULT_DEFERRED_TIMEOUT_MS, deferredAttribute, type DeferredAttribute } from "./deferred.js";
|
|
6
10
|
export { installTracePropagation, type PropagationConfigInput, type ProviderConfigLike } from "./propagation.js";
|
|
7
11
|
export { createJsonConsoleLogger, DEFAULT_LOG_LEVEL, fromOpenCodeLogLevel, type LogFields, type Logger, type LogLevel } from "./logging.js";
|
|
8
12
|
export type { ExporterKind, MetricTemporality, OtelPluginOptions, ResolvedOtelConfig, SignalName } from "./types.js";
|
package/dist/lib.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export { createOtelPlugin, OpencodeOtelPlugin } from "./opencode.js";
|
|
2
|
-
export { parseKeyValueList, resolveOtelConfig, signalUrl, SIGNALS } from "./config.js";
|
|
2
|
+
export { parseCommand, parseKeyValueList, resolveOtelConfig, signalUrl, SIGNALS } from "./config.js";
|
|
3
3
|
export { buildResource, createProviders } from "./providers.js";
|
|
4
4
|
export { createInstruments, detectLanguage } from "./instruments.js";
|
|
5
5
|
export { TelemetryRecorder } from "./recorder.js";
|
|
6
|
+
export { createTokenSource, DEFAULT_REFRESH_MS, EXPIRY_SKEW_MS, readJwtExpiry } from "./token-source.js";
|
|
7
|
+
export { withFailureLogging } from "./export-logging.js";
|
|
8
|
+
export { describeRemote, parseRemoteFromConfig, readVcsInfo, resolveGitDirs, sanitizeRemoteUrl } from "./vcs.js";
|
|
9
|
+
export { DEFAULT_DEFERRED_TIMEOUT_MS, deferredAttribute } from "./deferred.js";
|
|
6
10
|
export { installTracePropagation } from "./propagation.js";
|
|
7
11
|
export { createJsonConsoleLogger, DEFAULT_LOG_LEVEL, fromOpenCodeLogLevel } from "./logging.js";
|
|
12
|
+
|
|
8
13
|
//# sourceMappingURL=lib.js.map
|
package/dist/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,SACE,kBACA,0BAEK;AAEP,SAEE,cACA,mBACA,mBACA,WACA,eACK;AAEP,SACE,eACA,uBAGK;AAEP,SAAS,mBAAmB,sBAAwC;AAEpE,SAA4B,yBAAyB;AAErD,SACE,mBACA,oBACA,gBACA,qBAIK;AAEP,SAA4B,0BAA0B;AAEtD,SACE,gBAEA,uBACA,aACA,gBACA,yBAEK;AAEP,SACE,6BACA,yBAEK;AAEP,SACE,+BAGK;AAEP,SACE,yBACA,mBACA,4BAIK","names":[],"sources":["../src/lib.ts"],"version":3,"file":"lib.js","sourceRoot":""}
|
package/dist/logging.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ export type { LogLevel } from "./types.js";
|
|
|
3
3
|
export declare const LOG_LEVEL_PRIORITY: Record<LogLevel, number>;
|
|
4
4
|
export declare const DEFAULT_LOG_LEVEL: LogLevel;
|
|
5
5
|
export interface LogFields {
|
|
6
|
-
|
|
6
|
+
[key: string]: unknown;
|
|
7
7
|
}
|
|
8
8
|
export interface Logger {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
trace(event: string, fields?: LogFields): void;
|
|
10
|
+
debug(event: string, fields?: LogFields): void;
|
|
11
|
+
info(event: string, fields?: LogFields): void;
|
|
12
|
+
warn(event: string, fields?: LogFields): void;
|
|
13
|
+
error(event: string, fields?: LogFields): void;
|
|
14
14
|
}
|
|
15
15
|
export declare function createJsonConsoleLogger(minLevel?: LogLevel): Logger;
|
|
16
16
|
export declare function fromOpenCodeLogLevel(value: unknown): LogLevel | undefined;
|
package/dist/logging.js
CHANGED
|
@@ -1,72 +1,69 @@
|
|
|
1
1
|
export const LOG_LEVEL_PRIORITY = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
trace: 5,
|
|
3
|
+
debug: 10,
|
|
4
|
+
info: 20,
|
|
5
|
+
warn: 30,
|
|
6
|
+
error: 40
|
|
7
7
|
};
|
|
8
8
|
export const DEFAULT_LOG_LEVEL = "info";
|
|
9
9
|
function redactFields(fields) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
if (!fields) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const redacted = {};
|
|
14
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
15
|
+
if (/token|secret|password|authorization/i.test(key)) {
|
|
16
|
+
redacted[key] = "[redacted]";
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
redacted[key] = value;
|
|
20
|
+
}
|
|
21
|
+
return redacted;
|
|
22
22
|
}
|
|
23
23
|
export function createJsonConsoleLogger(minLevel = DEFAULT_LOG_LEVEL) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
24
|
+
const minPriority = LOG_LEVEL_PRIORITY[minLevel];
|
|
25
|
+
const write = (level, event, fields) => {
|
|
26
|
+
if (LOG_LEVEL_PRIORITY[level] < minPriority) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const payload = {
|
|
30
|
+
ts: new Date().toISOString(),
|
|
31
|
+
level,
|
|
32
|
+
event,
|
|
33
|
+
...redactFields(fields) ?? {}
|
|
34
|
+
};
|
|
35
|
+
const line = JSON.stringify(payload);
|
|
36
|
+
if (level === "error") {
|
|
37
|
+
console.error(line);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (level === "warn") {
|
|
41
|
+
console.warn(line);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
console.log(line);
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
trace: (event, fields) => write("trace", event, fields),
|
|
48
|
+
debug: (event, fields) => write("debug", event, fields),
|
|
49
|
+
info: (event, fields) => write("info", event, fields),
|
|
50
|
+
warn: (event, fields) => write("warn", event, fields),
|
|
51
|
+
error: (event, fields) => write("error", event, fields)
|
|
52
|
+
};
|
|
53
53
|
}
|
|
54
54
|
export function fromOpenCodeLogLevel(value) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return "error";
|
|
68
|
-
default:
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
55
|
+
if (typeof value !== "string") {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
switch (value.toUpperCase()) {
|
|
59
|
+
case "DEBUG":
|
|
60
|
+
// Host DEBUG unlocks our most-verbose internal tier (trace).
|
|
61
|
+
return "trace";
|
|
62
|
+
case "INFO": return "info";
|
|
63
|
+
case "WARN": return "warn";
|
|
64
|
+
case "ERROR": return "error";
|
|
65
|
+
default: return undefined;
|
|
66
|
+
}
|
|
71
67
|
}
|
|
68
|
+
|
|
72
69
|
//# sourceMappingURL=logging.js.map
|
package/dist/logging.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAIA,OAAO,MAAM,qBAA+C;CAC1D,OAAO;CACP,OAAO;CACP,MAAM;CACN,MAAM;CACN,OAAO;AACT;AAEA,OAAO,MAAM,oBAA8B;AAc3C,SAAS,aAAa,QAA2C;CAC/D,IAAI,CAAC,QAAQ;EACX,OAAO;CACT;CACA,MAAM,WAAsB,CAAC;CAC7B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAAG;EACjD,IAAI,uCAAuC,KAAK,GAAG,GAAG;GACpD,SAAS,OAAO;GAChB;EACF;EACA,SAAS,OAAO;CAClB;CACA,OAAO;AACT;AAEA,OAAO,SAAS,wBAAwB,WAAqB,mBAA2B;CACtF,MAAM,cAAc,mBAAmB;CAEvC,MAAM,SAAS,OAAiB,OAAe,WAA6B;EAC1E,IAAI,mBAAmB,SAAS,aAAa;GAC3C;EACF;EACA,MAAM,UAAU;GACd,IAAI,IAAI,KAAK,CAAC,CAAC,YAAY;GAC3B;GACA;GACA,GAAI,aAAa,MAAM,KAAK,CAAC;EAC/B;EACA,MAAM,OAAO,KAAK,UAAU,OAAO;EACnC,IAAI,UAAU,SAAS;GACrB,QAAQ,MAAM,IAAI;GAClB;EACF;EACA,IAAI,UAAU,QAAQ;GACpB,QAAQ,KAAK,IAAI;GACjB;EACF;EACA,QAAQ,IAAI,IAAI;CAClB;CAEA,OAAO;EACL,QAAQ,OAAO,WAAW,MAAM,SAAS,OAAO,MAAM;EACtD,QAAQ,OAAO,WAAW,MAAM,SAAS,OAAO,MAAM;EACtD,OAAO,OAAO,WAAW,MAAM,QAAQ,OAAO,MAAM;EACpD,OAAO,OAAO,WAAW,MAAM,QAAQ,OAAO,MAAM;EACpD,QAAQ,OAAO,WAAW,MAAM,SAAS,OAAO,MAAM;CACxD;AACF;AAEA,OAAO,SAAS,qBAAqB,OAAsC;CACzE,IAAI,OAAO,UAAU,UAAU;EAC7B,OAAO;CACT;CACA,QAAQ,MAAM,YAAY,GAA1B;EACE,KAAK;;EAEH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,SACH,OAAO;EACT,SACE,OAAO;CACX;AACF","names":[],"sources":["../src/logging.ts"],"version":3,"file":"logging.js","sourceRoot":""}
|