fix(models): enrich local transport failure diagnostics

This commit is contained in:
Peter Steinberger
2026-04-27 09:25:33 +01:00
parent c2d82b87ee
commit a95da5b52d
13 changed files with 203 additions and 2 deletions

View File

@@ -1525,6 +1525,7 @@ describe("diagnostics-otel service", () => {
api: "openai-responses",
durationMs: 40,
errorCategory: "ProviderError",
failureKind: "terminated",
upstreamRequestIdHash: "sha256:123456abcdef",
});
await flushDiagnosticEvents();
@@ -1532,6 +1533,12 @@ describe("diagnostics-otel service", () => {
const modelCall = telemetryState.tracer.startSpan.mock.calls.find(
(call) => call[0] === "openclaw.model.call",
);
expect(modelCall?.[1]).toEqual({
attributes: expect.objectContaining({
"openclaw.failureKind": "terminated",
}),
startTime: expect.any(Number),
});
expect(modelCall?.[1]).toEqual({
attributes: expect.not.objectContaining({
"openclaw.upstreamRequestIdHash": expect.anything(),
@@ -1542,6 +1549,14 @@ describe("diagnostics-otel service", () => {
expect(span?.addEvent).toHaveBeenCalledWith("openclaw.provider.request", {
"openclaw.upstreamRequestIdHash": "sha256:123456abcdef",
});
expect(
telemetryState.histograms.get("openclaw.model_call.duration_ms")?.record,
).toHaveBeenCalledWith(
40,
expect.objectContaining({
"openclaw.failureKind": "terminated",
}),
);
expect(
telemetryState.histograms.get("openclaw.model_call.duration_ms")?.record,
).toHaveBeenCalledWith(

View File

@@ -1834,6 +1834,9 @@ export function createDiagnosticsOtelService(): OpenClawPluginService {
const metricAttrs = {
...modelCallMetricAttrs(evt),
"openclaw.errorCategory": errorType,
...(evt.failureKind
? { "openclaw.failureKind": lowCardinalityAttr(evt.failureKind, "other") }
: {}),
};
modelCallDurationHistogram.record(evt.durationMs, metricAttrs);
recordModelCallSizeTimingMetrics(evt, metricAttrs);
@@ -1850,6 +1853,9 @@ export function createDiagnosticsOtelService(): OpenClawPluginService {
"openclaw.errorCategory": errorType,
"error.type": errorType,
};
if (evt.failureKind) {
spanAttrs["openclaw.failureKind"] = lowCardinalityAttr(evt.failureKind, "other");
}
assignGenAiModelCallAttrs(spanAttrs, evt);
if (evt.api) {
spanAttrs["openclaw.api"] = evt.api;