@oka-core/reason 0.2.16 → 0.2.17
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/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/telemetry.d.ts +16 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +61 -0
- package/package.json +8 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAWA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,9 +8,12 @@ import { registerReadTools } from "./tools/read.js";
|
|
|
8
8
|
import { registerAuthTools } from "./tools/auth.js";
|
|
9
9
|
import { loadEnvFile } from "./auth.js";
|
|
10
10
|
import { analytics } from "./analytics.js";
|
|
11
|
+
import { initTelemetry, shutdownTelemetry } from "./telemetry.js";
|
|
11
12
|
export { analytics } from "./analytics.js";
|
|
12
13
|
// Load .env from the project root (cwd), env vars take precedence
|
|
13
14
|
loadEnvFile(process.cwd());
|
|
15
|
+
// Initialize OTel tracing (no-op if OTEL_EXPORTER_OTLP_ENDPOINT is not set)
|
|
16
|
+
await initTelemetry();
|
|
14
17
|
// Attach a no-op sink so analytics events don't queue indefinitely.
|
|
15
18
|
// Downstream consumers can replace this by calling analytics.attach() with a real sink.
|
|
16
19
|
analytics.attach({ track: () => { } });
|
|
@@ -27,4 +30,7 @@ registerWriteTools(server, client);
|
|
|
27
30
|
registerReadTools(server, client);
|
|
28
31
|
registerAuthTools(server, client);
|
|
29
32
|
const transport = new StdioServerTransport();
|
|
33
|
+
// Flush OTel spans on shutdown
|
|
34
|
+
process.on("SIGTERM", () => void shutdownTelemetry());
|
|
35
|
+
process.on("SIGINT", () => void shutdownTelemetry());
|
|
30
36
|
await server.connect(transport);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional OpenTelemetry initialization for the MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Activates only when OTEL_EXPORTER_OTLP_ENDPOINT is set in the environment.
|
|
5
|
+
* Exports traces via OTLP/HTTP to the configured collector (e.g. https://otel.oka.so).
|
|
6
|
+
*
|
|
7
|
+
* Zero cost when disabled — returns a no-op shutdown function.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Initialize OTel tracing if OTEL_EXPORTER_OTLP_ENDPOINT is set.
|
|
11
|
+
* Returns a shutdown function that flushes pending spans.
|
|
12
|
+
*/
|
|
13
|
+
export declare function initTelemetry(): Promise<() => Promise<void>>;
|
|
14
|
+
/** Flush and shut down the OTel provider (if active). */
|
|
15
|
+
export declare function shutdownTelemetry(): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=telemetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;GAGG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAqDlE;AAED,yDAAyD;AACzD,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAIvD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional OpenTelemetry initialization for the MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Activates only when OTEL_EXPORTER_OTLP_ENDPOINT is set in the environment.
|
|
5
|
+
* Exports traces via OTLP/HTTP to the configured collector (e.g. https://otel.oka.so).
|
|
6
|
+
*
|
|
7
|
+
* Zero cost when disabled — returns a no-op shutdown function.
|
|
8
|
+
*/
|
|
9
|
+
let shutdownFn;
|
|
10
|
+
/**
|
|
11
|
+
* Initialize OTel tracing if OTEL_EXPORTER_OTLP_ENDPOINT is set.
|
|
12
|
+
* Returns a shutdown function that flushes pending spans.
|
|
13
|
+
*/
|
|
14
|
+
export async function initTelemetry() {
|
|
15
|
+
const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
16
|
+
if (!endpoint) {
|
|
17
|
+
return async () => { };
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const { NodeTracerProvider } = await import("@opentelemetry/sdk-trace-node");
|
|
21
|
+
const { BatchSpanProcessor } = await import("@opentelemetry/sdk-trace-base");
|
|
22
|
+
const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-http");
|
|
23
|
+
const { Resource } = await import("@opentelemetry/resources");
|
|
24
|
+
const { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } = await import("@opentelemetry/semantic-conventions");
|
|
25
|
+
const { createRequire } = await import("node:module");
|
|
26
|
+
const require = createRequire(import.meta.url);
|
|
27
|
+
const { version } = require("../package.json");
|
|
28
|
+
const resource = new Resource({
|
|
29
|
+
[ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME ?? "oka-reason-mcp",
|
|
30
|
+
[ATTR_SERVICE_VERSION]: version,
|
|
31
|
+
"service.namespace": "agentic",
|
|
32
|
+
});
|
|
33
|
+
const exporter = new OTLPTraceExporter({
|
|
34
|
+
url: `${endpoint.replace(/\/$/, "")}/v1/traces`,
|
|
35
|
+
headers: process.env.OTEL_EXPORTER_OTLP_HEADERS
|
|
36
|
+
? Object.fromEntries(process.env.OTEL_EXPORTER_OTLP_HEADERS.split(",").map((h) => {
|
|
37
|
+
const [k = "", ...v] = h.split("=");
|
|
38
|
+
return [k.trim(), v.join("=").trim()];
|
|
39
|
+
}))
|
|
40
|
+
: undefined,
|
|
41
|
+
});
|
|
42
|
+
const provider = new NodeTracerProvider({ resource });
|
|
43
|
+
provider.addSpanProcessor(new BatchSpanProcessor(exporter));
|
|
44
|
+
provider.register();
|
|
45
|
+
shutdownFn = async () => {
|
|
46
|
+
await provider.forceFlush();
|
|
47
|
+
await provider.shutdown();
|
|
48
|
+
};
|
|
49
|
+
return shutdownFn;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// OTel deps not installed — degrade gracefully
|
|
53
|
+
return async () => { };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Flush and shut down the OTel provider (if active). */
|
|
57
|
+
export async function shutdownTelemetry() {
|
|
58
|
+
if (shutdownFn) {
|
|
59
|
+
await shutdownFn();
|
|
60
|
+
}
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oka-core/reason",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.17",
|
|
4
4
|
"description": "MCP server for institutional knowledge capture, semantic search, and consolidation",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -58,6 +58,13 @@
|
|
|
58
58
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
59
59
|
"zod": "^3.23.0"
|
|
60
60
|
},
|
|
61
|
+
"optionalDependencies": {
|
|
62
|
+
"@opentelemetry/sdk-trace-node": "^1.25.0",
|
|
63
|
+
"@opentelemetry/sdk-trace-base": "^1.25.0",
|
|
64
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.52.0",
|
|
65
|
+
"@opentelemetry/resources": "^1.25.0",
|
|
66
|
+
"@opentelemetry/semantic-conventions": "^1.25.0"
|
|
67
|
+
},
|
|
61
68
|
"devDependencies": {
|
|
62
69
|
"typescript": "^5.5.0",
|
|
63
70
|
"vitest": "^2.0.0",
|