Skip to content

Commit

Permalink
Add sentry (#23)
Browse files Browse the repository at this point in the history
* add sentry

* add sentry-sidekiq and use of Sentry.set_user

* Update config/initializers/sentry.rb

Co-authored-by: Fran Bolívar <[email protected]>

---------

Co-authored-by: David Igón <=>
Co-authored-by: Fran Bolívar <[email protected]>
  • Loading branch information
davidbeig and fblupi authored Feb 27, 2024
1 parent 1dcbc66 commit d7ea580
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ group :production do
gem "figaro", "~> 1.2"
gem "sidekiq", "~> 6.0"
gem "whenever", require: false

gem "sentry-rails"
gem "sentry-ruby"
gem "sentry-sidekiq"
end

group :test do
Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,14 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2)
semantic_range (3.0.0)
sentry-rails (5.16.1)
railties (>= 5.0)
sentry-ruby (~> 5.16.1)
sentry-ruby (5.16.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
sentry-sidekiq (5.16.1)
sentry-ruby (~> 5.16.1)
sidekiq (>= 3.0)
seven_zip_ruby (1.3.0)
sidekiq (6.5.9)
connection_pool (>= 2.2.5, < 3)
Expand Down Expand Up @@ -927,6 +935,9 @@ DEPENDENCIES
rubocop-faker
rubocop-rails
rubocop-rspec
sentry-rails
sentry-ruby
sentry-sidekiq
sidekiq (~> 6.0)
spring (~> 2.0)
spring-watcher-listen (~> 2.0)
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/decidim_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@
# entry point, but you can change what controller it inherits from
# so you can customize some methods.
class DecidimController < ApplicationController
before_action :set_sentry_context

def set_sentry_context
return unless Rails.application.secrets.sentry_enabled?

Sentry.set_user({ id: try(:current_user).try(:id) }.merge(session))
Sentry.set_extras(params: params.to_unsafe_h, url: request.url)
end
end
13 changes: 13 additions & 0 deletions config/initializers/sentry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

if Rails.application.secrets.sentry_enabled
Sentry.init do |config|
config.dsn = ENV.fetch("SENTRY_DSN")
config.breadcrumbs_logger = [:active_support_logger, :http_logger]

# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production.
config.traces_sample_rate = ENV.fetch("SENTRY_TRACES_SAMPLE_RATE", "0.5").to_f
end
end
2 changes: 2 additions & 0 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ default: &default

development:
<<: *default
sentry_enabled: false
secret_key_base: <%= ENV["SECRET_KEY_BASE"].presence || "417e4b74122188de90a9ec2551d2d2c52eb9d18f09684605b876d7772b3295b58f810c1de2b3131c0689d38454aac60c765cb4c1c1b9fa89fb9e028f460726f1" %>
omniauth:
developer:
Expand Down Expand Up @@ -189,6 +190,7 @@ test:
# instead read values from the environment.
production:
<<: *default
sentry_enabled: true
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
smtp_username: <%= ENV["SMTP_USERNAME"] %>
smtp_password: <%= ENV["SMTP_PASSWORD"] %>
Expand Down

0 comments on commit d7ea580

Please sign in to comment.