feat(logger): serialize and log error cause chains in CloudflareLogger and ErrorHandler - #62
Conversation
…r and ErrorHandler
There was a problem hiding this comment.
📋 Review Summary
This pull request introduces error cause chain formatting and serialization across CloudflareLogger and ErrorHandler, ensuring nested causes are included in log messages and webhook alerts. While the logging changes in logger.js are well-tested, errors.js contains a critical regression where dataStr was left undeclared, resulting in a runtime ReferenceError during webhook dispatch.
🔍 General Feedback
- Good test coverage was added in
test/logger.test.jscovering both single-level and multi-level cause chain logging. - Consider adding unit tests for
ErrorHandler(e.g. in a newtest/errors.test.js) to verify webhook payload formatting and duplicate suppression logic so regressions like missing variables are caught by CI.
📊 Token Usage & Cost Efficiency
| Metric | Value |
|---|---|
| Input Tokens (uncached) | 7,536 |
| Input Tokens (cached) | 38,168 (⚡ 83.5% cached) |
| Output Tokens | 706 |
| Total Session Tokens | 54,297 |
| Cost (uncached input) | $0.0057 |
| Cost (cached input) | $0.0029 |
| Cost (output) | $0.0026 |
| Estimated Total Cost | $0.0112 |
Gemini 3.8 Flash: introductory rate $0.75/$3.75 per 1M applied; reverts to $1.5/$7.5 after 2026-12-31.
Gemini 3.8 Flash: standard tier; batch and flex are half again, priority is higher.
Cache reads are priced here, but context-cache STORAGE, where the model charges for it separately per token-hour, is not included, so the figure can run slightly low.
What
CloudflareLoggerandErrorHandler.serializeError(err)helper to ensure non-enumerableErrorproperties (message,stack,status, and nestedcause) are converted into JSON-serializable objects rather than serializing to{}.(caused by: <cause chain>)todata.messageso that root causes appear directly in single-line Cloudflare log views.ErrorHandlerwebhook alert messages (Google Chat / Slack).Testing
npm testpasses (14/14 test files, 28/28 tests passed).