@neutrome/open-ai-router 0.5.1 → 0.5.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neutrome/open-ai-router",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
@@ -8,8 +8,8 @@
8
8
  "dependencies": {
9
9
  "@modelcontextprotocol/sdk": "^1.29.0",
10
10
  "hono": "^4.12.18",
11
- "@neutrome/lilsdk-ts": "0.3.0",
12
- "@neutrome/lil-engine": "0.3.0"
11
+ "@neutrome/lil-engine": "0.3.1",
12
+ "@neutrome/lilsdk-ts": "0.3.1"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@types/node": "^25.9.3",
package/src/otlp.ts CHANGED
@@ -14,6 +14,12 @@ type OtlpAttribute = {
14
14
  key: string;
15
15
  value: { stringValue?: string; intValue?: string; boolValue?: boolean };
16
16
  };
17
+ type OtlpLogRecord = {
18
+ timeUnixNano: string;
19
+ severityText: "ERROR";
20
+ body: { stringValue: string };
21
+ attributes: OtlpAttribute[];
22
+ };
17
23
 
18
24
  export async function exportOtlp(
19
25
  env: Environment,
@@ -30,34 +36,62 @@ export async function exportOtlp(
30
36
  "content-type": "application/json",
31
37
  ...headersFor(env, signal),
32
38
  },
33
- body: JSON.stringify({
34
- resourceSpans: [
35
- {
36
- resource: {
37
- attributes: attributes({
38
- "service.name":
39
- stringEnv(env, "OTEL_SERVICE_NAME") ?? "neutrome-router",
40
- }),
41
- },
42
- scopeSpans: [
43
- { scope: { name: "@neutrome/open-ai-router" }, spans },
44
- ],
45
- },
46
- ],
47
- }),
39
+ body: JSON.stringify(otlpPayload(env, signal, spans)),
48
40
  });
49
41
  if (!response.ok) {
50
- console.error("[telemetry] OTLP export rejected", {
51
- signal,
52
- status: response.status,
53
- statusText: response.statusText,
54
- });
42
+ console.error(
43
+ `[telemetry] OTLP ${signal} export rejected: ${response.status} ${response.statusText}`,
44
+ );
55
45
  }
56
46
  } catch (error) {
57
47
  console.error("[telemetry] OTLP export failed", error);
58
48
  }
59
49
  }
60
50
 
51
+ function otlpPayload(
52
+ env: Environment,
53
+ signal: "traces" | "errors",
54
+ spans: OtlpSpan[],
55
+ ): Record<string, unknown> {
56
+ const resource = {
57
+ attributes: attributes({
58
+ "service.name": stringEnv(env, "OTEL_SERVICE_NAME") ?? "neutrome-router",
59
+ }),
60
+ };
61
+ if (signal === "traces") {
62
+ return {
63
+ resourceSpans: [
64
+ {
65
+ resource,
66
+ scopeSpans: [{ scope: { name: "@neutrome/open-ai-router" }, spans }],
67
+ },
68
+ ],
69
+ };
70
+ }
71
+ return {
72
+ resourceLogs: [
73
+ {
74
+ resource,
75
+ scopeLogs: [
76
+ {
77
+ scope: { name: "@neutrome/open-ai-router" },
78
+ logRecords: spans.map(errorLogRecord),
79
+ },
80
+ ],
81
+ },
82
+ ],
83
+ };
84
+ }
85
+
86
+ function errorLogRecord(span: OtlpSpan): OtlpLogRecord {
87
+ return {
88
+ timeUnixNano: span.endTimeUnixNano,
89
+ severityText: "ERROR",
90
+ body: { stringValue: span.status?.message ?? span.name },
91
+ attributes: span.attributes,
92
+ };
93
+ }
94
+
61
95
  export function rootOtlpSpan(input: {
62
96
  traceId: string;
63
97
  spanId: string;
@@ -45,6 +45,7 @@ describe("createRouterTelemetry", () => {
45
45
  expect(fetchMock.mock.calls[1]?.[1]?.headers).toMatchObject({
46
46
  authorization: "Bearer error-token",
47
47
  });
48
+ expect(fetchMock.mock.calls[1]?.[1]?.body).toContain("resourceLogs");
48
49
  fetchMock.mockRestore();
49
50
  });
50
51
 
@@ -67,11 +68,9 @@ describe("createRouterTelemetry", () => {
67
68
 
68
69
  await telemetry.flush();
69
70
 
70
- expect(errorSpy).toHaveBeenCalledWith("[telemetry] OTLP export rejected", {
71
- signal: "traces",
72
- status: 401,
73
- statusText: "Unauthorized",
74
- });
71
+ expect(errorSpy).toHaveBeenCalledWith(
72
+ "[telemetry] OTLP traces export rejected: 401 Unauthorized",
73
+ );
75
74
  fetchMock.mockRestore();
76
75
  errorSpy.mockRestore();
77
76
  });