fix: gate diagnostic logs behind verbose
This commit is contained in:
@@ -43,7 +43,7 @@ export function abortEmbeddedPiRun(sessionId: string): boolean {
|
|||||||
diag.debug(`abort failed: sessionId=${sessionId} reason=no_active_run`);
|
diag.debug(`abort failed: sessionId=${sessionId} reason=no_active_run`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
diag.info(`aborting run: sessionId=${sessionId}`);
|
diag.debug(`aborting run: sessionId=${sessionId}`);
|
||||||
handle.abort();
|
handle.abort();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ export function setActiveEmbeddedRun(sessionId: string, handle: EmbeddedPiQueueH
|
|||||||
reason: wasActive ? "run_replaced" : "run_started",
|
reason: wasActive ? "run_replaced" : "run_started",
|
||||||
});
|
});
|
||||||
if (!sessionId.startsWith("probe-")) {
|
if (!sessionId.startsWith("probe-")) {
|
||||||
diag.info(`run registered: sessionId=${sessionId} totalActive=${ACTIVE_EMBEDDED_RUNS.size}`);
|
diag.debug(`run registered: sessionId=${sessionId} totalActive=${ACTIVE_EMBEDDED_RUNS.size}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ export function clearActiveEmbeddedRun(sessionId: string, handle: EmbeddedPiQueu
|
|||||||
ACTIVE_EMBEDDED_RUNS.delete(sessionId);
|
ACTIVE_EMBEDDED_RUNS.delete(sessionId);
|
||||||
logSessionStateChange({ sessionId, state: "idle", reason: "run_completed" });
|
logSessionStateChange({ sessionId, state: "idle", reason: "run_completed" });
|
||||||
if (!sessionId.startsWith("probe-")) {
|
if (!sessionId.startsWith("probe-")) {
|
||||||
diag.info(`run cleared: sessionId=${sessionId} totalActive=${ACTIVE_EMBEDDED_RUNS.size}`);
|
diag.debug(`run cleared: sessionId=${sessionId} totalActive=${ACTIVE_EMBEDDED_RUNS.size}`);
|
||||||
}
|
}
|
||||||
notifyEmbeddedRunEnded(sessionId);
|
notifyEmbeddedRunEnded(sessionId);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export function logWebhookReceived(params: {
|
|||||||
}) {
|
}) {
|
||||||
webhookStats.received += 1;
|
webhookStats.received += 1;
|
||||||
webhookStats.lastReceived = Date.now();
|
webhookStats.lastReceived = Date.now();
|
||||||
diag.info(
|
diag.debug(
|
||||||
`webhook received: channel=${params.channel} type=${params.updateType ?? "unknown"} chatId=${
|
`webhook received: channel=${params.channel} type=${params.updateType ?? "unknown"} chatId=${
|
||||||
params.chatId ?? "unknown"
|
params.chatId ?? "unknown"
|
||||||
} total=${webhookStats.received}`,
|
} total=${webhookStats.received}`,
|
||||||
@@ -84,7 +84,7 @@ export function logWebhookProcessed(params: {
|
|||||||
durationMs?: number;
|
durationMs?: number;
|
||||||
}) {
|
}) {
|
||||||
webhookStats.processed += 1;
|
webhookStats.processed += 1;
|
||||||
diag.info(
|
diag.debug(
|
||||||
`webhook processed: channel=${params.channel} type=${
|
`webhook processed: channel=${params.channel} type=${
|
||||||
params.updateType ?? "unknown"
|
params.updateType ?? "unknown"
|
||||||
} chatId=${params.chatId ?? "unknown"} duration=${params.durationMs ?? 0}ms processed=${
|
} chatId=${params.chatId ?? "unknown"} duration=${params.durationMs ?? 0}ms processed=${
|
||||||
@@ -132,7 +132,7 @@ 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.info(
|
diag.debug(
|
||||||
`message queued: sessionId=${state.sessionId ?? "unknown"} sessionKey=${
|
`message queued: sessionId=${state.sessionId ?? "unknown"} sessionKey=${
|
||||||
state.sessionKey ?? "unknown"
|
state.sessionKey ?? "unknown"
|
||||||
} source=${params.source} queueDepth=${state.queueDepth} sessionState=${state.state}`,
|
} source=${params.source} queueDepth=${state.queueDepth} sessionState=${state.state}`,
|
||||||
@@ -173,7 +173,7 @@ export function logMessageProcessed(params: {
|
|||||||
} else if (params.outcome === "skipped") {
|
} else if (params.outcome === "skipped") {
|
||||||
diag.debug(payload);
|
diag.debug(payload);
|
||||||
} else {
|
} else {
|
||||||
diag.info(payload);
|
diag.debug(payload);
|
||||||
}
|
}
|
||||||
emitDiagnosticEvent({
|
emitDiagnosticEvent({
|
||||||
type: "message.processed",
|
type: "message.processed",
|
||||||
@@ -203,7 +203,7 @@ export function logSessionStateChange(
|
|||||||
state.lastActivity = Date.now();
|
state.lastActivity = Date.now();
|
||||||
if (params.state === "idle") state.queueDepth = Math.max(0, state.queueDepth - 1);
|
if (params.state === "idle") state.queueDepth = Math.max(0, state.queueDepth - 1);
|
||||||
if (!isProbeSession) {
|
if (!isProbeSession) {
|
||||||
diag.info(
|
diag.debug(
|
||||||
`session state: sessionId=${state.sessionId ?? "unknown"} sessionKey=${
|
`session state: sessionId=${state.sessionId ?? "unknown"} sessionKey=${
|
||||||
state.sessionKey ?? "unknown"
|
state.sessionKey ?? "unknown"
|
||||||
} prev=${prevState} new=${params.state} reason="${params.reason ?? ""}" queueDepth=${
|
} prev=${prevState} new=${params.state} reason="${params.reason ?? ""}" queueDepth=${
|
||||||
@@ -263,7 +263,7 @@ export function logLaneDequeue(lane: string, waitMs: number, queueSize: number)
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function logRunAttempt(params: SessionRef & { runId: string; attempt: number }) {
|
export function logRunAttempt(params: SessionRef & { runId: string; attempt: number }) {
|
||||||
diag.info(
|
diag.debug(
|
||||||
`run attempt: sessionId=${params.sessionId ?? "unknown"} sessionKey=${
|
`run attempt: sessionId=${params.sessionId ?? "unknown"} sessionKey=${
|
||||||
params.sessionKey ?? "unknown"
|
params.sessionKey ?? "unknown"
|
||||||
} runId=${params.runId} attempt=${params.attempt}`,
|
} runId=${params.runId} attempt=${params.attempt}`,
|
||||||
@@ -285,7 +285,7 @@ export function logActiveRuns() {
|
|||||||
([id, s]) =>
|
([id, s]) =>
|
||||||
`${id}(q=${s.queueDepth},age=${Math.round((Date.now() - s.lastActivity) / 1000)}s)`,
|
`${id}(q=${s.queueDepth},age=${Math.round((Date.now() - s.lastActivity) / 1000)}s)`,
|
||||||
);
|
);
|
||||||
diag.info(`active runs: count=${activeSessions.length} sessions=[${activeSessions.join(", ")}]`);
|
diag.debug(`active runs: count=${activeSessions.length} sessions=[${activeSessions.join(", ")}]`);
|
||||||
markActivity();
|
markActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,7 +314,7 @@ export function startDiagnosticHeartbeat() {
|
|||||||
if (!hasActivity) return;
|
if (!hasActivity) return;
|
||||||
if (now - lastActivityAt > 120_000 && activeCount === 0 && waitingCount === 0) return;
|
if (now - lastActivityAt > 120_000 && activeCount === 0 && waitingCount === 0) return;
|
||||||
|
|
||||||
diag.info(
|
diag.debug(
|
||||||
`heartbeat: webhooks=${webhookStats.received}/${webhookStats.processed}/${webhookStats.errors} active=${activeCount} waiting=${waitingCount} queued=${totalQueued}`,
|
`heartbeat: webhooks=${webhookStats.received}/${webhookStats.processed}/${webhookStats.errors} active=${activeCount} waiting=${waitingCount} queued=${totalQueued}`,
|
||||||
);
|
);
|
||||||
emitDiagnosticEvent({
|
emitDiagnosticEvent({
|
||||||
|
|||||||
Reference in New Issue
Block a user