diff options
Diffstat (limited to 'api/debug/ingest.php')
| -rw-r--r-- | api/debug/ingest.php | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/api/debug/ingest.php b/api/debug/ingest.php index 7388bce..98354fe 100644 --- a/api/debug/ingest.php +++ b/api/debug/ingest.php @@ -80,6 +80,20 @@ function norm_ts($s, $fallback) { return gmdate('c', $t); // always +00:00, never Z } +// Where did it happen? Parsed ONCE here so the digest (Python) and the dashboard (PHP) read the +// same value instead of re-implementing this regex twice. Returns 'modules/core/x.js:12:3'. +function first_frame($stack) { + if (!is_string($stack) || $stack === '') return null; + foreach (preg_split('/\R/', $stack) as $i => $line) { + if ($i === 0 || !preg_match('/^\s+at /', $line)) continue; // line 0 is "TypeError: ..." + if (preg_match('#([\w./-]+\.js)(?:\?v=[\w.]+)?:(\d+):(\d+)#', $line, $m)) { + $p = preg_replace('#^.*?/spaces/newos4/#', '', $m[1]); + return $p . ':' . $m[2] . ':' . $m[3]; + } + } + return null; +} + $processed = 0; // entries handled (NOT occurrences) — the client's truncation warning uses this foreach ($errors as $e) { $processed++; @@ -103,6 +117,7 @@ foreach ($errors as $e) { $allErrors[$idx]['ingested_at'] = $now; if (!empty($e['stack'])) { $allErrors[$idx]['stack'] = substr($e['stack'], 0, 2000); + $allErrors[$idx]['frame'] = first_frame($e['stack']) ?? ($allErrors[$idx]['frame'] ?? null); } $ingested += $delta; } @@ -118,6 +133,7 @@ foreach ($errors as $e) { 'source' => $e['source'] ?? '', 'module' => $e['module'] ?? null, 'stack' => isset($e['stack']) ? substr($e['stack'], 0, 2000) : null, + 'frame' => first_frame($e['stack'] ?? null), 'session_id' => $sessionId, 'count' => $delta, 'first_seen' => norm_ts($e['firstSeen'] ?? null, $now), |