From b88b7f14b786a373e1345373390f581925de88c4 Mon Sep 17 00:00:00 2001 From: kolesnikov Date: Wed, 26 Aug 2015 21:40:19 +0300 Subject: [PATCH] Add Exercise-18 solution Add services integrations: * NewRelic * Rollbar * Mandrill --- Gemfile | 6 ++++ Gemfile.lock | 9 ++++++ config/application.rb | 2 +- config/initializers/rollbar.rb | 54 ++++++++++++++++++++++++++++++++++ config/newrelic.yml | 49 ++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 config/initializers/rollbar.rb create mode 100644 config/newrelic.yml diff --git a/Gemfile b/Gemfile index 736e62a..f8c02bb 100644 --- a/Gemfile +++ b/Gemfile @@ -43,6 +43,12 @@ gem "whenever", require: false gem "http_accept_language" # locale data gem "rails-i18n", "~> 4.0.4" +# Exception tracking and logging +gem "rollbar" +# The New Relic Ruby agent +gem "newrelic_rpm" + +gem "mandrill-api" group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger cli diff --git a/Gemfile.lock b/Gemfile.lock index 1ed94c6..634f2b5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,6 +94,7 @@ GEM http_parser.rb (~> 0.6.0) erubis (2.7.0) eventmachine (1.0.8) + excon (0.45.4) execjs (2.6.0) factory_girl (4.5.0) activesupport (>= 3.0.0) @@ -148,6 +149,9 @@ GEM lumberjack (1.0.9) mail (2.6.3) mime-types (>= 1.16, < 3) + mandrill-api (1.0.53) + excon (>= 0.16.0, < 1.0) + json (>= 1.7.7, < 2.0) method_source (0.8.2) mime-types (2.6.1) mimemagic (0.3.0) @@ -158,6 +162,7 @@ GEM multipart-post (2.0.0) nenv (0.2.0) netrc (0.10.3) + newrelic_rpm (3.13.0.299) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) notiffany (0.0.7) @@ -227,6 +232,7 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 3.0) netrc (~> 0.7) + rollbar (2.1.2) rspec (3.3.0) rspec-core (~> 3.3.0) rspec-expectations (~> 3.3.0) @@ -327,12 +333,15 @@ DEPENDENCIES http_accept_language jbuilder (~> 2.0) jquery-rails + mandrill-api + newrelic_rpm nokogiri paperclip pg rails (= 4.2.3) rails-i18n (~> 4.0.4) rails_12factor + rollbar rspec-rails sass-rails (~> 5.0) sdoc (~> 0.4.0) diff --git a/config/application.rb b/config/application.rb index 9aa6152..9ce5d19 100644 --- a/config/application.rb +++ b/config/application.rb @@ -18,7 +18,7 @@ class Application < Rails::Application config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { - address: "smtp.gmail.com", + address: "smtp.mandrillapp.com", port: 587, authentication: :plain, user_name: ENV["SMTP_USER"], diff --git a/config/initializers/rollbar.rb b/config/initializers/rollbar.rb new file mode 100644 index 0000000..cca42a8 --- /dev/null +++ b/config/initializers/rollbar.rb @@ -0,0 +1,54 @@ +require "rollbar/rails" +Rollbar.configure do |config| + # Without configuration, Rollbar is enabled in all environments. + # To disable in specific environments, set config.enabled=false. + + config.access_token = ENV["ROLLBAR_ACCESS_TOKEN"] + + # Here we'll disable in 'test': + if Rails.env.test? + config.enabled = false + end + + # By default, Rollbar will try to call the `current_user` controller method + # to fetch the logged-in user object, and then call that object's `id`, + # `username`, and `email` methods to fetch those properties. To customize: + # config.person_method = "my_current_user" + # config.person_id_method = "my_id" + # config.person_username_method = "my_username" + # config.person_email_method = "my_email" + + # If you want to attach custom data to all exception and message reports, + # provide a lambda like the following. It should return a hash. + # config.custom_data_method = lambda { {:some_key => "some_value" } } + + # Add exception class names to the exception_level_filters hash to + # change the level that exception is reported at. Note that if an exception + # has already been reported and logged the level will need to be changed + # via the rollbar interface. + # Valid levels: 'critical', 'error', 'warning', 'info', 'debug', 'ignore' + # 'ignore' will cause the exception to not be reported at all. + # config.exception_level_filters.merge!('MyCriticalException' => 'critical') + # + # You can also specify a callable, which will be called with the exception + # instance. + # config.exception_level_filters.merge!( + # 'MyCriticalException' => lambda { |e| 'critical' } + # ) + + # Enable asynchronous reporting (uses girl_friday or Threading if girl_friday + # is not installed) + # config.use_async = true + # Supply your own async handler: + # config.async_handler = Proc.new { |payload| + # Thread.new { Rollbar.process_payload_safely(payload) } + # } + + # Enable asynchronous reporting (using sucker_punch) + # config.use_sucker_punch + + # Enable delayed reporting (using Sidekiq) + # config.use_sidekiq + # You can supply custom Sidekiq options: + # config.use_sidekiq 'queue' => 'my_queue' +end diff --git a/config/newrelic.yml b/config/newrelic.yml new file mode 100644 index 0000000..c65ef0e --- /dev/null +++ b/config/newrelic.yml @@ -0,0 +1,49 @@ +# +# This file configures the New Relic Agent. New Relic monitors Ruby, Java, +# .NET, PHP, Python and Node applications with deep visibility and low +# overhead. For more information, visit www.newrelic.com. +# +# Generated August 26, 2015 +# +# This configuration file is custom generated for JustDevLab +# +# For full documentation of agent configuration options, please refer to +# https://docs.newrelic.com/docs/agents/ruby-agent/installation-configuration/ruby-agent-configuration + +common: &default_settings + # Required license key associated with your New Relic account. + license_key: <%= ENV["NEW_RELIC_LICENSE_KEY"] %> + + # Your application name. Renaming here affects where data displays in New + # Relic. For more details, see https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/renaming-applications + app_name: Flashcards + + # To disable the agent regardless of other settings, uncomment the following: + # agent_enabled: false + + # Logging level for log/newrelic_agent.log + log_level: info + + +# Environment-specific settings are in this section. +# RAILS_ENV or RACK_ENV (as appropriate) is used to determine the environment. +# If your application has other named environments, configure them here. +development: + <<: *default_settings + app_name: Flashcards (Development) + + # NOTE: There is substantial overhead when running in developer mode. + # Do not use for production or load testing. + developer_mode: true + +test: + <<: *default_settings + # It doesn't make sense to report to New Relic from automated test runs. + monitor_mode: false + +staging: + <<: *default_settings + app_name: Flashcards (Staging) + +production: + <<: *default_settings