mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 19:14:58 +00:00
perf(logging): skip eager debug formatting in diagnostic
This commit is contained in:
@@ -27,7 +27,7 @@ describe("diagnostic session state pruning", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("caps tracked session states to a bounded max", () => {
|
it("caps tracked session states to a bounded max", () => {
|
||||||
for (let i = 0; i < 2105; i += 1) {
|
for (let i = 0; i < 2001; i += 1) {
|
||||||
logSessionStateChange({ sessionId: `session-${i}`, state: "idle" });
|
logSessionStateChange({ sessionId: `session-${i}`, state: "idle" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -104,11 +104,13 @@ export function logWebhookReceived(params: {
|
|||||||
}) {
|
}) {
|
||||||
webhookStats.received += 1;
|
webhookStats.received += 1;
|
||||||
webhookStats.lastReceived = Date.now();
|
webhookStats.lastReceived = Date.now();
|
||||||
diag.debug(
|
if (diag.isEnabled("debug")) {
|
||||||
`webhook received: channel=${params.channel} type=${params.updateType ?? "unknown"} chatId=${
|
diag.debug(
|
||||||
params.chatId ?? "unknown"
|
`webhook received: channel=${params.channel} type=${params.updateType ?? "unknown"} chatId=${
|
||||||
} total=${webhookStats.received}`,
|
params.chatId ?? "unknown"
|
||||||
);
|
} total=${webhookStats.received}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
emitDiagnosticEvent({
|
emitDiagnosticEvent({
|
||||||
type: "webhook.received",
|
type: "webhook.received",
|
||||||
channel: params.channel,
|
channel: params.channel,
|
||||||
@@ -125,13 +127,15 @@ export function logWebhookProcessed(params: {
|
|||||||
durationMs?: number;
|
durationMs?: number;
|
||||||
}) {
|
}) {
|
||||||
webhookStats.processed += 1;
|
webhookStats.processed += 1;
|
||||||
diag.debug(
|
if (diag.isEnabled("debug")) {
|
||||||
`webhook processed: channel=${params.channel} type=${
|
diag.debug(
|
||||||
params.updateType ?? "unknown"
|
`webhook processed: channel=${params.channel} type=${
|
||||||
} chatId=${params.chatId ?? "unknown"} duration=${params.durationMs ?? 0}ms processed=${
|
params.updateType ?? "unknown"
|
||||||
webhookStats.processed
|
} chatId=${params.chatId ?? "unknown"} duration=${params.durationMs ?? 0}ms processed=${
|
||||||
}`,
|
webhookStats.processed
|
||||||
);
|
}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
emitDiagnosticEvent({
|
emitDiagnosticEvent({
|
||||||
type: "webhook.processed",
|
type: "webhook.processed",
|
||||||
channel: params.channel,
|
channel: params.channel,
|
||||||
@@ -173,11 +177,13 @@ export function logMessageQueued(params: {
|
|||||||
const state = getSessionState(params);
|
const state = getSessionState(params);
|
||||||
state.queueDepth += 1;
|
state.queueDepth += 1;
|
||||||
state.lastActivity = Date.now();
|
state.lastActivity = Date.now();
|
||||||
diag.debug(
|
if (diag.isEnabled("debug")) {
|
||||||
`message queued: sessionId=${state.sessionId ?? "unknown"} sessionKey=${
|
diag.debug(
|
||||||
state.sessionKey ?? "unknown"
|
`message queued: sessionId=${state.sessionId ?? "unknown"} sessionKey=${
|
||||||
} source=${params.source} queueDepth=${state.queueDepth} sessionState=${state.state}`,
|
state.sessionKey ?? "unknown"
|
||||||
);
|
} source=${params.source} queueDepth=${state.queueDepth} sessionState=${state.state}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
emitDiagnosticEvent({
|
emitDiagnosticEvent({
|
||||||
type: "message.queued",
|
type: "message.queued",
|
||||||
sessionId: state.sessionId,
|
sessionId: state.sessionId,
|
||||||
@@ -200,21 +206,22 @@ export function logMessageProcessed(params: {
|
|||||||
reason?: string;
|
reason?: string;
|
||||||
error?: string;
|
error?: string;
|
||||||
}) {
|
}) {
|
||||||
const payload = `message processed: channel=${params.channel} chatId=${
|
const wantsLog = params.outcome === "error" ? diag.isEnabled("error") : diag.isEnabled("debug");
|
||||||
params.chatId ?? "unknown"
|
if (wantsLog) {
|
||||||
} messageId=${params.messageId ?? "unknown"} sessionId=${
|
const payload = `message processed: channel=${params.channel} chatId=${
|
||||||
params.sessionId ?? "unknown"
|
params.chatId ?? "unknown"
|
||||||
} sessionKey=${params.sessionKey ?? "unknown"} outcome=${params.outcome} duration=${
|
} messageId=${params.messageId ?? "unknown"} sessionId=${
|
||||||
params.durationMs ?? 0
|
params.sessionId ?? "unknown"
|
||||||
}ms${params.reason ? ` reason=${params.reason}` : ""}${
|
} sessionKey=${params.sessionKey ?? "unknown"} outcome=${params.outcome} duration=${
|
||||||
params.error ? ` error="${params.error}"` : ""
|
params.durationMs ?? 0
|
||||||
}`;
|
}ms${params.reason ? ` reason=${params.reason}` : ""}${
|
||||||
if (params.outcome === "error") {
|
params.error ? ` error="${params.error}"` : ""
|
||||||
diag.error(payload);
|
}`;
|
||||||
} else if (params.outcome === "skipped") {
|
if (params.outcome === "error") {
|
||||||
diag.debug(payload);
|
diag.error(payload);
|
||||||
} else {
|
} else {
|
||||||
diag.debug(payload);
|
diag.debug(payload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
emitDiagnosticEvent({
|
emitDiagnosticEvent({
|
||||||
type: "message.processed",
|
type: "message.processed",
|
||||||
@@ -245,7 +252,7 @@ export function logSessionStateChange(
|
|||||||
if (params.state === "idle") {
|
if (params.state === "idle") {
|
||||||
state.queueDepth = Math.max(0, state.queueDepth - 1);
|
state.queueDepth = Math.max(0, state.queueDepth - 1);
|
||||||
}
|
}
|
||||||
if (!isProbeSession) {
|
if (!isProbeSession && diag.isEnabled("debug")) {
|
||||||
diag.debug(
|
diag.debug(
|
||||||
`session state: sessionId=${state.sessionId ?? "unknown"} sessionKey=${
|
`session state: sessionId=${state.sessionId ?? "unknown"} sessionKey=${
|
||||||
state.sessionKey ?? "unknown"
|
state.sessionKey ?? "unknown"
|
||||||
|
|||||||
Reference in New Issue
Block a user