Skip to content

feat(sentry): add error monitoring for router, worker, and dashboard#502

Merged
zbigniewsobiecki merged 1 commit intodevfrom
feat/sentry-integration
Feb 23, 2026
Merged

feat(sentry): add error monitoring for router, worker, and dashboard#502
zbigniewsobiecki merged 1 commit intodevfrom
feat/sentry-integration

Conversation

@zbigniewsobiecki
Copy link
Copy Markdown
Member

Summary

  • Integrate @sentry/node v10 across all three container types (router, worker, dashboard) using Node's --import flag for early SDK initialization
  • Add src/instrument.ts (module preload) and src/sentry.ts (thin no-op wrappers that guard all calls behind SENTRY_DSN)
  • Wire Sentry captures into Hono error handlers, webhook processing, worker lifecycle, watchdog timeouts, queue errors, and retry exhaustion
  • Forward SENTRY_* env vars from router to spawned worker containers

Bug fixes found during code review

# Severity Issue Fix
1 High tracesSampleRate=0 silently became 0.1 (|| treats 0 as falsy) Use != null check on raw env var
2 High Watchdog process.exit(1) dropped queued Sentry events (no flush) Add await flush(3000) before exit
3 High Router webhook try/catch swallowed queue failures (Redis down → HTTP 200) Remove redundant try/catch, let errors propagate to app.onError → 500
4 Medium Server mode handleProcessingError had no Sentry capture Add captureException
5 Medium Dashboard container had no Sentry setup at all Add --import flag to Dockerfile + captures in error handler
6 Medium server.ts error handler had no Sentry capture Add captureException

Code quality

  • Extract dispatchJob() from worker-entry.ts main() to fix cognitive complexity lint warning (17 → well under 15)
  • Fix all import ordering and formatting issues flagged by biome

Files changed

New files: src/instrument.ts, src/sentry.ts, tests/unit/instrument.test.ts, tests/unit/sentry.test.ts

Modified (source): src/router/index.ts, src/router/worker-manager.ts, src/router/queue.ts, src/worker-entry.ts, src/agents/shared/lifecycle.ts, src/utils/lifecycle.ts, src/server.ts, src/server/webhookHandlers.ts, src/dashboard.ts, src/config/env.ts, src/config/retryConfig.ts, Dockerfile.dashboard, Dockerfile.router, Dockerfile.worker, CLAUDE.md

Modified (tests): tests/unit/utils/lifecycle.test.ts, tests/unit/server/webhookHandlers.test.ts

Test plan

  • npm run lint — zero errors
  • npm run typecheck — zero errors
  • npm test — 2730 tests pass (165 files), including 22 new Sentry-specific tests
  • CI passes (lint, typecheck, tests, Docker build validation)
  • Manual: set SENTRY_TRACES_SAMPLE_RATE=0, verify tracing is disabled (not overridden to 0.1)
  • Manual: deploy with SENTRY_DSN set, trigger a webhook error, verify event appears in Sentry

🤖 Generated with Claude Code

Integrate @sentry/node v10 across all three container types (router,
worker, dashboard) using Node's --import flag for early SDK initialization.

Core:
- Add src/instrument.ts (module preload) and src/sentry.ts (no-op wrappers)
- Wire Sentry captures into all Hono error handlers, webhook processing,
  worker lifecycle, watchdog timeouts, queue errors, and retry exhaustion
- Forward SENTRY_* env vars from router to spawned worker containers

Bug fixes found during review:
- Fix tracesSampleRate=0 silently becoming 0.1 (|| vs nullish check)
- Add Sentry flush before watchdog process.exit(1) to drain queued events
- Remove redundant try/catch in router webhook handlers that swallowed
  queue failures (Redis down → 200 instead of 500), restoring correct
  HTTP semantics for webhook provider retries
- Add Sentry capture to server mode's handleProcessingError (was log-only)

Code quality:
- Extract dispatchJob() from worker-entry main() to fix cognitive
  complexity lint warning (17 > 15)
- Fix all import ordering and formatting issues

Tests:
- Add tests/unit/sentry.test.ts — no-op behavior, context propagation
- Add tests/unit/instrument.test.ts — conditional init, tracesSampleRate=0
- Add Sentry flush assertion to lifecycle watchdog tests
- Add handleProcessingError Sentry capture test to webhookHandlers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zbigniewsobiecki zbigniewsobiecki merged commit 39a083f into dev Feb 23, 2026
5 checks passed
@zbigniewsobiecki zbigniewsobiecki deleted the feat/sentry-integration branch February 23, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant