From 9655e9d481c2871ae4a53cde237240cee5cda60e Mon Sep 17 00:00:00 2001 From: Martin Villalba <14tinchov@gmail.com> Date: Thu, 9 Oct 2025 20:35:54 +0200 Subject: [PATCH] Mvillalba/dro 147 adding sentry to projects (#179) * Added sentry integration * Fixing lint * Added dotenv and sentry documentation * Fixing rubocop errors --------- Co-authored-by: Martin Villalba --- Gemfile | 2 ++ Gemfile.lock | 5 +++++ README.md | 25 +++++++++++++++++++++++++ app/views/layouts/application.html.erb | 1 + config/initializers/sentry.rb | 10 ++++++++++ 5 files changed, 43 insertions(+) create mode 100644 config/initializers/sentry.rb diff --git a/Gemfile b/Gemfile index 108626ad..0eef0579 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ gem "minitest-rails", "~> 8.0.0" gem "pg", "~> 1.1" gem "propshaft" gem "puma", ">= 5.0" +gem "sentry-ruby" gem "sentry-rails" gem "solid_cable" gem "solid_cache" @@ -35,6 +36,7 @@ end group :development do gem "web-console" + gem "dotenv-rails" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 8b7aea6d..46969596 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -112,6 +112,9 @@ GEM responders warden (~> 1.2.3) dotenv (3.1.8) + dotenv-rails (3.1.8) + dotenv (= 3.1.8) + railties (>= 6.1) drb (2.2.3) dry-cli (1.2.0) ed25519 (1.4.0) @@ -419,6 +422,7 @@ DEPENDENCIES capybara debug devise (~> 4.9) + dotenv-rails httparty (~> 0.23.1) jbuilder json_schemer (~> 2.4) @@ -436,6 +440,7 @@ DEPENDENCIES rubocop-rails-omakase selenium-webdriver sentry-rails + sentry-ruby solid_cable solid_cache solid_queue diff --git a/README.md b/README.md index 98002897..7f8f21fa 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,31 @@ or run the following command to deploy to google cloud Add environment variables to google cloud `add-update-env-gcloud.sh` and run the following command to add environment variables to google cloud `sh add-update-env-gcloud.sh` +### Sentry Configuration + +This project includes Sentry integration for error monitoring and performance tracking. To enable Sentry: + +1. **Create a Sentry project:** + - Go to [Sentry.io](https://sentry.io) and create a new project + - Select "Ruby" as the platform + - Copy the DSN from your project settings + +2. **Set the environment variable:** + - Add `SENTRY_DSN` to your environment variables with the DSN from your Sentry project + - For local development, add it to your `.env` file: + ```bash + SENTRY_DSN=https://your-dsn@sentry.io/project-id + ``` + - For production, add it to your Google Cloud environment variables + +3. **Sentry features enabled:** + - Automatic error tracking and reporting + - Performance monitoring + - Request headers and IP data collection (for debugging) + - Active Support and HTTP logger breadcrumbs + +The Sentry integration will only be active when the `SENTRY_DSN` environment variable is present and configured. + ### Technology Stack ![PostgreSQL 17](https://img.shields.io/badge/PostgreSQL-17-336791?logo=postgresql&logoColor=white) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index da6a88b6..00cb9db7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -16,6 +16,7 @@ <%= vite_stylesheet_tag "application" %> <%= vite_typescript_tag "application" %> <%= yield :head %> + <%= Sentry.get_trace_propagation_meta.html_safe if ENV['SENTRY_DSN'].present? %> diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb new file mode 100644 index 00000000..93a4216c --- /dev/null +++ b/config/initializers/sentry.rb @@ -0,0 +1,10 @@ +if ENV["SENTRY_DSN"].present? + Sentry.init do |config| + config.dsn = ENV["SENTRY_DSN"] + config.breadcrumbs_logger = %i[active_support_logger http_logger] + + # Add data like request headers and IP for users, + # see https://docs.sentry.io/platforms/ruby/data-management/data-collected/ for more info + config.send_default_pii = true + end +end