feat: integrate Sentry for error tracking and fix metrics DI startup …#55
Merged
Merged
Conversation
11 tasks
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.
Closes #12
I have completed the task successfully. Here is a summary of the work:
Sentry Initialization:
• Initialized Sentry via Sentry.init at the very top of main.ts, ensuring it runs before NestJS
bootstraps.
• Used process.env.SENTRY_TRACES_SAMPLE_RATE to support configuring the trace sample rate via environment
variables (falling back to 0.1 as requested).
• Configured process.env.SENTRY_DSN as an optional fallback ( process.env.SENTRY_DSN || undefined ) to
ensure the application starts up gracefully as a no-op fallback when SENTRY_DSN is empty.
NestJS Setup & Sentry Module:
• Registered SentryModule.forRoot() in the imports list in app.module.ts.
• Registered the SentryGlobalFilter globally as APP_FILTER under the providers array in app.module.ts,
enabling all unhandled controller exceptions to be caught and logged directly to Sentry.
Validation & Test Route:
• Added a sentry-test endpoint to the HealthController in health.controller.ts which throws a deliberate
error
( throw new Error('sentry test') ).
• Decorated the endpoint with full Swagger @apioperation and @apiresponse decorators to conform to our
standards, with no any types introduced.
• Tested the endpoint locally and confirmed that unhandled exceptions are caught by the Sentry filter and
logged.
Environment Template:
• Created the .env.example configuration template containing environment variable definitions, adding
SENTRY_DSN= and SENTRY_TRACES_SAMPLE_RATE=0.1 , alongside other project variables.
Fixed Pre-existing DI Bug:
• Resolved a pre-existing DI error in the codebase's prometheus metrics setup which had prevented the
application from starting:
• Updated metrics.service.ts to use @InjectMetric(...) instead of Nest's generic @Inject(...) to allow
@willsoto/nestjs-prometheus to correctly resolve the metric tokens.
• Decorated MetricsModule with @global() in metrics.module.ts so that the MetricsService provider is
globally accessible.
• Removed MetricsController from the duplicate declaration in the controllers array in
metrics.module.ts
to avoid duplicated route binding errors in Fastify.
Documentation & Progress tracking:
• Added a section "Error tracking" in README.md documenting how to enable and configure Sentry.
• Logged the work inside the progress-tracker.md file.
• Verified that npm run build compiles with zero compiler warnings or errors.