From 9157876cae223b438209e537ab035eafff11326e Mon Sep 17 00:00:00 2001
From: stephanierousset <61418966+Stef-Rousset@users.noreply.github.com>
Date: Tue, 12 Nov 2024 15:58:29 +0100
Subject: [PATCH] backport: remove sentry (#622)
---
.env-example | 3 -
.overloads | 1 -
Gemfile | 3 -
Gemfile.lock | 15 +-
app.json | 3 +-
.../layouts/decidim/_head_extra.html.erb | 9 --
config/initializers/sentry.rb | 5 -
config/secrets.yml | 4 -
lib/decidim_app/sentry_setup.rb | 57 --------
spec/lib/decidim_app/sentry_setup_spec.rb | 129 ------------------
10 files changed, 3 insertions(+), 226 deletions(-)
delete mode 100644 config/initializers/sentry.rb
delete mode 100644 lib/decidim_app/sentry_setup.rb
delete mode 100644 spec/lib/decidim_app/sentry_setup_spec.rb
diff --git a/.env-example b/.env-example
index bc0ead2894..14c215885a 100644
--- a/.env-example
+++ b/.env-example
@@ -5,7 +5,6 @@ AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
SECRET_KEY_BASE=
GEOCODER_LOOKUP_API_KEY=
-SENTRY_DSN=
HELP_SCOUT_BEACON_ID_MAIN=
BACKUP_ENABLED=
BACKUP_S3SYNC_ENABLED=
@@ -48,8 +47,6 @@ AVAILABLE_LOCALES="fr,en"
# Force SSL - binary (default: 1)
# Can be disable for reverse proxy setup
FORCE_SSL=1
-SENTRY_SIDEKIQ_SAMPLE_RATE=0.1
-SENTRY_SAMPLE_RATE=0.5
FRIENDLY_SIGNUP_OVERRIDE_PASSWORDS=1
FRIENDLY_SIGNUP_INSTANT_VALIDATION=1
FRIENDLY_SIGNUP_HIDE_NICKNAME=1
diff --git a/.overloads b/.overloads
index 385fe4ffee..3f9b1a6fbb 100644
--- a/.overloads
+++ b/.overloads
@@ -58,7 +58,6 @@ config/initializers/filter_parameter_logging.rb
config/initializers/inflections.rb
config/initializers/mime_types.rb
config/initializers/new_framework_defaults_5_2.rb
-config/initializers/sentry.rb
config/initializers/social_share_button.rb
config/initializers/wrap_parameters.rb
config/locales/decidim-awesome/fr.yml
diff --git a/Gemfile b/Gemfile
index 92dea90aff..b066a14083 100644
--- a/Gemfile
+++ b/Gemfile
@@ -86,9 +86,6 @@ group :production do
gem "health_check", "~> 3.1"
gem "lograge"
gem "sendgrid-ruby"
- gem "sentry-rails"
- gem "sentry-ruby"
- gem "sentry-sidekiq"
gem "sidekiq", "~> 6.0"
gem "sidekiq-scheduler", "~> 5.0"
end
diff --git a/Gemfile.lock b/Gemfile.lock
index fbcfc7891e..c49bd80729 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -164,7 +164,7 @@ GIT
GIT
remote: https://github.com/decidim-ice/decidim-module-decidim_awesome
- revision: 51bc593da8fb72d14c2e5b5df55dbb686be1fbbe
+ revision: b9aae42bc835485edec5887cb02062caaaf64ed1
branch: release/0.27-stable
specs:
decidim-decidim_awesome (0.10.3)
@@ -1036,14 +1036,6 @@ GEM
semantic_range (3.0.0)
sendgrid-ruby (6.7.0)
ruby_http_client (~> 3.4)
- 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.12)
connection_pool (>= 2.2.5, < 3)
@@ -1223,9 +1215,6 @@ DEPENDENCIES
rack-attack (~> 6.6)
rubocop-faker
sendgrid-ruby
- sentry-rails
- sentry-ruby
- sentry-sidekiq
sidekiq (~> 6.0)
sidekiq-scheduler (~> 5.0)
spring (~> 2.0)
@@ -1238,4 +1227,4 @@ RUBY VERSION
ruby 3.0.6p216
BUNDLED WITH
- 2.4.6
+ 2.5.10
diff --git a/app.json b/app.json
index 1d321aed7b..611b2d2ad6 100644
--- a/app.json
+++ b/app.json
@@ -7,8 +7,7 @@
"heroku-redis:hobby-dev",
"memcachedcloud:30",
"newrelic:wayne",
- "sendgrid:starter",
- "sentry:f1"
+ "sendgrid:starter"
],
"scripts": {
"postdeploy":"rake db:schema:load db:migrate"
diff --git a/app/views/layouts/decidim/_head_extra.html.erb b/app/views/layouts/decidim/_head_extra.html.erb
index 876fb4f0ee..23a5027dd8 100644
--- a/app/views/layouts/decidim/_head_extra.html.erb
+++ b/app/views/layouts/decidim/_head_extra.html.erb
@@ -1,12 +1,3 @@
-<% if Rails.application.secrets.dig(:sentry, :enabled) %>
-
-
-<% end %>
-
<% if defined?(Decidim::DecidimAwesome) %>
<%= stylesheet_pack_tag "decidim_decidim_awesome", media: "all" %>
<%= render(partial: "layouts/decidim/decidim_awesome/custom_styles") if awesome_custom_styles %>
diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb
deleted file mode 100644
index 5e75fcffde..0000000000
--- a/config/initializers/sentry.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-# frozen_string_literal: true
-
-require "decidim_app/sentry_setup"
-
-SentrySetup.init
diff --git a/config/secrets.yml b/config/secrets.yml
index e9c2c8d3f8..2f166fdfd3 100644
--- a/config/secrets.yml
+++ b/config/secrets.yml
@@ -106,10 +106,6 @@ default: &default
uid_field: <%= ENV["OMNIAUTH_OPENID_CONNECT_UID_FIELD"] %>
maps:
api_key: <%= ENV["GEOCODER_LOOKUP_API_KEY"] %>
- sentry:
- enabled: <%= !ENV["SENTRY_DSN"].blank? %>
- dsn: <%= ENV["SENTRY_DSN"] %>
- js_version: "4.6.4"
etherpad:
server: <%= ENV["ETHERPAD_SERVER"] %>
api_key: <%= ENV["ETHERPAD_API_KEY"] %>
diff --git a/lib/decidim_app/sentry_setup.rb b/lib/decidim_app/sentry_setup.rb
deleted file mode 100644
index 1b4da5fb2e..0000000000
--- a/lib/decidim_app/sentry_setup.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-# frozen_string_literal: true
-
-require "sentry-ruby"
-require "json"
-require "decidim_app/sentry_setup"
-
-module SentrySetup
- class << self
- def init
- return unless Rails.application.secrets.dig(:sentry, :enabled)
-
- Sentry.init do |config|
- config.dsn = Rails.application.secrets.dig(:sentry, :dsn)
- config.breadcrumbs_logger = [:active_support_logger, :http_logger]
-
- config.traces_sample_rate = sample_rate.to_f
-
- config.traces_sampler = ->(sampling_context) { sample_trace(sampling_context) }
- end
-
- Sentry.set_tags("server.hostname": hostname) if hostname.present?
- Sentry.set_tags("server.ip": ip) if ip.present?
- end
-
- private
-
- def sample_trace(sampling_context)
- transaction_context = sampling_context[:transaction_context]
- op = transaction_context[:op]
- transaction_name = transaction_context[:name]
-
- if op =~ /http/ && transaction_name == "/health_check"
- 0.0
- else
- sample_rate.to_f
- end
- end
-
- def server_metadata
- JSON.parse(`scw-metadata-json`)
- rescue Errno::ENOENT, TypeError
- {}
- end
-
- def hostname
- server_metadata["hostname"]
- end
-
- def ip
- server_metadata.dig("public_ip", "address")
- end
-
- def sample_rate
- Sidekiq.server? ? ENV.fetch("SENTRY_SIDEKIQ_SAMPLE_RATE", "0.1") : ENV.fetch("SENTRY_SAMPLE_RATE", "0.5")
- end
- end
-end
diff --git a/spec/lib/decidim_app/sentry_setup_spec.rb b/spec/lib/decidim_app/sentry_setup_spec.rb
deleted file mode 100644
index ef1a209afd..0000000000
--- a/spec/lib/decidim_app/sentry_setup_spec.rb
+++ /dev/null
@@ -1,129 +0,0 @@
-# frozen_string_literal: true
-
-require "spec_helper"
-require "json"
-
-describe SentrySetup do
- let(:secrets) do
- {
- sentry: {
- enabled: true,
- dsn: "http://sentry.dsn",
- js_version: "4.6.4"
- }
- }
- end
-
- let(:server_metadata) do
- JSON.dump({
- hostname: "my_hostname",
- public_ip: {
- address: "123.123.123.123"
- }
- })
- end
-
- before do
- allow(Rails.application).to receive(:secrets).and_return(secrets)
- allow(described_class).to receive(:`).with("scw-metadata-json").and_return(server_metadata)
- subject.init
- end
-
- describe ".init" do
- it "is configured" do
- expect(Sentry.configuration.dsn.host).to eq("sentry.dsn")
- expect(Sentry.configuration.traces_sample_rate).to eq(0.5)
- end
-
- context "when sentry is disabled" do
- let(:secrets) do
- {
- sentry: {
- enabled: false
- }
- }
- end
-
- let(:sentry) { double("Sentry") }
-
- it "is not configured" do
- expect(sentry).not_to receive(:init)
- end
- end
- end
-
- describe "#sample_trace" do
- let(:transaction_name) { "/some_page" }
- let(:context) { { transaction_context: { op: "http", name: transaction_name } } }
-
- context "when transaction is about the health check" do
- let(:transaction_name) { "/health_check" }
-
- it "returns 0" do
- expect(subject.send(:sample_trace, context)).to eq 0.0
- end
- end
-
- it "returns a Float" do
- expect(subject.send(:sample_trace, context)).to be_a Float
- end
- end
-
- describe ".ip" do
- it "returns the ip" do
- expect(subject.send(:ip)).to eq("123.123.123.123")
- end
-
- context "when server_metadata is not available" do
- let(:server_metadata) { nil }
-
- it "returns nil" do
- expect(subject.send(:ip)).to be_nil
- end
- end
- end
-
- describe ".hostname" do
- it "returns the hostname" do
- expect(subject.send(:hostname)).to eq("my_hostname")
- end
-
- context "when server_metadata is not available" do
- let(:server_metadata) { {} }
-
- it "returns nil" do
- expect(subject.send(:hostname)).to be_nil
- end
- end
- end
-
- describe ".server_metadata" do
- context "when metadata are non-existent" do
- let(:server_metadata) { {} }
-
- it "returns nil" do
- expect(subject.send(:server_metadata)).to eq({})
- end
- end
-
- it "returns a metadata hash" do
- expect(subject.send(:server_metadata)).to be_a(Hash)
- end
- end
-
- describe ".sample rate" do
- it "returns the sample rate" do
- expect(subject.send(:sample_rate)).to eq("0.5")
- end
-
- context "when in a sidekiq worker" do
- before do
- allow(Sidekiq).to receive(:server?).and_return("constant")
- end
-
- it "returns the sample rate" do
- expect(subject.send(:sample_rate)).to eq("0.1")
- end
- end
- end
-end