@evref-bl/plexus 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/answers/index.d.ts +97 -0
- package/dist/answers/index.d.ts.map +1 -0
- package/dist/answers/index.js +352 -0
- package/dist/answers/index.js.map +1 -0
- package/dist/answers/texts.d.ts +83 -0
- package/dist/answers/texts.d.ts.map +1 -0
- package/dist/answers/texts.js +216 -0
- package/dist/answers/texts.js.map +1 -0
- package/dist/cli.js +16 -2
- package/dist/cli.js.map +1 -1
- package/dist/commandLine.d.ts.map +1 -1
- package/dist/commandLine.js +21 -9
- package/dist/commandLine.js.map +1 -1
- package/dist/config/pharoMcpVersion.d.ts +1 -1
- package/dist/config/pharoMcpVersion.js +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/forward/index.d.ts +43 -2
- package/dist/forward/index.d.ts.map +1 -1
- package/dist/forward/index.js +59 -3
- package/dist/forward/index.js.map +1 -1
- package/dist/forward/jsonRpc.d.ts +40 -2
- package/dist/forward/jsonRpc.d.ts.map +1 -1
- package/dist/forward/jsonRpc.js +143 -25
- package/dist/forward/jsonRpc.js.map +1 -1
- package/dist/images/bases.d.ts +3 -2
- package/dist/images/bases.d.ts.map +1 -1
- package/dist/images/bases.js +12 -8
- package/dist/images/bases.js.map +1 -1
- package/dist/images/context.d.ts +17 -2
- package/dist/images/context.d.ts.map +1 -1
- package/dist/images/context.js +15 -1
- package/dist/images/context.js.map +1 -1
- package/dist/images/create.d.ts.map +1 -1
- package/dist/images/create.js +3 -2
- package/dist/images/create.js.map +1 -1
- package/dist/images/delete.d.ts.map +1 -1
- package/dist/images/delete.js +2 -1
- package/dist/images/delete.js.map +1 -1
- package/dist/images/endpoint.d.ts +13 -1
- package/dist/images/endpoint.d.ts.map +1 -1
- package/dist/images/endpoint.js +29 -1
- package/dist/images/endpoint.js.map +1 -1
- package/dist/images/index.d.ts +9 -5
- package/dist/images/index.d.ts.map +1 -1
- package/dist/images/index.js +19 -14
- package/dist/images/index.js.map +1 -1
- package/dist/images/scripts.d.ts +13 -4
- package/dist/images/scripts.d.ts.map +1 -1
- package/dist/images/scripts.js +28 -6
- package/dist/images/scripts.js.map +1 -1
- package/dist/images/start.d.ts.map +1 -1
- package/dist/images/start.js +11 -5
- package/dist/images/start.js.map +1 -1
- package/dist/images/stop.d.ts +13 -7
- package/dist/images/stop.d.ts.map +1 -1
- package/dist/images/stop.js +138 -9
- package/dist/images/stop.js.map +1 -1
- package/dist/images/store.d.ts.map +1 -1
- package/dist/images/store.js +2 -1
- package/dist/images/store.js.map +1 -1
- package/dist/images/templates.d.ts.map +1 -1
- package/dist/images/templates.js +2 -1
- package/dist/images/templates.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.d.ts +11 -2
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +135 -72
- package/dist/mcp/server.js.map +1 -1
- package/dist/telemetry/reachability.d.ts +59 -0
- package/dist/telemetry/reachability.d.ts.map +1 -0
- package/dist/telemetry/reachability.js +183 -0
- package/dist/telemetry/reachability.js.map +1 -0
- package/dist/telemetry/sdk.d.ts +54 -0
- package/dist/telemetry/sdk.d.ts.map +1 -0
- package/dist/telemetry/sdk.js +167 -0
- package/dist/telemetry/sdk.js.map +1 -0
- package/dist/telemetry/settings.d.ts +16 -0
- package/dist/telemetry/settings.d.ts.map +1 -0
- package/dist/telemetry/settings.js +67 -0
- package/dist/telemetry/settings.js.map +1 -0
- package/dist/telemetry/trace.d.ts +32 -0
- package/dist/telemetry/trace.d.ts.map +1 -0
- package/dist/telemetry/trace.js +79 -0
- package/dist/telemetry/trace.js.map +1 -0
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +13 -4
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** The SDK the command installed, or none: what to run the command in, and how to end it. */
|
|
2
|
+
export interface Telemetry {
|
|
3
|
+
/** Runs the command's work under the parent `TRACEPARENT` names, when it names one. */
|
|
4
|
+
within<T>(work: () => T): T;
|
|
5
|
+
/** Exports what is left, waiting no longer than a second, or the export timeout when it is shorter. */
|
|
6
|
+
shutdown(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface TelemetryOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The process serves until its input closes (`plexus mcp`): its batches go
|
|
11
|
+
* in the background with the whole export timeout. Otherwise each export
|
|
12
|
+
* is given no more than the process waits at its end.
|
|
13
|
+
*/
|
|
14
|
+
longLived?: boolean;
|
|
15
|
+
/** Where reachability is kept, instead of the user's cache directory. */
|
|
16
|
+
reachabilityFile?: string;
|
|
17
|
+
/** The clock reachability is kept by. */
|
|
18
|
+
now?: () => number;
|
|
19
|
+
}
|
|
20
|
+
/** How long an export may take, and how long the process waits for its spans as it ends. */
|
|
21
|
+
export declare function exportTimings(traces: TracesExport, longLived?: boolean): {
|
|
22
|
+
exportTimeoutMs: number;
|
|
23
|
+
exitWaitMs: number;
|
|
24
|
+
};
|
|
25
|
+
export interface TracesExport {
|
|
26
|
+
protocol: "http/protobuf" | "http/json";
|
|
27
|
+
timeoutMs: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* What the environment asks of traces: an OTLP export over HTTP, or nothing.
|
|
31
|
+
* Nothing when `OTEL_SDK_DISABLED` is true, when `OTEL_TRACES_EXPORTER` names
|
|
32
|
+
* an exporter other than `otlp` (`none` among them), when no OTLP endpoint is
|
|
33
|
+
* set, and when the protocol is one PLexus does not send (gRPC).
|
|
34
|
+
*/
|
|
35
|
+
export declare function tracesExport(env: NodeJS.ProcessEnv): TracesExport | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Installs the trace SDK when `env` asks for it, and says how to run and end
|
|
38
|
+
* the command under it. The exporter reads the rest of its settings, the
|
|
39
|
+
* endpoint and headers among them, from the process environment, as the
|
|
40
|
+
* OpenTelemetry exporters do.
|
|
41
|
+
*
|
|
42
|
+
* The resource is `service.name`, `service.version`, `os.type`, Node's version
|
|
43
|
+
* as `process.runtime.*`, and what `OTEL_RESOURCE_ATTRIBUTES` adds; the
|
|
44
|
+
* environment cannot replace these, since the programs PLexus runs with share
|
|
45
|
+
* it. The host and process detectors are not used: they would send the
|
|
46
|
+
* hostname, the command line and the executable's path.
|
|
47
|
+
*
|
|
48
|
+
* When the endpoint failed recently and its time to try again has not come,
|
|
49
|
+
* nothing is installed and no SDK module is loaded.
|
|
50
|
+
*/
|
|
51
|
+
export declare function startTelemetry(env: NodeJS.ProcessEnv, options?: TelemetryOptions): Promise<Telemetry>;
|
|
52
|
+
/** The parent a caller passes in `TRACEPARENT`, `TRACESTATE` and `BAGGAGE`, as the environment carrier has it. */
|
|
53
|
+
export declare function parentFromEnvironment(env: NodeJS.ProcessEnv): import("@opentelemetry/api").Context;
|
|
54
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/telemetry/sdk.ts"],"names":[],"mappings":"AAgBA,6FAA6F;AAC7F,MAAM,WAAW,SAAS;IACxB,uFAAuF;IACvF,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5B,uGAAuG;IACvG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAaD,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,yEAAyE;IACzE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,yCAAyC;IACzC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,UAAQ,GAAG;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAGtH;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,eAAe,GAAG,WAAW,CAAC;IACxC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,YAAY,GAAG,SAAS,CAyB7E;AAOD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,SAAS,CAAC,CA8D/G;AAED,kHAAkH;AAClH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,wCAa3D"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `plexus` command is an application, so it may install an OpenTelemetry
|
|
3
|
+
* SDK, which the library never does. It installs one only when the standard
|
|
4
|
+
* `OTEL_*` environment asks for an OTLP traces exporter, loading the SDK then
|
|
5
|
+
* and not before; with nothing configured, nothing is loaded or sent.
|
|
6
|
+
*
|
|
7
|
+
* Nothing here reaches a command's answer or its exit status: an SDK that is
|
|
8
|
+
* missing, fails to load, or fails to export leaves the command as it was,
|
|
9
|
+
* and nothing is printed. A collector that could not be reached is
|
|
10
|
+
* remembered, and left alone for a while (see `reachability.ts`).
|
|
11
|
+
*/
|
|
12
|
+
import os from "node:os";
|
|
13
|
+
import { context, propagation, ROOT_CONTEXT, trace } from "@opentelemetry/api";
|
|
14
|
+
import { plexusVersion } from "../version.js";
|
|
15
|
+
import { GuardedExporter, Reachability, reachabilityFile, tracesEndpoint } from "./reachability.js";
|
|
16
|
+
const none = {
|
|
17
|
+
within: (work) => work(),
|
|
18
|
+
shutdown: async () => undefined,
|
|
19
|
+
};
|
|
20
|
+
/** The export timeout unless `OTEL_EXPORTER_OTLP_TIMEOUT` says otherwise: a command never waits long on telemetry. */
|
|
21
|
+
const defaultTimeoutMs = 2_000;
|
|
22
|
+
/** The longest a process waits for its spans as it ends. */
|
|
23
|
+
const longestExitWaitMs = 1_000;
|
|
24
|
+
/** How long an export may take, and how long the process waits for its spans as it ends. */
|
|
25
|
+
export function exportTimings(traces, longLived = false) {
|
|
26
|
+
const exitWaitMs = Math.min(longestExitWaitMs, traces.timeoutMs);
|
|
27
|
+
return { exportTimeoutMs: longLived ? traces.timeoutMs : exitWaitMs, exitWaitMs };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* What the environment asks of traces: an OTLP export over HTTP, or nothing.
|
|
31
|
+
* Nothing when `OTEL_SDK_DISABLED` is true, when `OTEL_TRACES_EXPORTER` names
|
|
32
|
+
* an exporter other than `otlp` (`none` among them), when no OTLP endpoint is
|
|
33
|
+
* set, and when the protocol is one PLexus does not send (gRPC).
|
|
34
|
+
*/
|
|
35
|
+
export function tracesExport(env) {
|
|
36
|
+
if (env.OTEL_SDK_DISABLED?.trim().toLowerCase() === "true") {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const exporters = (env.OTEL_TRACES_EXPORTER ?? "")
|
|
40
|
+
.split(",")
|
|
41
|
+
.map((each) => each.trim().toLowerCase())
|
|
42
|
+
.filter((each) => each !== "");
|
|
43
|
+
if (exporters.length > 0 && !(exporters.length === 1 && exporters[0] === "otlp")) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
if (!(env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT?.trim() || env.OTEL_EXPORTER_OTLP_ENDPOINT?.trim())) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const protocol = (env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL?.trim() ||
|
|
50
|
+
env.OTEL_EXPORTER_OTLP_PROTOCOL?.trim() ||
|
|
51
|
+
"http/protobuf").toLowerCase();
|
|
52
|
+
if (protocol !== "http/protobuf" && protocol !== "http/json") {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
const timeoutMs = positive(env.OTEL_EXPORTER_OTLP_TRACES_TIMEOUT) ?? positive(env.OTEL_EXPORTER_OTLP_TIMEOUT) ?? defaultTimeoutMs;
|
|
56
|
+
return { protocol, timeoutMs };
|
|
57
|
+
}
|
|
58
|
+
function positive(value) {
|
|
59
|
+
const number = value === undefined || value.trim() === "" ? NaN : Number(value);
|
|
60
|
+
return Number.isFinite(number) && number > 0 ? number : undefined;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Installs the trace SDK when `env` asks for it, and says how to run and end
|
|
64
|
+
* the command under it. The exporter reads the rest of its settings, the
|
|
65
|
+
* endpoint and headers among them, from the process environment, as the
|
|
66
|
+
* OpenTelemetry exporters do.
|
|
67
|
+
*
|
|
68
|
+
* The resource is `service.name`, `service.version`, `os.type`, Node's version
|
|
69
|
+
* as `process.runtime.*`, and what `OTEL_RESOURCE_ATTRIBUTES` adds; the
|
|
70
|
+
* environment cannot replace these, since the programs PLexus runs with share
|
|
71
|
+
* it. The host and process detectors are not used: they would send the
|
|
72
|
+
* hostname, the command line and the executable's path.
|
|
73
|
+
*
|
|
74
|
+
* When the endpoint failed recently and its time to try again has not come,
|
|
75
|
+
* nothing is installed and no SDK module is loaded.
|
|
76
|
+
*/
|
|
77
|
+
export async function startTelemetry(env, options = {}) {
|
|
78
|
+
const traces = tracesExport(env);
|
|
79
|
+
const endpoint = tracesEndpoint(env);
|
|
80
|
+
if (traces === undefined || endpoint === undefined) {
|
|
81
|
+
return none;
|
|
82
|
+
}
|
|
83
|
+
const reachability = new Reachability(options.reachabilityFile ?? reachabilityFile(env), endpoint, options.now);
|
|
84
|
+
if (reachability.isOpen()) {
|
|
85
|
+
return none;
|
|
86
|
+
}
|
|
87
|
+
const { exportTimeoutMs, exitWaitMs } = exportTimings(traces, options.longLived);
|
|
88
|
+
try {
|
|
89
|
+
const [sdk, hooks, core, resources, exporters] = await Promise.all([
|
|
90
|
+
import("@opentelemetry/sdk-trace"),
|
|
91
|
+
import("@opentelemetry/context-async-hooks"),
|
|
92
|
+
import("@opentelemetry/core"),
|
|
93
|
+
import("@opentelemetry/resources"),
|
|
94
|
+
traces.protocol === "http/json"
|
|
95
|
+
? import("@opentelemetry/exporter-trace-otlp-http")
|
|
96
|
+
: import("@opentelemetry/exporter-trace-otlp-proto"),
|
|
97
|
+
]);
|
|
98
|
+
const resource = resources
|
|
99
|
+
.defaultResource()
|
|
100
|
+
.merge(resources.detectResources({ detectors: [resources.envDetector] }))
|
|
101
|
+
.merge(resources.resourceFromAttributes({
|
|
102
|
+
"service.name": "plexus",
|
|
103
|
+
"service.version": plexusVersion,
|
|
104
|
+
"os.type": osType(),
|
|
105
|
+
"process.runtime.name": "nodejs",
|
|
106
|
+
"process.runtime.version": process.versions.node,
|
|
107
|
+
}));
|
|
108
|
+
const provider = new sdk.TracerProvider({
|
|
109
|
+
resource,
|
|
110
|
+
spanProcessors: [
|
|
111
|
+
new sdk.BatchSpanProcessor({
|
|
112
|
+
exporter: new GuardedExporter(new exporters.OTLPTraceExporter({ timeoutMillis: exportTimeoutMs }), reachability, core.ExportResultCode),
|
|
113
|
+
exportTimeoutMillis: exportTimeoutMs,
|
|
114
|
+
}),
|
|
115
|
+
],
|
|
116
|
+
});
|
|
117
|
+
context.setGlobalContextManager(new hooks.AsyncLocalStorageContextManager().enable());
|
|
118
|
+
propagation.setGlobalPropagator(new core.CompositePropagator({
|
|
119
|
+
propagators: [new core.W3CTraceContextPropagator(), new core.W3CBaggagePropagator()],
|
|
120
|
+
}));
|
|
121
|
+
trace.setGlobalTracerProvider(provider);
|
|
122
|
+
const parent = parentFromEnvironment(env);
|
|
123
|
+
return {
|
|
124
|
+
within: (work) => context.with(parent, work),
|
|
125
|
+
shutdown: () => within(exitWaitMs, provider.shutdown()),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return none;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** The parent a caller passes in `TRACEPARENT`, `TRACESTATE` and `BAGGAGE`, as the environment carrier has it. */
|
|
133
|
+
export function parentFromEnvironment(env) {
|
|
134
|
+
const carrier = {};
|
|
135
|
+
for (const [key, variable] of [
|
|
136
|
+
["traceparent", "TRACEPARENT"],
|
|
137
|
+
["tracestate", "TRACESTATE"],
|
|
138
|
+
["baggage", "BAGGAGE"],
|
|
139
|
+
]) {
|
|
140
|
+
const value = env[variable];
|
|
141
|
+
if (value !== undefined && value !== "") {
|
|
142
|
+
carrier[key] = value;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return propagation.extract(ROOT_CONTEXT, carrier);
|
|
146
|
+
}
|
|
147
|
+
/** The work's end, or the bound's, whichever comes first, failing never. */
|
|
148
|
+
async function within(boundMs, work) {
|
|
149
|
+
let timer;
|
|
150
|
+
try {
|
|
151
|
+
await Promise.race([
|
|
152
|
+
work.catch(() => undefined),
|
|
153
|
+
new Promise((resolve) => {
|
|
154
|
+
timer = setTimeout(resolve, boundMs);
|
|
155
|
+
}),
|
|
156
|
+
]);
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
clearTimeout(timer);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** The OS family, in OpenTelemetry's words. */
|
|
163
|
+
function osType() {
|
|
164
|
+
const platform = os.platform();
|
|
165
|
+
return platform === "win32" ? "windows" : platform === "sunos" ? "solaris" : platform;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/telemetry/sdk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAA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AAY,CAAC;QAC5B,CAAC,SAAS,EAAE,SAAS,CAAC;KACd,EAAE,CAAC;QACX,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;YACxC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,WAAW,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,4EAA4E;AAC5E,KAAK,UAAU,MAAM,CAAC,OAAe,EAAE,IAAsB;IAC3D,IAAI,KAAiC,CAAC;IACtC,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,IAAI,CAAC;YACjB,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;YAC3B,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBACtB,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACvC,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,+CAA+C;AAC/C,SAAS,MAAM;IACb,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC/B,OAAO,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;AACxF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Where the settings live. */
|
|
2
|
+
export declare function settingsFile(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, home?: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* The OTEL_* settings a file's lines give. Blank lines and `#` comments are
|
|
5
|
+
* skipped, as are a leading `export` and quotes around a value; any other
|
|
6
|
+
* key is not ours to set.
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseSettings(text: string): Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* Puts the file's settings into the environment, unless it already sets an
|
|
11
|
+
* OTEL_* of its own: whoever set one there meant the environment to decide.
|
|
12
|
+
* The images PLexus starts run in this environment, so they read the same
|
|
13
|
+
* settings. Answers what it set; nothing when there is no file.
|
|
14
|
+
*/
|
|
15
|
+
export declare function applySettingsFile(env?: NodeJS.ProcessEnv, file?: string): Record<string, string>;
|
|
16
|
+
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/telemetry/settings.ts"],"names":[],"mappings":"AAWA,+BAA+B;AAC/B,wBAAgB,YAAY,CAC1B,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,QAAQ,GAAE,MAAM,CAAC,QAA2B,EAC5C,IAAI,GAAE,MAAqB,GAC1B,MAAM,CAMR;AAID;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAelE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,IAAI,GAAE,MAA0B,GAC/B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAWxB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The settings file the Pharo tools share: `KEY=value` lines of standard
|
|
3
|
+
* OTEL_* variables, read when the environment sets none. Agent hosts do not
|
|
4
|
+
* pass OTEL_* to the servers they start, so a variable set in a shell never
|
|
5
|
+
* reaches `plexus mcp`; the file does. The pharo-agent plugin and Pharo MCP
|
|
6
|
+
* read the same file.
|
|
7
|
+
*/
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
/** Where the settings live. */
|
|
12
|
+
export function settingsFile(env = process.env, platform = process.platform, home = os.homedir()) {
|
|
13
|
+
const paths = platform === "win32" ? path.win32 : path.posix;
|
|
14
|
+
const xdg = env.XDG_CONFIG_HOME;
|
|
15
|
+
if (xdg && paths.isAbsolute(xdg))
|
|
16
|
+
return paths.join(xdg, "pharo-agent", "otel.env");
|
|
17
|
+
if (platform === "win32" && env.APPDATA)
|
|
18
|
+
return paths.join(env.APPDATA, "pharo-agent", "otel.env");
|
|
19
|
+
return paths.join(home, ".config", "pharo-agent", "otel.env");
|
|
20
|
+
}
|
|
21
|
+
const settingName = /^OTEL_[A-Z0-9_]+$/;
|
|
22
|
+
/**
|
|
23
|
+
* The OTEL_* settings a file's lines give. Blank lines and `#` comments are
|
|
24
|
+
* skipped, as are a leading `export` and quotes around a value; any other
|
|
25
|
+
* key is not ours to set.
|
|
26
|
+
*/
|
|
27
|
+
export function parseSettings(text) {
|
|
28
|
+
const settings = {};
|
|
29
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
30
|
+
const line = raw.trim().replace(/^export\s+/, "");
|
|
31
|
+
if (line === "" || line.startsWith("#"))
|
|
32
|
+
continue;
|
|
33
|
+
const equals = line.indexOf("=");
|
|
34
|
+
if (equals === -1)
|
|
35
|
+
continue;
|
|
36
|
+
const key = line.slice(0, equals).trim();
|
|
37
|
+
if (!settingName.test(key))
|
|
38
|
+
continue;
|
|
39
|
+
let value = line.slice(equals + 1).trim();
|
|
40
|
+
const quoted = value.match(/^(["'])(.*)\1$/s);
|
|
41
|
+
if (quoted)
|
|
42
|
+
value = quoted[2];
|
|
43
|
+
settings[key] = value;
|
|
44
|
+
}
|
|
45
|
+
return settings;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Puts the file's settings into the environment, unless it already sets an
|
|
49
|
+
* OTEL_* of its own: whoever set one there meant the environment to decide.
|
|
50
|
+
* The images PLexus starts run in this environment, so they read the same
|
|
51
|
+
* settings. Answers what it set; nothing when there is no file.
|
|
52
|
+
*/
|
|
53
|
+
export function applySettingsFile(env = process.env, file = settingsFile(env)) {
|
|
54
|
+
if (Object.keys(env).some((key) => key.startsWith("OTEL_")))
|
|
55
|
+
return {};
|
|
56
|
+
let text;
|
|
57
|
+
try {
|
|
58
|
+
text = fs.readFileSync(file, "utf8");
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
const settings = parseSettings(text);
|
|
64
|
+
Object.assign(env, settings);
|
|
65
|
+
return settings;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/telemetry/settings.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,+BAA+B;AAC/B,MAAM,UAAU,YAAY,CAC1B,MAAyB,OAAO,CAAC,GAAG,EACpC,WAA4B,OAAO,CAAC,QAAQ,EAC5C,OAAe,EAAE,CAAC,OAAO,EAAE;IAE3B,MAAM,KAAK,GAAG,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;IAC7D,MAAM,GAAG,GAAG,GAAG,CAAC,eAAe,CAAC;IAChC,IAAI,GAAG,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;IACpF,IAAI,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC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C,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IACvE,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC7B,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What PLexus records about its own work, through the OpenTelemetry API
|
|
3
|
+
* alone: every call here is a no-op until the application running PLexus
|
|
4
|
+
* registers an SDK. A span carries names, kinds and outcomes, never a value:
|
|
5
|
+
* no argument, result, image name, path or message, and no status
|
|
6
|
+
* description, since that would be a message.
|
|
7
|
+
*/
|
|
8
|
+
import { type Attributes, type Span, type SpanKind } from "@opentelemetry/api";
|
|
9
|
+
/** A name chosen by code, kept as it is when it looks like an identifier, and `_OTHER` when it does not. */
|
|
10
|
+
export declare function identifierOrOther(name: string): string;
|
|
11
|
+
/** Marks the span failed: status ERROR, with no description, and `error.type`. */
|
|
12
|
+
export declare function failed(span: Span, type: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* The kind of a failure: a PlexusError's code, else the error's class name.
|
|
15
|
+
* Both are chosen by code, never by what the error is about.
|
|
16
|
+
*/
|
|
17
|
+
export declare function errorType(error: unknown): string;
|
|
18
|
+
/**
|
|
19
|
+
* `work` inside a span that is active while it runs, ended with its outcome.
|
|
20
|
+
* A rejection fails the span with the type `typeOf` gives, and is passed on.
|
|
21
|
+
*/
|
|
22
|
+
export declare function inSpan<T>(name: string, kind: SpanKind, attributes: Attributes, work: (span: Span) => Promise<T>, typeOf?: (error: unknown) => string): Promise<T>;
|
|
23
|
+
/**
|
|
24
|
+
* The params with the active trace context in their `_meta`, under the
|
|
25
|
+
* unprefixed `traceparent`, `tracestate` and `baggage` keys, beside whatever
|
|
26
|
+
* `_meta` they already carry. Unchanged when there is no context to pass,
|
|
27
|
+
* which is always the case while no SDK is registered.
|
|
28
|
+
*/
|
|
29
|
+
export declare function withTraceContext(params: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
|
|
30
|
+
/** The trace context a request's `_meta` names, as the parent of what answers it. */
|
|
31
|
+
export declare function contextFromMeta(meta: unknown): import("@opentelemetry/api").Context;
|
|
32
|
+
//# sourceMappingURL=trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/telemetry/trace.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAKL,KAAK,UAAU,EACf,KAAK,IAAI,EACT,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAM5B,4GAA4G;AAC5G,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,kFAAkF;AAClF,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAGrD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAKhD;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACtB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,EACd,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,EAChC,MAAM,GAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAkB,GAC7C,OAAO,CAAC,CAAC,CAAC,CAaZ;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAC1C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAQrC;AAED,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,wCAQ5C"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What PLexus records about its own work, through the OpenTelemetry API
|
|
3
|
+
* alone: every call here is a no-op until the application running PLexus
|
|
4
|
+
* registers an SDK. A span carries names, kinds and outcomes, never a value:
|
|
5
|
+
* no argument, result, image name, path or message, and no status
|
|
6
|
+
* description, since that would be a message.
|
|
7
|
+
*/
|
|
8
|
+
import { context, propagation, SpanStatusCode, trace, } from "@opentelemetry/api";
|
|
9
|
+
import { PlexusError } from "../errors.js";
|
|
10
|
+
import { plexusVersion } from "../version.js";
|
|
11
|
+
const identifier = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
|
|
12
|
+
/** A name chosen by code, kept as it is when it looks like an identifier, and `_OTHER` when it does not. */
|
|
13
|
+
export function identifierOrOther(name) {
|
|
14
|
+
return identifier.test(name) ? name : "_OTHER";
|
|
15
|
+
}
|
|
16
|
+
/** Marks the span failed: status ERROR, with no description, and `error.type`. */
|
|
17
|
+
export function failed(span, type) {
|
|
18
|
+
span.setAttribute("error.type", type);
|
|
19
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The kind of a failure: a PlexusError's code, else the error's class name.
|
|
23
|
+
* Both are chosen by code, never by what the error is about.
|
|
24
|
+
*/
|
|
25
|
+
export function errorType(error) {
|
|
26
|
+
if (error instanceof PlexusError) {
|
|
27
|
+
return error.code;
|
|
28
|
+
}
|
|
29
|
+
return error instanceof Error ? identifierOrOther(error.name) : "_OTHER";
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `work` inside a span that is active while it runs, ended with its outcome.
|
|
33
|
+
* A rejection fails the span with the type `typeOf` gives, and is passed on.
|
|
34
|
+
*/
|
|
35
|
+
export function inSpan(name, kind, attributes, work, typeOf = errorType) {
|
|
36
|
+
return trace
|
|
37
|
+
.getTracer("@evref-bl/plexus", plexusVersion)
|
|
38
|
+
.startActiveSpan(name, { kind, attributes }, async (span) => {
|
|
39
|
+
try {
|
|
40
|
+
return await work(span);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
failed(span, typeOf(error));
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
span.end();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The params with the active trace context in their `_meta`, under the
|
|
53
|
+
* unprefixed `traceparent`, `tracestate` and `baggage` keys, beside whatever
|
|
54
|
+
* `_meta` they already carry. Unchanged when there is no context to pass,
|
|
55
|
+
* which is always the case while no SDK is registered.
|
|
56
|
+
*/
|
|
57
|
+
export function withTraceContext(params) {
|
|
58
|
+
const carrier = {};
|
|
59
|
+
propagation.inject(context.active(), carrier);
|
|
60
|
+
if (Object.keys(carrier).length === 0) {
|
|
61
|
+
return params;
|
|
62
|
+
}
|
|
63
|
+
const meta = isRecord(params?._meta) ? params._meta : {};
|
|
64
|
+
return { ...params, _meta: { ...meta, ...carrier } };
|
|
65
|
+
}
|
|
66
|
+
/** The trace context a request's `_meta` names, as the parent of what answers it. */
|
|
67
|
+
export function contextFromMeta(meta) {
|
|
68
|
+
return propagation.extract(context.active(), isRecord(meta) ? meta : {}, {
|
|
69
|
+
get: (carrier, key) => {
|
|
70
|
+
const value = carrier[key];
|
|
71
|
+
return typeof value === "string" ? value : undefined;
|
|
72
|
+
},
|
|
73
|
+
keys: (carrier) => Object.keys(carrier),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function isRecord(value) {
|
|
77
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../src/telemetry/trace.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,OAAO,EACP,WAAW,EACX,cAAc,EACd,KAAK,GAIN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,UAAU,GAAG,gCAAgC,CAAC;AAEpD,4GAA4G;AAC5G,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;AACjD,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,MAAM,CAAC,IAAU,EAAE,IAAY;IAC7C,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IACtC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IACD,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC3E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,MAAM,CACpB,IAAY,EACZ,IAAc,EACd,UAAsB,EACtB,IAAgC,EAChC,SAAqC,SAAS;IAE9C,OAAO,KAAK;SACT,SAAS,CAAC,kBAAkB,EAAE,aAAa,CAAC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AC,CAAC;YAC3B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;QACvD,CAAC;QACD,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;KACxC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -57,6 +57,13 @@ export interface StartOptions {
|
|
|
57
57
|
/** How long the image has to answer: 300000 unless given. */
|
|
58
58
|
timeoutMs?: number;
|
|
59
59
|
}
|
|
60
|
+
export interface StopOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Have the image save itself and quit, through its MCP server, instead of
|
|
63
|
+
* killing it. Killing without saving unless given.
|
|
64
|
+
*/
|
|
65
|
+
save?: boolean;
|
|
66
|
+
}
|
|
60
67
|
export interface ImagesOptions {
|
|
61
68
|
/** `plexusHome()` unless given. */
|
|
62
69
|
home?: string;
|
|
@@ -64,5 +71,12 @@ export interface ImagesOptions {
|
|
|
64
71
|
scope?: string;
|
|
65
72
|
/** The launcher on the home's profile unless given. */
|
|
66
73
|
launcher?: LauncherPort;
|
|
74
|
+
/**
|
|
75
|
+
* Enroll the images handled in OpenTelemetry: an image made without a
|
|
76
|
+
* script loads MCP's `Telemetry` group as well, and an image started
|
|
77
|
+
* switches its MCP server to the OpenTelemetry backend when it has one.
|
|
78
|
+
* `PLEXUS_TELEMETRY` (`1` or `true`) unless given.
|
|
79
|
+
*/
|
|
80
|
+
telemetry?: boolean;
|
|
67
81
|
}
|
|
68
82
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
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
|
4
4
|
"private": false,
|
|
5
5
|
"description": "PLexus: Pharo images as directories and processes, and forwarding to the MCP servers they run.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
|
-
"node": ">=22.
|
|
34
|
+
"node": ">=22.15.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsc -p tsconfig.json",
|
|
@@ -41,7 +41,16 @@
|
|
|
41
41
|
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\""
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@evref-bl/pharo-launcher-mcp": "0.
|
|
45
|
-
"@modelcontextprotocol/sdk": "^1.29.0"
|
|
44
|
+
"@evref-bl/pharo-launcher-mcp": "0.5.0",
|
|
45
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
46
|
+
"@opentelemetry/api": "1.10.0"
|
|
47
|
+
},
|
|
48
|
+
"optionalDependencies": {
|
|
49
|
+
"@opentelemetry/context-async-hooks": "3.1.1",
|
|
50
|
+
"@opentelemetry/core": "3.1.1",
|
|
51
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.301.2",
|
|
52
|
+
"@opentelemetry/exporter-trace-otlp-proto": "0.301.2",
|
|
53
|
+
"@opentelemetry/resources": "3.1.1",
|
|
54
|
+
"@opentelemetry/sdk-trace": "3.1.1"
|
|
46
55
|
}
|
|
47
56
|
}
|