From 3ad025ba5f696ab566e32632e246762c0c97cbd2 Mon Sep 17 00:00:00 2001 From: Jesse Tomchak Date: Wed, 8 Nov 2023 13:37:45 -0700 Subject: [PATCH] MAM-3095-load-test-20k-data-capture (#204) Full log replacement of Datadog with AppSignal. Better Logging, Alerting, Simpler adding errors --- Capfile | 2 + Gemfile | 4 +- Gemfile.lock | 16 ++----- .../channel_mammoth_statuses_scheduler.rb | 2 +- config.ru | 8 +++- config/application.rb | 1 - config/appsignal.yml | 47 +++++++++++++++++++ config/deploy.rb | 1 + config/environments/production.rb | 2 +- config/initializers/datadog-tracer.rb | 20 -------- config/initializers/logging.rb | 6 +++ 11 files changed, 70 insertions(+), 39 deletions(-) create mode 100644 config/appsignal.yml delete mode 100644 config/initializers/datadog-tracer.rb create mode 100644 config/initializers/logging.rb diff --git a/Capfile b/Capfile index 86efa5bac..50b3247a8 100644 --- a/Capfile +++ b/Capfile @@ -13,3 +13,5 @@ require 'capistrano/rails/assets' require 'capistrano/rails/migrations' Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } + +require 'appsignal/capistrano' diff --git a/Gemfile b/Gemfile index bfd9ccc65..70727c6a8 100644 --- a/Gemfile +++ b/Gemfile @@ -193,7 +193,6 @@ end group :production, :staging do gem 'lograge', '~> 0.12' - gem 'ddtrace', require: 'ddtrace/auto_instrument' gem 'google-protobuf', '~> 3.0' end @@ -213,3 +212,6 @@ gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0' # Use Json Web Token (JWT) for token based authentication Mammoth gem 'jwt' + +# Appsignal +gem 'appsignal' diff --git a/Gemfile.lock b/Gemfile.lock index d3a392c2c..4125dc2e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -118,6 +118,8 @@ GEM annotate (3.2.0) activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) + appsignal (3.4.14) + rack ast (2.4.2) async (1.31.0) console (~> 1.10) @@ -245,16 +247,7 @@ GEM activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) - datadog-ci (0.2.0) - msgpack date (3.3.3) - ddtrace (1.15.0) - datadog-ci (~> 0.2.0) - debase-ruby_core_source (= 3.2.2) - libdatadog (~> 5.0.0.1.0) - libddwaf (~> 1.14.0.0.0) - msgpack - debase-ruby_core_source (3.2.2) debug_inspector (1.1.0) devise (4.9.2) bcrypt (~> 3.0) @@ -457,9 +450,6 @@ GEM letter_opener (~> 1.7) railties (>= 5.2) rexml - libdatadog (5.0.0.1.0) - libddwaf (1.14.0.0.0) - ffi (~> 1.0) link_header (0.0.8) llhttp-ffi (0.4.0) ffi-compiler (~> 1.0) @@ -865,6 +855,7 @@ DEPENDENCIES active_model_serializers (~> 0.10) addressable (~> 2.8) annotate (~> 3.2) + appsignal async (~> 1.31) async-http aws-sdk-s3 (~> 1.123) @@ -889,7 +880,6 @@ DEPENDENCIES concurrent-ruby connection_pool database_cleaner-active_record - ddtrace devise (~> 4.9) devise-two-factor (~> 4.1) devise_pam_authenticatable2 (~> 9.2) diff --git a/app/workers/scheduler/channel_mammoth_statuses_scheduler.rb b/app/workers/scheduler/channel_mammoth_statuses_scheduler.rb index b118712f9..05712d106 100644 --- a/app/workers/scheduler/channel_mammoth_statuses_scheduler.rb +++ b/app/workers/scheduler/channel_mammoth_statuses_scheduler.rb @@ -25,7 +25,7 @@ def perform def update_channel_feeds! @channels = Mammoth::Channels.new.channels_with_statuses @channels.each do |channel| - Rails.logger.info { "CHANNEL:: #{channel} \n" } + Rails.logger.debug { "CHANNEL:: #{channel} \n" } push_statuses(channel[:statuses], channel[:id]) end end diff --git a/config.ru b/config.ru index afd13e211..256af8dee 100644 --- a/config.ru +++ b/config.ru @@ -1,6 +1,10 @@ # frozen_string_literal: true # This file is used by Rack-based servers to start the application. - -require File.expand_path('config/environment', __dir__) +begin + require File.expand_path('config/environment', __dir__) +rescue Exception => e + Appsignal.send_error(e) + raise +end run Rails.application diff --git a/config/application.rb b/config/application.rb index 1e4703cb5..3efe7584d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -14,7 +14,6 @@ #require 'action_mailbox/engine' #require 'action_text/engine' #require 'rails/test_unit/railtie' -require 'datadog/profiling/preload' require 'sprockets/railtie' # Used to be implicitly required in action_mailbox/engine diff --git a/config/appsignal.yml b/config/appsignal.yml new file mode 100644 index 000000000..f20168136 --- /dev/null +++ b/config/appsignal.yml @@ -0,0 +1,47 @@ +default: + &defaults # Your push api key, it is possible to set this dynamically using ERB: + push_api_key: "<%= ENV['APPSIGNAL_PUSH_API_KEY'] %>" + + # Your app's name + name: 'moth.social' + working_directory_path: '/tmp/appsignal' + + # Actions that should not be monitored by AppSignal + # ignore_actions: + # - ApplicationController#isup + + # Errors that should not be recorded by AppSignal + # For more information see our docs: + # https://docs.appsignal.com/ruby/configuration/ignore-errors.html + # ignore_errors: + # - Exception + # - NoMemoryError + # - ScriptError + # - LoadError + # - NotImplementedError + # - SyntaxError + # - SecurityError + # - SignalException + # - Interrupt + # - SystemExit + # - SystemStackError + + # See https://docs.appsignal.com/ruby/configuration/options.html for + # all configuration options. + +# Configuration per environment, leave out an environment or set active +# to false to not push metrics for that environment. + +development: + <<: *defaults + active: true + +production: + <<: *defaults + active: true + enable_nginx_metrics: true + +staging: + <<: *defaults + active: true + enable_nginx_metrics: true diff --git a/config/deploy.rb b/config/deploy.rb index 0610c4c1c..583674376 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -9,6 +9,7 @@ set :rbenv_type, :user set :rbenv_ruby, File.read('.ruby-version').strip set :migration_role, :app +set :appsignal_config, name: 'moth.social' append :linked_dirs, 'vendor/bundle', 'public/system' diff --git a/config/environments/production.rb b/config/environments/production.rb index fc665e490..b404e7f1b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -52,7 +52,7 @@ # information to avoid inadvertent exposure of personally identifiable information (PII). # Use the lowest log level to ensure availability of diagnostic information # when problems arise. - config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'warn').to_sym + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info').to_sym # Prepend all log lines with the following tags. config.log_tags = [:request_id] diff --git a/config/initializers/datadog-tracer.rb b/config/initializers/datadog-tracer.rb deleted file mode 100644 index 69bf7efa8..000000000 --- a/config/initializers/datadog-tracer.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require 'ddtrace' - -if Rails.env.production? || Rails.env.staging? - Datadog.configure do |c| - if Rails.configuration.hosts[0].include? 'staging' - c.env = 'staging' - else - c.profiling.enabled = true - c.env = Rails.env - end - c.service = 'moth.social' - c.tracing.instrument :httprb, service_name: 'moth.social' - c.tracing.instrument :faraday, service_name: 'moth.social' - c.tracing.instrument :active_support, service_name: 'moth.social' - c.tracing.instrument :http, service_name: 'moth.social' - c.tracing.instrument :rack, service_name: 'moth.social', headers: { response: %w(Content-Type X-Request-ID X-RateLimit-Remaining) } - end -end diff --git a/config/initializers/logging.rb b/config/initializers/logging.rb new file mode 100644 index 000000000..182f0a6a6 --- /dev/null +++ b/config/initializers/logging.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + + +console_logger = ActiveSupport::Logger.new(STDOUT) +appsignal_logger = ActiveSupport::TaggedLogging.new(Appsignal::Logger.new('rails')) +Rails.logger = console_logger.extend(ActiveSupport::Logger.broadcast(appsignal_logger))