feat: error alerting + configurable log level (#93 & #94) - #168
Open
gabrielujelistic-collab wants to merge 1 commit into
Conversation
- Wire Sentry into HttpExceptionFilter's generic-Error branch (issue stellar-vortex-protocol#93) Only unhandled exceptions trigger an alert; expected HttpExceptions (404, 400, etc.) are silently ignored to prevent alert fatigue. src/common/sentry.ts — initSentry() + captureException() helpers src/main.ts — call initSentry() at application boot src/common/http-exception.filter.ts — call captureException in 500 branch - Make log level configurable via LOG_LEVEL env var (issue stellar-vortex-protocol#94) src/common/logger.ts — resolveLogLevel() reads LOG_LEVEL, falls back to 'info' in prod / 'debug' elsewhere src/config/env.validation.ts — LOG_LEVEL + SENTRY_DSN Joi entries - Tests src/common/http-exception.filter.spec.ts — verify captureException called only on generic errors, not on HttpExceptions (7 cases) src/common/logger.spec.ts — verify resolveLogLevel() priority and NODE_ENV heuristic (7 cases) - Dependencies @sentry/node@8.54.0 added to production dependencies Closes stellar-vortex-protocol#93 Closes stellar-vortex-protocol#94
|
@gabrielujelistic-collab Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: error alerting + configurable log level
Summary
This PR addresses two observability gaps in the vortex-backend service:
Changes
Issue #93 — Error alerting via Sentry (
HttpExceptionFilter500 branch)Problem:
HttpExceptionFilter.catch()logged unexpected errors withlogger.error()but nothing actually paged anyone. A recurring 500 could go unnoticed indefinitely.Solution: Wire
@sentry/nodeinto the generic-Errorcatch branch — and only that branch — so alert fatigue on routine404/400HttpExceptions is avoided.New file:
src/common/sentry.tsinitSentry()is a no-op whenSENTRY_DSNis absent — no environment changes are required for local development or CI.captureException()delegates to the Sentry SDK which internally guards against uninitialised state.Modified:
src/common/http-exception.filter.tsModified:
src/main.tsinitSentry()is called beforeNestFactory.create()so that any startup crash is also captured.New env var:
SENTRY_DSNSENTRY_DSN""(disabled)Issue #94 — Configurable log level via
LOG_LEVELProblem:
src/common/logger.tscreated a Winston logger with a hardcoded level. There was no way to:debug/verbose) against a production issue.Solution: Export a
resolveLogLevel()helper that applies the following priority:LOG_LEVELenv var (explicit override, works in any environment)"info"in production,"debug"everywhere elseModified:
src/common/logger.tsModified:
src/config/env.validation.tsFollows the existing Joi validation pattern. The schema default acts as a documentation hint and validation guard;
resolveLogLevel()handles the runtime NODE_ENV heuristic.New env var:
LOG_LEVELLOG_LEVELdebuginfoerror|warn|info|http|verbose|debug|sillyTest output
Unit tests (32 passed)
New test cases added for each issue:
http-exception.filter.spec.ts(issue #93)does NOT call captureException for expected HttpExceptions (no alert fatigue)calls captureException with the Error instance (Sentry alerting)wraps non-Error throws and still calls captureExceptionreturns 500 with fallback message for unknown throwslogger.spec.ts(issue #94)returns LOG_LEVEL when explicitly set, regardless of NODE_ENVLOG_LEVEL override works in development toodefaults to 'info' in production when LOG_LEVEL is unsetdefaults to 'debug' in development when LOG_LEVEL is unsetdefaults to 'debug' in test environment when LOG_LEVEL is unsetaccepts 'verbose' as a valid LOG_LEVELaccepts 'silly' as a valid LOG_LEVELe2e tests (23 passed)
Lint & typecheck
Files changed
src/common/sentry.tssrc/common/http-exception.filter.tscaptureException()in the 500 branchsrc/common/logger.tsresolveLogLevel(); use it for the Winston levelsrc/config/env.validation.tsLOG_LEVELandSENTRY_DSNJoi entriessrc/main.tsinitSentry()before app bootstrap.env.exampleLOG_LEVELandSENTRY_DSNsrc/common/http-exception.filter.spec.tssrc/common/logger.spec.tsresolveLogLevel()package.json@sentry/node@8.54.0dependencypackage-lock.jsonHow to configure
Local development (Sentry disabled)
No changes needed.
SENTRY_DSNdefaults to empty and is a no-op.Enabling Sentry
# .env SENTRY_DSN=https://your-key@o0.ingest.sentry.io/your-project-idChanging log verbosity
Closes #93
Closes #94