
























@@ -1496,38 +1496,18 @@ describe("diagnostics-otel service", () => {
14961496});
14971497await flushDiagnosticEvents();
149814981499-const modelCall = telemetryState.tracer.startSpan.mock.calls.find(
1500-(call) => call[0] === "openclaw.model.call",
1501-);
1502-expect(modelCall?.[1]).toMatchObject({
1503-attributes: {
1504-"gen_ai.provider.name": "openai",
1505-"gen_ai.request.model": "gpt-5.4",
1506-"gen_ai.operation.name": "text_completion",
1507-},
1508-});
1509-expect(modelCall?.[1]).toEqual({
1510-attributes: expect.not.objectContaining({
1511-"gen_ai.system": expect.anything(),
1512-}),
1513-startTime: expect.any(Number),
1514-});
1515-const modelUsage = telemetryState.tracer.startSpan.mock.calls.find(
1516-(call) => call[0] === "openclaw.model.usage",
1517-);
1518-expect(modelUsage?.[1]).toMatchObject({
1519-attributes: {
1520-"gen_ai.provider.name": "openai",
1521-"gen_ai.request.model": "gpt-5.4",
1522-"gen_ai.operation.name": "chat",
1523-},
1524-});
1525-expect(modelUsage?.[1]).toEqual({
1526-attributes: expect.not.objectContaining({
1527-"gen_ai.system": expect.anything(),
1528-}),
1529-startTime: expect.any(Number),
1530-});
1499+const modelCallOptions = startedSpanOptions("openclaw.model.call");
1500+expect(modelCallOptions?.attributes?.["gen_ai.provider.name"]).toBe("openai");
1501+expect(modelCallOptions?.attributes?.["gen_ai.request.model"]).toBe("gpt-5.4");
1502+expect(modelCallOptions?.attributes?.["gen_ai.operation.name"]).toBe("text_completion");
1503+expect(Object.hasOwn(modelCallOptions?.attributes ?? {}, "gen_ai.system")).toBe(false);
1504+expect(modelCallOptions?.startTime).toBeTypeOf("number");
1505+const modelUsageOptions = startedSpanOptions("openclaw.model.usage");
1506+expect(modelUsageOptions?.attributes?.["gen_ai.provider.name"]).toBe("openai");
1507+expect(modelUsageOptions?.attributes?.["gen_ai.request.model"]).toBe("gpt-5.4");
1508+expect(modelUsageOptions?.attributes?.["gen_ai.operation.name"]).toBe("chat");
1509+expect(Object.hasOwn(modelUsageOptions?.attributes ?? {}, "gen_ai.system")).toBe(false);
1510+expect(modelUsageOptions?.startTime).toBeTypeOf("number");
15311511await service.stop?.(ctx);
15321512});
15331513@@ -1550,40 +1530,21 @@ describe("diagnostics-otel service", () => {
15501530});
15511531await flushDiagnosticEvents();
155215321553-const modelCall = telemetryState.tracer.startSpan.mock.calls.find(
1554-(call) => call[0] === "openclaw.model.call",
1555-);
1556-expect(modelCall?.[1]).toEqual({
1557-attributes: expect.objectContaining({
1558-"openclaw.failureKind": "terminated",
1559-}),
1560-startTime: expect.any(Number),
1561-});
1562-expect(modelCall?.[1]).toEqual({
1563-attributes: expect.not.objectContaining({
1564-"openclaw.upstreamRequestIdHash": expect.anything(),
1565-}),
1566-startTime: expect.any(Number),
1567-});
1533+const modelCallOptions = startedSpanOptions("openclaw.model.call");
1534+expect(modelCallOptions?.attributes?.["openclaw.failureKind"]).toBe("terminated");
1535+expect(
1536+Object.hasOwn(modelCallOptions?.attributes ?? {}, "openclaw.upstreamRequestIdHash"),
1537+).toBe(false);
1538+expect(modelCallOptions?.startTime).toBeTypeOf("number");
15681539const span = telemetryState.spans.find((candidate) => candidate.name === "openclaw.model.call");
15691540expect(span?.addEvent).toHaveBeenCalledWith("openclaw.provider.request", {
15701541"openclaw.upstreamRequestIdHash": "sha256:123456abcdef",
15711542});
1572-expect(
1573-telemetryState.histograms.get("openclaw.model_call.duration_ms")?.record,
1574-).toHaveBeenCalledWith(
1575-40,
1576-expect.objectContaining({
1577-"openclaw.failureKind": "terminated",
1578-}),
1579-);
1580-expect(
1581-telemetryState.histograms.get("openclaw.model_call.duration_ms")?.record,
1582-).toHaveBeenCalledWith(
1583-40,
1584-expect.not.objectContaining({
1585-"openclaw.upstreamRequestIdHash": expect.anything(),
1586-}),
1543+const modelCallDuration = lastHistogramRecord("openclaw.model_call.duration_ms");
1544+expect(modelCallDuration?.[0]).toBe(40);
1545+expect(modelCallDuration?.[1]?.["openclaw.failureKind"]).toBe("terminated");
1546+expect(Object.hasOwn(modelCallDuration?.[1] ?? {}, "openclaw.upstreamRequestIdHash")).toBe(
1547+false,
15871548);
15881549await service.stop?.(ctx);
15891550});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。