Skip to content

Add Sentry error monitoring#218

Merged
DominicBM merged 1 commit intomainfrom
fix/signin-password-contact-message
Mar 15, 2026
Merged

Add Sentry error monitoring#218
DominicBM merged 1 commit intomainfrom
fix/signin-password-contact-message

Conversation

@DominicBM
Copy link
Contributor

@DominicBM DominicBM commented Mar 15, 2026

Summary

  • Adds sentry-ruby and sentry-rails gems
  • Initializer reads SENTRY_DSN and SENTRY_ENVIRONMENT from env vars (no-op when unset)
  • ECS task definition analytics-dashboard:93 has been updated with SENTRY_DSN pointing to the dpla-frontend Sentry project and SENTRY_ENVIRONMENT=analytics-dashboard
  • Errors from this app will appear in Sentry under environment analytics-dashboard, distinct from the frontend sites

Test plan

  • Deploy via pipeline after merge
  • Verify errors appear in Sentry (https://dpla.sentry.io) under environment analytics-dashboard

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Integrated error tracking and monitoring capabilities to enhance application stability and debugging.

Adds sentry-ruby and sentry-rails gems with an initializer that reads
SENTRY_DSN and SENTRY_ENVIRONMENT from env vars. The ECS task definition
has been updated to supply these (analytics-dashboard:93).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

Walkthrough

The pull request adds Sentry error tracking to the application by introducing the sentry-ruby and sentry-rails gems, alongside a new initializer that configures Sentry with environment-sourced DSN, enables breadcrumbs and HTTP logging, and sets distributed tracing to a 10% sample rate.

Changes

Cohort / File(s) Summary
Dependency Addition
Gemfile
Adds sentry-ruby (> 5.22) and sentry-rails (> 5.22) gems for error tracking and Rails integration.
Sentry Configuration
config/initializers/sentry.rb
Initializes Sentry with DSN from ENV["SENTRY_DSN"], enables active support and HTTP logger breadcrumbs, sets distributed tracing sample rate to 10%, and configures environment from SENTRY_ENVIRONMENT or Rails.env.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add Sentry error monitoring' accurately and concisely describes the main change: adding Sentry for error tracking with the two new gems and initializer configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/signin-password-contact-message
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
Gemfile (1)

43-44: Sort gems alphabetically per RuboCop convention.

Static analysis indicates sentry-rails should appear before sentry-ruby.

♻️ Proposed fix
-gem 'sentry-ruby', '~> 5.22'
-gem 'sentry-rails', '~> 5.22'
+gem 'sentry-rails', '~> 5.22'
+gem 'sentry-ruby', '~> 5.22'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Gemfile` around lines 43 - 44, Reorder the two Sentry gem entries in the
Gemfile so they are alphabetized per RuboCop convention: move the declaration
for gem 'sentry-rails', '~> 5.22' to appear before gem 'sentry-ruby', '~> 5.22'.
Ensure no other formatting changes are made and run RuboCop to confirm the
ordering violation is resolved.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@config/initializers/sentry.rb`:
- Around line 1-6: The rescue_from handler in ApplicationController is
swallowing service-related exceptions before Sentry can see them; update the
handler method (e.g., handle_service_error in
app/controllers/application_controller.rb) to explicitly call
Sentry.capture_exception(exception) before logging and rendering the error page
so the exceptions are reported to Sentry, then continue to
Rails.logger.error(exception.full_message) and render
"errors/service_unavailable" with status :service_unavailable and layout
"application".

---

Nitpick comments:
In `@Gemfile`:
- Around line 43-44: Reorder the two Sentry gem entries in the Gemfile so they
are alphabetized per RuboCop convention: move the declaration for gem
'sentry-rails', '~> 5.22' to appear before gem 'sentry-ruby', '~> 5.22'. Ensure
no other formatting changes are made and run RuboCop to confirm the ordering
violation is resolved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4b0250f5-06bf-4d46-8516-49609659d574

📥 Commits

Reviewing files that changed from the base of the PR and between 99eaf90 and d4b96dc.

⛔ Files ignored due to path filters (1)
  • Gemfile.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • Gemfile
  • config/initializers/sentry.rb

Comment on lines +1 to +6
Sentry.init do |config|
config.dsn = ENV["SENTRY_DSN"]
config.breadcrumbs_logger = [:active_support_logger, :http_logger]
config.traces_sample_rate = 0.1
config.environment = ENV.fetch("SENTRY_ENVIRONMENT", Rails.env)
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Rescued exceptions in ApplicationController won't be reported to Sentry.

The rescue_from handler in app/controllers/application_controller.rb (lines 6-7, 18-21) catches Google::Apis::Error, Signet::AuthorizationError, Faraday::Error, and Timeout::Error, then renders an error page without re-raising. These exceptions are swallowed before the sentry-rails middleware can intercept them.

To capture these errors, explicitly report them in the handler:

🔧 Proposed fix in app/controllers/application_controller.rb
def handle_service_error(exception)
  Sentry.capture_exception(exception)
  Rails.logger.error(exception.full_message)
  render "errors/service_unavailable", status: :service_unavailable, layout: "application"
end
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@config/initializers/sentry.rb` around lines 1 - 6, The rescue_from handler in
ApplicationController is swallowing service-related exceptions before Sentry can
see them; update the handler method (e.g., handle_service_error in
app/controllers/application_controller.rb) to explicitly call
Sentry.capture_exception(exception) before logging and rendering the error page
so the exceptions are reported to Sentry, then continue to
Rails.logger.error(exception.full_message) and render
"errors/service_unavailable" with status :service_unavailable and layout
"application".

@DominicBM DominicBM merged commit eacd57e into main Mar 15, 2026
7 checks passed
@DominicBM DominicBM deleted the fix/signin-password-contact-message branch March 15, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant