























@@ -989,6 +989,67 @@ describe("diagnostics-otel service", () => {
989989await service.stop?.(ctx);
990990});
991991992+test("exports trusted context assembly spans without prompt content", async () => {
993+const service = createDiagnosticsOtelService();
994+const ctx = createOtelContext(OTEL_TEST_ENDPOINT, { traces: true, metrics: true });
995+await service.start(ctx);
996+997+emitTrustedDiagnosticEvent({
998+type: "context.assembled",
999+runId: "run-1",
1000+sessionKey: "session-key",
1001+sessionId: "session-id",
1002+provider: "openai",
1003+model: "gpt-5.4",
1004+channel: "webchat",
1005+trigger: "message",
1006+messageCount: 12,
1007+historyTextChars: 1234,
1008+historyImageBlocks: 2,
1009+maxMessageTextChars: 456,
1010+systemPromptChars: 789,
1011+promptChars: 42,
1012+promptImages: 1,
1013+contextTokenBudget: 128_000,
1014+reserveTokens: 4096,
1015+trace: {
1016+traceId: TRACE_ID,
1017+spanId: GRANDCHILD_SPAN_ID,
1018+parentSpanId: SPAN_ID,
1019+traceFlags: "01",
1020+},
1021+});
1022+await flushDiagnosticEvents();
1023+1024+const contextCall = telemetryState.tracer.startSpan.mock.calls.find(
1025+(call) => call[0] === "openclaw.context.assembled",
1026+);
1027+expect(contextCall?.[1]).toMatchObject({
1028+attributes: {
1029+"openclaw.provider": "openai",
1030+"openclaw.model": "gpt-5.4",
1031+"openclaw.channel": "webchat",
1032+"openclaw.trigger": "message",
1033+"openclaw.context.message_count": 12,
1034+"openclaw.context.history_text_chars": 1234,
1035+"openclaw.context.history_image_blocks": 2,
1036+"openclaw.context.max_message_text_chars": 456,
1037+"openclaw.context.system_prompt_chars": 789,
1038+"openclaw.context.prompt_chars": 42,
1039+"openclaw.context.prompt_images": 1,
1040+"openclaw.context.token_budget": 128_000,
1041+"openclaw.context.reserve_tokens": 4096,
1042+},
1043+});
1044+expect(JSON.stringify(contextCall)).not.toContain("session-key");
1045+expect(JSON.stringify(contextCall)).not.toContain("prompt text");
1046+expect(telemetryState.tracer.setSpanContext).toHaveBeenCalledWith(
1047+expect.anything(),
1048+expect.objectContaining({ traceId: TRACE_ID, spanId: SPAN_ID }),
1049+);
1050+await service.stop?.(ctx);
1051+});
1052+9921053test("parents trusted diagnostic lifecycle spans from explicit parent ids", async () => {
9931054const service = createDiagnosticsOtelService();
9941055const ctx = createOtelContext(OTEL_TEST_ENDPOINT, { traces: true, metrics: true });
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。