@neutrome/open-ai-router 0.5.3 → 0.5.4

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.3",
3
+ "version": "0.5.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
package/src/otlp.ts CHANGED
@@ -39,8 +39,9 @@ export async function exportOtlp(
39
39
  body: JSON.stringify(otlpPayload(env, signal, spans)),
40
40
  });
41
41
  if (!response.ok) {
42
+ const responseBody = (await response.text()).slice(0, 2_000);
42
43
  console.error(
43
- `[telemetry] OTLP ${signal} export rejected: ${response.status} ${response.statusText}`,
44
+ `[telemetry] OTLP ${signal} export rejected: ${response.status} ${response.statusText}${responseBody ? `: ${responseBody}` : ""}`,
44
45
  );
45
46
  }
46
47
  } catch (error) {
@@ -45,16 +45,34 @@ 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
+ expect(
49
+ JSON.parse(String(fetchMock.mock.calls[1]?.[1]?.body)),
50
+ ).toMatchObject({
51
+ resourceLogs: [
52
+ {
53
+ scopeLogs: [
54
+ {
55
+ logRecords: [
56
+ {
57
+ severityText: "ERROR",
58
+ body: { stringValue: "upstream unavailable" },
59
+ },
60
+ ],
61
+ },
62
+ ],
63
+ },
64
+ ],
65
+ });
49
66
  fetchMock.mockRestore();
50
67
  });
51
68
 
52
69
  it("logs a rejected exporter response without exposing credentials", async () => {
53
- const fetchMock = vi
54
- .spyOn(globalThis, "fetch")
55
- .mockResolvedValue(
56
- new Response(null, { status: 401, statusText: "Unauthorized" }),
57
- );
70
+ const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValue(
71
+ new Response("invalid authentication", {
72
+ status: 401,
73
+ statusText: "Unauthorized",
74
+ }),
75
+ );
58
76
  const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
59
77
  const telemetry = createRouterTelemetry({
60
78
  OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "https://traces.example/v1/traces",
@@ -69,7 +87,7 @@ describe("createRouterTelemetry", () => {
69
87
  await telemetry.flush();
70
88
 
71
89
  expect(errorSpy).toHaveBeenCalledWith(
72
- "[telemetry] OTLP traces export rejected: 401 Unauthorized",
90
+ "[telemetry] OTLP traces export rejected: 401 Unauthorized: invalid authentication",
73
91
  );
74
92
  fetchMock.mockRestore();
75
93
  errorSpy.mockRestore();