From 26e80a86f32ccd50f43a6e3998fe13e8435380c3 Mon Sep 17 00:00:00 2001 From: Brian Austin <13002992+brianjaustin@users.noreply.github.com> Date: Thu, 25 Jul 2024 15:20:45 -0400 Subject: [PATCH] AO3-6742 Replace New Relic with Sentry (#4865) --- ACKNOWLEDGMENTS.md | 4 +- Gemfile | 15 +- Gemfile.lock | 16 +- README.md | 1 + config/deploy.rb | 1 - .../gem-plugin_config/newrelic.rb | 2 - config/initializers/new_relic.rb | 29 --- config/initializers/sentry.rb | 29 +++ config/newrelic.example | 227 ------------------ 9 files changed, 50 insertions(+), 274 deletions(-) delete mode 100644 config/initializers/gem-plugin_config/newrelic.rb delete mode 100644 config/initializers/new_relic.rb create mode 100644 config/initializers/sentry.rb delete mode 100644 config/newrelic.example diff --git a/ACKNOWLEDGMENTS.md b/ACKNOWLEDGMENTS.md index 941dbf1965e..128480ddacf 100644 --- a/ACKNOWLEDGMENTS.md +++ b/ACKNOWLEDGMENTS.md @@ -12,7 +12,7 @@ Acknowledgments

Galera Cluster for clustered MySQL.

GitHub for collaborative programming.

HAProxy for load balancing.

-

Hound for style guidance.

+

Hound and reviewdog logo reviewdog for style guidance.

Jira for our issue tracking.

NGINX for our front end.

Memcached for caching.

@@ -23,5 +23,5 @@ Acknowledgments

RSpec for unit tests.

Ruby as our language.

RubyMine for our integrated development environment.

+

Sentry for APM/application monitoring.

Slack for communications.

-

Vagrant for our development environment.

diff --git a/Gemfile b/Gemfile index bacdfc2a0ae..3f14f2a23ae 100644 --- a/Gemfile +++ b/Gemfile @@ -80,14 +80,6 @@ gem 'escape_utils', '1.2.1' gem 'timeliness' -# TODO: rpm_contrib is deprecated and needs to be replaced -# Here is a list of possible alternatives: -# https://github.com/newrelic/extends_newrelic_rpm -# -# The last working version is not compatible with Rails 5 -# -# gem 'rpm_contrib', '2.2.0' - # for generating graphs gem 'google_visualr', git: 'https://github.com/winston/google_visualr' @@ -184,7 +176,8 @@ gem 'unicorn', '~> 5.5', require: false gem 'god', '~> 0.13.7' group :staging, :production do - # Place the New Relic gem as low in the list as possible, allowing the - # frameworks above it to be instrumented when the gem initializes. - gem "newrelic_rpm" + gem "stackprof" + gem "sentry-ruby" + gem "sentry-rails" + gem "sentry-resque" end diff --git a/Gemfile.lock b/Gemfile.lock index cf96262827f..587fe1f539e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -395,7 +395,6 @@ GEM net-ssh-gateway (2.0.0) net-ssh (>= 4.0.0) netrc (0.11.0) - newrelic_rpm (9.7.1) nio4r (2.7.0) nkf (0.2.0) nokogiri (1.16.5) @@ -553,6 +552,15 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) + sentry-rails (5.18.0) + railties (>= 5.0) + sentry-ruby (~> 5.18.0) + sentry-resque (5.18.0) + resque (>= 1.24) + sentry-ruby (~> 5.18.0) + sentry-ruby (5.18.0) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) shoulda (4.0.0) shoulda-context (~> 2.0) shoulda-matchers (~> 4.0) @@ -577,6 +585,7 @@ GEM sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) + stackprof (0.2.26) stringex (2.8.6) strscan (3.1.0) sys-uname (1.2.3) @@ -684,7 +693,6 @@ DEPENDENCIES minitest mysql2 n_plus_one_control - newrelic_rpm nokogiri (>= 1.8.5) permit_yo phraseapp-in-context-editor-ruby (>= 1.0.6) @@ -711,10 +719,14 @@ DEPENDENCIES rvm-capistrano sanitize (>= 4.6.5) selenium-webdriver + sentry-rails + sentry-resque + sentry-ruby shoulda simplecov simplecov-cobertura sprockets (< 4) + stackprof terrapin test-unit (~> 3.2) timecop diff --git a/README.md b/README.md index b91d3e67c3f..8ad346597c9 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ We benefit from software and services that are free to use for Open Source proje * [Codeship](https://codeship.com/) * [Hound](https://houndci.com/) by [thoughtbot](https://thoughtbot.com/) * [BrowserStack](https://www.browserstack.com) +* [Sentry](https://sentry.io) * [Full list of acknowledgments](ACKNOWLEDGMENTS.md) Thank you kindly! diff --git a/config/deploy.rb b/config/deploy.rb index fc5bf0fbf59..340316fda93 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -139,4 +139,3 @@ after "deploy:restart", "deploy:restart_workers" after "deploy:restart", "deploy:restart_schedulers" after "deploy:symlink", "deploy:update_configs" -after "deploy:update", "newrelic:notice_deployment" diff --git a/config/initializers/gem-plugin_config/newrelic.rb b/config/initializers/gem-plugin_config/newrelic.rb deleted file mode 100644 index 480500999d5..00000000000 --- a/config/initializers/gem-plugin_config/newrelic.rb +++ /dev/null @@ -1,2 +0,0 @@ -# Enable garbage collection profiling in New Relic -GC::Profiler.enable \ No newline at end of file diff --git a/config/initializers/new_relic.rb b/config/initializers/new_relic.rb deleted file mode 100644 index 20c40825822..00000000000 --- a/config/initializers/new_relic.rb +++ /dev/null @@ -1,29 +0,0 @@ -module NewRelic - module Agent - class NewRelicService - def create_http_connection - if Agent.config[:proxy_host] - ::NewRelic::Agent.logger.debug("Using proxy server #{Agent.config[:proxy_host]}:#{Agent.config[:proxy_port]}") - - proxy = Net::HTTP::Proxy( - Agent.config[:proxy_host], - Agent.config[:proxy_port], - Agent.config[:proxy_user], - Agent.config[:proxy_pass] - ) - conn = proxy.new(@collector.name, @collector.port) - else - # adding nil as prxy_addr here bypasses http_proxy environment variable if it is present. - # https://docs.ruby-lang.org/en/2.6.0/Net/HTTP.html#class-Net::HTTP-label-Proxies - conn = Net::HTTP.new(@collector.name, @collector.port, nil) - end - - setup_connection_for_ssl(conn) - setup_connection_timeouts(conn) - - ::NewRelic::Agent.logger.debug("Created PATCHED net/http handle to #{conn.address}:#{conn.port}") - conn - end - end - end -end diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb new file mode 100644 index 00000000000..8464e9ddaca --- /dev/null +++ b/config/initializers/sentry.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +if Rails.env.production? || Rails.env.staging? + Sentry.init do |config| + # get breadcrumbs from logs + config.breadcrumbs_logger = [:active_support_logger, :http_logger] + + # enable tracing + config.traces_sampler = lambda do |sampling_context| + next sampling_context[:parent_sampled] unless sampling_context[:parent_sampled].nil? + + rack_env = sampling_context[:env] + rate_from_nginx = Float(rack_env["HTTP_X_SENTRY_RATE"], exception: false) + return rate_from_nginx if rate_from_nginx + return 0.01 if Rails.env.production? + return 1.00 if Rails.env.staging? + + # Default to off for other environments when no override is present + 0.0 + end + + # enable profiling + # this is relative to traces_sample_rate + config.profiles_sample_rate = 1.0 + + config.environment = Rails.env + config.release = ArchiveConfig.REVISION.to_s + end +end diff --git a/config/newrelic.example b/config/newrelic.example deleted file mode 100644 index 1ac55365fac..00000000000 --- a/config/newrelic.example +++ /dev/null @@ -1,227 +0,0 @@ -# -# This file configures the New Relic Agent. New Relic monitors -# Ruby, Java, .NET, PHP, and Python applications with deep visibility and low overhead. -# For more information, visit www.newrelic.com. -# -# Generated June 02, 2012 -# -# This configuration file is custom generated for Organization for Transformative Works - -# Here are the settings that are common to all environments: -common: &default_settings - # ============================== LICENSE KEY =============================== - - # You must specify the license key associated with your New Relic - # account. This key binds your Agent's data to your account in the - # New Relic service. - license_key: 'LICENSE KEY GOES HERE' - - # Agent Enabled (Ruby/Rails Only) - # Use this setting to force the agent to run or not run. - # Default is 'auto' which means the agent will install and run only - # if a valid dispatcher such as Mongrel is running. This prevents - # it from running with Rake or the console. Set to false to - # completely turn the agent off regardless of the other settings. - # Valid values are true, false and auto. - # agent_enabled: auto - - # Application Name - # Set this to be the name of your application as you'd like it show - # up in New Relic. New Relic will then auto-map instances of your application - # into a New Relic "application" on your home dashboard page. If you want - # to map this instance into multiple apps, like "AJAX Requests" and - # "All UI" then specify a semicolon-separated list of up to three - # distinct names. If you comment this out, it defaults to the - # capitalized RAILS_ENV (i.e., Production, Staging, etc) - app_name: Archive of Our Own - - # When "true", the agent collects performance data about your - # application and reports this data to the New Relic service at - # newrelic.com. This global switch is normally overridden for each - # environment below. (formerly called 'enabled') - monitor_mode: true - - # Developer mode should be off in every environment but - # development as it has very high overhead in memory. - developer_mode: false - - # The newrelic agent generates its own log file to keep its logging - # information separate from that of your application. Specify its - # log level here. - log_level: info - - # The newrelic agent communicates with the New Relic service via http by - # default. If you want to communicate via https to increase - # security, then turn on SSL by setting this value to true. Note, - # this will result in increased CPU overhead to perform the - # encryption involved in SSL communication, but this work is done - # asynchronously to the threads that process your application code, - # so it should not impact response times. - ssl: false - - # EXPERIMENTAL: enable verification of the SSL certificate sent by - # the server. This setting has no effect unless SSL is enabled - # above. This may block your application. Only enable it if the data - # you send us needs end-to-end verified certificates. - # - # This means we cannot cache the DNS lookup, so each request to the - # New Relic service will perform a lookup. It also means that we cannot - # use a non-blocking lookup, so in a worst case, if you have DNS - # problems, your app may block indefinitely. - # verify_certificate: true - - # Set your application's Apdex threshold value with the 'apdex_t' - # setting, in seconds. The apdex_t value determines the buckets used - # to compute your overall Apdex score. - # Requests that take less than apdex_t seconds to process will be - # classified as Satisfying transactions; more than apdex_t seconds - # as Tolerating transactions; and more than four times the apdex_t - # value as Frustrating transactions. - # For more about the Apdex standard, see - # http://newrelic.com/docs/general/apdex - apdex_t: 0.5 - - # Proxy settings for connecting to the New Relic server. - # - # If a proxy is used, the host setting is required. Other settings - # are optional. Default port is 8080. - # - # proxy_host: hostname - # proxy_port: 8080 - # proxy_user: - # proxy_pass: - - # Tells transaction tracer and error collector (when enabled) - # whether or not to capture HTTP params. When true, frameworks can - # exclude HTTP parameters from being captured. - # Rails: the RoR filter_parameter_logging excludes parameters - # Java: create a config setting called "ignored_params" and set it to - # a comma separated list of HTTP parameter names. - # ex: ignored_params: credit_card, ssn, password - capture_params: false - - # Transaction tracer captures deep information about slow - # transactions and sends this to the New Relic service once a - # minute. Included in the transaction is the exact call sequence of - # the transactions including any SQL statements issued. - transaction_tracer: - - # Transaction tracer is enabled by default. Set this to false to - # turn it off. This feature is only available at the Professional - # product level. - enabled: true - - # Threshold in seconds for when to collect a transaction - # trace. When the response time of a controller action exceeds - # this threshold, a transaction trace will be recorded and sent to - # New Relic. Valid values are any float value, or (default) "apdex_f", - # which will use the threshold for an dissatisfying Apdex - # controller action - four times the Apdex T value. - transaction_threshold: apdex_f - - # When transaction tracer is on, SQL statements can optionally be - # recorded. The recorder has three modes, "off" which sends no - # SQL, "raw" which sends the SQL statement in its original form, - # and "obfuscated", which strips out numeric and string literals. - record_sql: obfuscated - - # Threshold in seconds for when to collect stack trace for a SQL - # call. In other words, when SQL statements exceed this threshold, - # then capture and send to New Relic the current stack trace. This is - # helpful for pinpointing where long SQL calls originate from. - stack_trace_threshold: 0.500 - - # Determines whether the agent will capture query plans for slow - # SQL queries. Only supported in mysql and postgres. Should be - # set to false when using other adapters. - # explain_enabled: true - - # Threshold for query execution time below which query plans will not - # not be captured. Relevant only when `explain_enabled` is true. - # explain_threshold: 0.5 - - # Error collector captures information about uncaught exceptions and - # sends them to New Relic for viewing - error_collector: - - # Error collector is enabled by default. Set this to false to turn - # it off. This feature is only available at the Professional - # product level. - enabled: true - - # Rails Only - tells error collector whether or not to capture a - # source snippet around the place of the error when errors are View - # related. - capture_source: true - - # To stop specific errors from reporting to New Relic, set this property - # to comma-separated values. Default is to ignore routing errors, - # which are how 404's get triggered. - ignore_errors: ActionController::RoutingError - - # (Advanced) Uncomment this to ensure the CPU and memory samplers - # won't run. Useful when you are using the agent to monitor an - # external resource - # disable_samplers: true - - # If you aren't interested in visibility in these areas, you can - # disable the instrumentation to reduce overhead. - # - # disable_view_instrumentation: true - # disable_activerecord_instrumentation: true - # disable_memcache_instrumentation: true - # disable_dj: true - - # Certain types of instrumentation such as GC stats will not work if - # you are running multi-threaded. Please let us know. - # multi_threaded = false - -# Application Environments -# ------------------------------------------ -# Environment-specific settings are in this section. -# For Rails applications, RAILS_ENV is used to determine the environment. -# For Java applications, pass -Dnewrelic.environment to set -# the environment. - -# NOTE if your application has other named environments, you should -# provide newrelic configuration settings for these environments here. - -development: - <<: *default_settings - # Turn off communication to New Relic service in development mode (also - # 'enabled'). - # NOTE: for initial evaluation purposes, you may want to temporarily - # turn agent communication on in development mode. - monitor_mode: false - - # Rails Only - when running in Developer Mode, the New Relic Agent will - # present performance information on the last 100 transactions you have - # executed since starting the app server. - # NOTE: There is substantial overhead when running in developer mode. - # Do not use for production or load testing. - developer_mode: true - - # Enable textmate links - # textmate: true - -test: - <<: *default_settings - # It almost never makes sense to turn on the agent when running - # unit, functional or integration tests or the like. - monitor_mode: false - -# Turn on the agent in production for 24x7 monitoring. New Relic -# testing shows an average performance impact of < 5 ms per -# transaction, so you can leave this on all the time without -# incurring any user-visible performance degradation. -production: - <<: *default_settings - monitor_mode: true - -# Many applications have a staging environment which behaves -# identically to production. Support for that environment is provided -# here. By default, the staging environment has the agent turned on. -staging: - <<: *default_settings - monitor_mode: true - app_name: Archive of Our Own (Staging)