Skip to content

fix(logger): forward error-level logs to Sentry#505

Open
TerrifiedBug wants to merge 1 commit into
mainfrom
review/errorlog-sentry
Open

fix(logger): forward error-level logs to Sentry#505
TerrifiedBug wants to merge 1 commit into
mainfrom
review/errorlog-sentry

Conversation

@TerrifiedBug

Copy link
Copy Markdown
Owner

Problem

errorLog wrote only to stderr. Every catch site that reports a failure through it — scheduler initialisation, leader election, backup/rollback failures, KMS warm-up, and ~hundreds of others — never reached Sentry. Error tracking showed green while background work silently failed, so real incidents went undetected.

Found during a code-quality review (see review/arch__core.md; top-scored quick-win in review/BACKLOG.md).

Change

errorLog now forwards to Sentry.captureException when an Error object is present — either passed directly as data, or wrapped under error / err / cause / exception. The event is tagged with the log tag and carries the original message.

  • No-op when Sentry has no active client (Sentry.getClient() is falsy): the test suite and self-host deployments without a configured DSN are completely unaffected — no behaviour change, no new console output.
  • Conservative by design: only forwards when there is a real Error (with a stack), so it does not flood Sentry with message-only logs.

Tests

src/lib/__tests__/logger-sentry.test.ts covers: direct-Error forward, nested-error extraction, the no-client no-op, the non-Error no-op, and tag CR/LF sanitisation.

  • vitest run logger suites: 28 passed
  • eslint on changed files: 0 errors

errorLog previously wrote only to stderr, so the many catch sites that
report failures through it (scheduler init, leader election, backup and
rollback failures, etc.) were invisible to Sentry — error tracking showed
green while background work silently failed.

errorLog now forwards to Sentry.captureException when an Error is present
(directly, or wrapped under error/err/cause/exception), tagged with the
log tag and carrying the message. It is a no-op when Sentry has no active
client, so the test suite and DSN-less self-host deployments are
unaffected.

Adds logger-sentry.test.ts covering the forward, nested-error extraction,
the no-client no-op, the non-Error no-op, and tag sanitisation.
@github-actions github-actions Bot added the fix label Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant