Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sentry #23

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
fblupi marked this conversation as resolved.
Show resolved Hide resolved

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)

Check warning on line 13 in app/controllers/decidim_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/decidim_controller.rb#L12-L13

Added lines #L12 - L13 were not covered by tests
end
end
17 changes: 17 additions & 0 deletions config/initializers/sentry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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 = 1.0
# or
config.traces_sampler = lambda do |_context|
true
end
davidbeig marked this conversation as resolved.
Show resolved Hide resolved
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
Loading