Skip to content

Commit 6773de3

Browse files
committed
fix(diagnostics): omit replay signatures from telemetry
1 parent f0a9420 commit 6773de3

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

‎extensions/diagnostics-otel/src/service-genai-content.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ const INTERNAL_REASONING_MESSAGE_FIELDS = [
148148
"reasoning_text",
149149
] as const;
150150

151+
const INTERNAL_REASONING_PART_FIELDS = [
152+
"textSignature",
153+
"thinkingSignature",
154+
"thoughtSignature",
155+
] as const;
156+
151157
function redactInternalReasoningParts(value: unknown): unknown {
152158
if (!Array.isArray(value)) {
153159
return value;
@@ -159,7 +165,16 @@ function redactInternalReasoningParts(value: unknown): unknown {
159165
) {
160166
return { type: "reasoning", redacted: true };
161167
}
162-
return part;
168+
if (!isRecord(part)) {
169+
return part;
170+
}
171+
const redacted = { ...part };
172+
// Replay signatures carry opaque provider reasoning state even when attached
173+
// to visible text or tool calls. Preserve the visible part, not replay state.
174+
for (const field of INTERNAL_REASONING_PART_FIELDS) {
175+
delete redacted[field];
176+
}
177+
return redacted;
163178
});
164179
}
165180

‎extensions/diagnostics-otel/src/service.test.ts‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4378,7 +4378,11 @@ describe("diagnostics-otel service", () => {
43784378
content: [
43794379
{ type: "thinking", thinking: "input-internal-canary" },
43804380
{ type: "reasoning", content: "input-part-internal-canary" },
4381-
{ type: "text", text: "visible input" },
4381+
{
4382+
type: "text",
4383+
text: "visible input",
4384+
textSignature: "input-text-signature-internal-canary",
4385+
},
43824386
],
43834387
},
43844388
],
@@ -4390,6 +4394,13 @@ describe("diagnostics-otel service", () => {
43904394
content: [
43914395
{ type: "redacted_thinking", data: "output-internal-canary" },
43924396
{ type: "text", text: "visible output" },
4397+
{
4398+
type: "toolCall",
4399+
id: "tool-1",
4400+
name: "lookup",
4401+
arguments: { query: "visible" },
4402+
thoughtSignature: "output-thought-signature-internal-canary",
4403+
},
43934404
],
43944405
},
43954406
],
@@ -4406,6 +4417,8 @@ describe("diagnostics-otel service", () => {
44064417
"output-internal-canary",
44074418
"output-message-internal-canary",
44084419
"output-text-internal-canary",
4420+
"input-text-signature-internal-canary",
4421+
"output-thought-signature-internal-canary",
44094422
];
44104423
for (const key of [
44114424
"gen_ai.input.messages",
@@ -4423,6 +4436,12 @@ describe("diagnostics-otel service", () => {
44234436
]);
44244437
expect(JSON.parse(stringAttribute(attrs, "gen_ai.output.messages"))[0]?.parts).toEqual([
44254438
{ type: "text", content: "visible output" },
4439+
{
4440+
type: "tool_call",
4441+
id: "tool-1",
4442+
name: "lookup",
4443+
arguments: { query: "visible" },
4444+
},
44264445
]);
44274446
expect(
44284447
JSON.parse(stringAttribute(attrs, "openclaw.content.input_messages"))[0]?.content[0],
@@ -4433,6 +4452,17 @@ describe("diagnostics-otel service", () => {
44334452
expect(
44344453
JSON.parse(stringAttribute(attrs, "openclaw.content.output_messages"))[0]?.content[0],
44354454
).toEqual({ type: "reasoning", redacted: true });
4455+
expect(
4456+
JSON.parse(stringAttribute(attrs, "openclaw.content.input_messages"))[0]?.content[2],
4457+
).toEqual({ type: "text", text: "visible input" });
4458+
expect(
4459+
JSON.parse(stringAttribute(attrs, "openclaw.content.output_messages"))[0]?.content[2],
4460+
).toEqual({
4461+
type: "toolCall",
4462+
id: "tool-1",
4463+
name: "lookup",
4464+
arguments: { query: "visible" },
4465+
});
44364466
});
44374467

44384468
test("emits semconv response text for tool response parts", async () => {

0 commit comments

Comments
 (0)