Refactor telemetry aggregator regex for stricter error detection

- Update `scripts/agent/telemetry-aggregator.mjs` to use a stricter regex for parsing generic logs.
- Require brackets (e.g., `[ERROR]`, `[WARN]`) or trailing colons/word boundaries (e.g., `Error:`, `FAIL`) to match errors.
- Prevent false positives from status messages like "0 errors" or "0 failures".
- Support `[WARN]` as Medium severity.
- Ensure PII sanitization and `ENABLE_TELEMETRY` guardrails are preserved.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-01-30 06:33:52 +00:00
1 parent 73c705831b
commit 782ecf3cea
1 file changed
+9 -2
+9 -2
View File
@@ -147,19 +147,26 @@ function collectGenericLogs(filepath, sourceName) {
for (const line of lines) {
// Simple heuristic for generic logs: look for "Error:" or "Exception:"
// and capture following lines that look like stack traces (start with 'at ' or are indented)
// Also support bracketed log levels like [ERROR], [FAIL], [CRITICAL], [WARN]
const isErrorStart = /Error:|Exception:|FAIL|CRITICAL/.test(line);
const errorMatch = line.match(/(?:\[\s*(?:ERROR|FAIL|CRITICAL|EXCEPTION|WARN|WARNING)\s*\])|(?:\b(?:Error|Exception|Warning):)|(?:\b(?:FAIL|CRITICAL)\b)/i);
const isErrorStart = !!errorMatch;
const isStackLine = /^\s+at /.test(line) || /^\s+/.test(line); // Indented lines often follow errors
if (isErrorStart) {
if (currentError) {
errors.push(currentError);
}
let severity = 'High';
if (line.match(/CRITICAL/i)) severity = 'Critical';
else if (line.match(/WARN|WARNING/i)) severity = 'Medium';
currentError = {
source: sourceName,
title: sanitize(line.trim()),
details: [sanitize(line.trim())],
severity: 'High'
severity: severity
};
} else if (currentError && isStackLine) {
currentError.details.push(sanitize(line.trim()));