Repository navigation
feat(server): add sentry error and performance monitoring - #11
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe server adds Sentry runtime integrations, middleware, structured error logs, a debug endpoint, and instrumentation for session route events. ChangesServer observability
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
packages/server/src/index.ts (2)
12-12: 🚀 Performance & Scalability | 🔵 TrivialMake trace sampling production-safe.
tracesSampleRate: 1.0records every request for all deployments because the Sentry middleware has no environment branch. Use a lower production default, such as0.01, and keep1.0only behind an explicit diagnostics flag.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/server/src/index.ts` at line 12, Update the Sentry configuration around tracesSampleRate so production uses a lower default such as 0.01 instead of 1.0. Preserve 1.0 only when an explicit diagnostics flag is enabled, and ensure the environment branching applies consistently to all deployments.
11-11: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winUse an environment-specific Sentry DSN.
The server always initialises Sentry with the same DSN, so local or test environments send data to the production project if left enabled. Read
SENTRY_DSNfrom deployment configuration and skip Sentry setup when the DSN is absent.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/server/src/index.ts` at line 11, Update the Sentry initialization in the server entrypoint to read the DSN from the SENTRY_DSN environment configuration instead of using a hardcoded production value, and skip setup entirely when SENTRY_DSN is absent. Preserve the existing initialization behavior when a DSN is provided.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/server/package.json`:
- Around line 15-16: Synchronize the Sentry SDK versions in the package
dependencies by pinning both `@sentry/bun` and `@sentry/hono` to exactly 10.69.0, or
add an equivalent workspace override if the package must remain on that version.
In `@packages/server/src/index.ts`:
- Around line 17-24: Protect the /debug-sentry route registration in the server
bootstrap by requiring an explicit enable flag and the existing internal
authentication or network policy, or exclude the route from production entirely.
Ensure unauthorised callers cannot execute the logger.info, metrics.count, or
deliberate error throw inside the handler.
- Line 13: Configure the Sentry logging setup in packages/server/src/index.ts at
lines 13-13 with an approved environment-controlled beforeSendLog
allowlist/redaction policy before enabling logs. In
packages/server/src/routes/session.ts lines 64-67, remove the fabricated userId
and log only a short pseudonymous correlation ID; in lines 97-100, exclude the
user-controlled title and emit only approved safe identifiers or metadata.
- Around line 44-48: Change the unhandled server failure log in the surrounding
error handler from logger.warn to logger.error, preserving the existing safe
metadata payload of message, path, and method. Do not add Sentry-specific log
data because the Hono middleware already captures context.error.
---
Nitpick comments:
In `@packages/server/src/index.ts`:
- Line 12: Update the Sentry configuration around tracesSampleRate so production
uses a lower default such as 0.01 instead of 1.0. Preserve 1.0 only when an
explicit diagnostics flag is enabled, and ensure the environment branching
applies consistently to all deployments.
- Line 11: Update the Sentry initialization in the server entrypoint to read the
DSN from the SENTRY_DSN environment configuration instead of using a hardcoded
production value, and skip setup entirely when SENTRY_DSN is absent. Preserve
the existing initialization behavior when a DSN is provided.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e6e4e6fb-7045-447c-9819-2d83a17e2fdd
📒 Files selected for processing (3)
packages/server/package.jsonpackages/server/src/index.tspackages/server/src/routes/session.ts
New Features
Bug Fixes