fix(observability): pass err via { error } in initErrorRoutes for Winston dedup#3657
Conversation
…ston dedup logger.error(err.stack) passed a string → PostHogErrorTransport couldn't read posthogCaptured → 2 $exception events per uncaught express error. Fixes #3656. Adds unit test for info.error dedup path.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughExpress error middleware now logs errors as structured objects instead of string stacks, enabling the PostHog transport to read and honor deduplication flags, preventing duplicate exception events. ChangesError Deduplication in Express Error Middleware
Possibly related issues
🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3657 +/- ##
=======================================
Coverage 89.20% 89.20%
=======================================
Files 136 136
Lines 4668 4668
Branches 1451 1451
=======================================
Hits 4164 4164
Misses 392 392
Partials 112 112
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes PostHog Error Tracking deduplication for uncaught Express errors by ensuring Winston logs carry the original Error object (so the posthogCaptured flag can be read by the PostHog transport), and adds a unit test covering the { error: err } metadata dedup path.
Changes:
- Update Express error route logging to call
logger.error(..., { error: err })instead of loggingerr.stackas a plain string. - Add a unit test to ensure
PostHogErrorTransportskips capture wheninfo.error.posthogCaptured === true.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/services/express.js | Adjusts uncaught Express error logging to pass the Error object via Winston metadata for PostHog dedup. |
| lib/services/tests/logger.posthog.transport.unit.tests.js | Adds coverage for the dedup path when the Error is provided in info.error. |
| app.use((err, req, res, next) => { | ||
| if (!err) return next(); | ||
| logger.error(err.stack); | ||
| logger.error('Unhandled express error', { error: err }); | ||
| res.status(err.status || 500).send({ |
Summary
logger.error(err.stack)ininitErrorRoutespassed a string, soPostHogErrorTransportcouldn't readposthogCapturedon the Error → 2$exceptionevents per uncaught express error (validated prod 2026-05-11: 3 curl POSTs → 6 events)logger.error('Unhandled express error', { error: err })so transport readsinfo.error→ dedup path worksinfo.error.posthogCaptureddedup path (theinfo instanceof Errorpath was already tested)Files touched
lib/services/express.js— 1-line fix ininitErrorRouteslib/services/tests/logger.posthog.transport.unit.tests.js— +1 test (8 total, was 7)Test plan
npm run lint— cleannpm run test:unit— 1380 passed (1 new test added)npm run test:coverage— thresholds met (pre-existing$sortArrayperf test failure is unrelated to this change, fails on master too)Summary by CodeRabbit
Bug Fixes
Tests