

























@@ -1,5 +1,8 @@
11import type { OpenClawConfig } from "../config/types.openclaw.js";
2-import type { DiagnosticTraceContext } from "./diagnostic-trace-context.js";
2+import {
3+formatDiagnosticTraceparent,
4+type DiagnosticTraceContext,
5+} from "./diagnostic-trace-context.js";
36import { isBlockedObjectKey } from "./prototype-keys.js";
4758export type DiagnosticSessionState = "idle" | "processing" | "waiting";
@@ -413,6 +416,7 @@ type DiagnosticEventsGlobalState = {
413416414417const MAX_ASYNC_DIAGNOSTIC_EVENTS = 10_000;
415418const DIAGNOSTIC_EVENTS_STATE_KEY = Symbol.for("openclaw.diagnosticEvents.state.v1");
419+const dispatchedTrustedDiagnosticMetadata = new WeakSet<object>();
416420const ASYNC_DIAGNOSTIC_EVENT_TYPES = new Set<DiagnosticEventPayload["type"]>([
417421"tool.execution.started",
418422"tool.execution.completed",
@@ -500,7 +504,10 @@ function dispatchDiagnosticEvent(
500504try {
501505for (const listener of state.listeners) {
502506try {
503-listener(cloneDiagnosticEventForListener(enriched), Object.freeze({ ...metadata }));
507+listener(
508+cloneDiagnosticEventForListener(enriched),
509+createDiagnosticMetadataForListener(metadata),
510+);
504511} catch (err) {
505512const errorMessage =
506513err instanceof Error
@@ -519,6 +526,16 @@ function dispatchDiagnosticEvent(
519526}
520527}
521528529+function createDiagnosticMetadataForListener(
530+metadata: DiagnosticEventMetadata,
531+): DiagnosticEventMetadata {
532+const listenerMetadata = Object.freeze({ ...metadata });
533+if (listenerMetadata.trusted) {
534+dispatchedTrustedDiagnosticMetadata.add(listenerMetadata);
535+}
536+return listenerMetadata;
537+}
538+522539function cloneDiagnosticEventForListener(event: DiagnosticEventPayload): DiagnosticEventPayload {
523540return deepFreezeDiagnosticValue(structuredClone(event)) as DiagnosticEventPayload;
524541}
@@ -623,6 +640,16 @@ export function onDiagnosticEvent(listener: (evt: DiagnosticEventPayload) => voi
623640});
624641}
625642643+export function formatDiagnosticTraceparentForPropagation(
644+event: { trace?: DiagnosticTraceContext },
645+metadata: DiagnosticEventMetadata,
646+): string | undefined {
647+if (!metadata.trusted || !dispatchedTrustedDiagnosticMetadata.has(metadata)) {
648+return undefined;
649+}
650+return formatDiagnosticTraceparent(event.trace);
651+}
652+626653export function resetDiagnosticEventsForTest(): void {
627654const state = getDiagnosticEventsState();
628655state.enabled = true;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。