From 65a04769af4827327ac481650a480535a868a615 Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Sat, 17 Oct 2020 17:26:01 -0600 Subject: [PATCH] Update Sentry configuration. Use a distinct DSN for Rails and JS since we're splitting it into two separate projects, use Sentry's Vue integration, and add creating Sentry releases to the deploy task. --- app/controllers/application_controller.rb | 2 +- app/javascript/packs/application.ts | 11 +++++++-- config/application.rb | 24 ++++++++++--------- lib/tasks/deploy.rake | 10 ++++++++ package.json | 1 + yarn.lock | 29 +++++++++++++++++++++++ 6 files changed, 63 insertions(+), 14 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0fd21130a..f07c8c1ca 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -44,7 +44,7 @@ def user_not_authorized # Send user ID, params, and request URL to Sentry on-error. def set_raven_context - Raven.user_context(id: current_user&.username) + Raven.user_context(id: current_user&.id, username: current_user&.username) Raven.extra_context(params: params.to_unsafe_h, url: request.url) end end diff --git a/app/javascript/packs/application.ts b/app/javascript/packs/application.ts index a0c7a44bd..d0cf616c1 100644 --- a/app/javascript/packs/application.ts +++ b/app/javascript/packs/application.ts @@ -14,7 +14,8 @@ import VTooltip from 'v-tooltip'; import 'core-js/stable'; import 'regenerator-runtime/runtime'; import * as Sentry from '@sentry/browser'; -import * as _ from "lodash"; +import { Vue as VueIntegration } from '@sentry/integrations'; +import _ from "lodash"; import '../src/vue-loader'; import '../src/toggleable-buttons'; import '../src/bulma'; @@ -25,7 +26,13 @@ import '../src/settings'; require.context('../icons', true); if (process.env.NODE_ENV === 'production') { - Sentry.init({ dsn: process.env.SENTRY_DSN_JS }); + Sentry.init({ + dsn: process.env.SENTRY_DSN_JS, + integrations: [ + new VueIntegration({ Vue }) + ], + environment: process.env.NODE_ENV + }); } Vue.use(TurbolinksAdapter); diff --git a/config/application.rb b/config/application.rb index a366c3b02..b5697e009 100644 --- a/config/application.rb +++ b/config/application.rb @@ -51,10 +51,19 @@ class Application < Rails::Application generate.controller_specs false end - if Rails.env.production? - Raven.configure do |config| - config.dsn = ENV['SENTRY_DSN'] - end + # Get the current commit SHA for the Rails app. This will surely have some + # sort of negative side-effect I haven't figured out yet. This is used for + # caching to make sure the cache is busted when a new version of the + # application is deployed. + # https://brandonhilkert.com/blog/understanding-the-rails-cache-id-environment-variable/ + ENV['GIT_COMMIT_SHA'] = `git rev-parse --short HEAD`.strip + + # Configure Sentry. + Raven.configure do |config| + config.dsn = ENV['SENTRY_DSN_RAILS'] + # Only run in production. + config.environments = ['production'] + config.release = ENV['GIT_COMMIT_SHA'] end config.to_prepare do @@ -72,12 +81,5 @@ class Application < Rails::Application config.annotations.register_directories("spec") # Add .vue files to the file extensions picked up by 'rails notes'. config.annotations.register_extensions("vue") { |annotation| %r{//\s*(#{annotation}):?\s*(.*)$} } - - # Get the current commit SHA for the Rails app. This will surely have some - # sort of negative side-effect I haven't figured out yet. This is used for - # caching to make sure the cache is busted when a new version of the - # application is deployed. - # https://brandonhilkert.com/blog/understanding-the-rails-cache-id-environment-variable/ - ENV['GIT_COMMIT_SHA'] = `git rev-parse --short HEAD`.strip end end diff --git a/lib/tasks/deploy.rake b/lib/tasks/deploy.rake index f2b551055..04048ec1d 100644 --- a/lib/tasks/deploy.rake +++ b/lib/tasks/deploy.rake @@ -7,6 +7,12 @@ namespace :deploy do puts puts "Pulling down the latest code from master..." system('git pull') + # Create Sentry release + puts + puts "Creating Sentry release..." + version = `sentry-cli releases propose-version`.strip + system("sentry-cli releases new -p vglist-backend -p vglist-frontend #{version}") + system("sentry-cli releases set-commits --auto #{version}") # Install dependencies with Bundler. puts puts "Installing Ruby dependencies..." @@ -23,6 +29,10 @@ namespace :deploy do puts puts "Precompiling assets..." system('bundle exec rails assets:precompile') + # Finalize Sentry release + puts + puts "Finalizing Sentry release..." + system("sentry-cli releases finalize #{version}") puts puts "Deploy successful!" diff --git a/package.json b/package.json index c227dbaea..fca76ee0b 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "@rails/ujs": "^6.0.2", "@rails/webpacker": "5.2.1", "@sentry/browser": "5.26.0", + "@sentry/integrations": "^5.26.0", "@types/node": "^14.0.0", "babel-preset-typescript-vue": "^1.1.1", "bulma": "https://github.com/connorshea/bulma#css-variables-with-fallback", diff --git a/yarn.lock b/yarn.lock index 900415c80..597c4448f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -956,6 +956,16 @@ "@sentry/utils" "5.26.0" tslib "^1.9.3" +"@sentry/integrations@^5.26.0": + version "5.26.0" + resolved "https://registry.yarnpkg.com/@sentry/integrations/-/integrations-5.26.0.tgz#cf90005359862c5b1df4df0f1ce8be5e56c9e1ad" + integrity sha512-XBMPm3wWW+3EJvWFHdVcl0PSWjjNEzmQxjjWeMv9vLWAC1zhS8gcpk/LyDIFWojJBzhASD8f1mLv2ZdKZtA1ZQ== + dependencies: + "@sentry/types" "5.26.0" + "@sentry/utils" "5.26.0" + localforage "1.8.1" + tslib "^1.9.3" + "@sentry/minimal@5.26.0": version "5.26.0" resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.26.0.tgz#851dea3644153ed3ac4837fa8ed5661d94e7a313" @@ -4068,6 +4078,11 @@ iferr@^0.1.5: resolved "https://registry.yarnpkg.com/iferr/-/iferr-0.1.5.tgz#c60eed69e6d8fdb6b3104a1fcbca1c192dc5b501" integrity sha1-xg7taebY/bazEEofy8ocGS3FtQE= +immediate@~3.0.5: + version "3.0.6" + resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b" + integrity sha1-nbHb0Pr43m++D13V5Wu2BigN5ps= + import-cwd@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/import-cwd/-/import-cwd-2.1.0.tgz#aa6cf36e722761285cb371ec6519f53e2435b0a9" @@ -4651,6 +4666,13 @@ last-call-webpack-plugin@^3.0.0: lodash "^4.17.5" webpack-sources "^1.1.0" +lie@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/lie/-/lie-3.1.1.tgz#9a436b2cc7746ca59de7a41fa469b3efb76bd87e" + integrity sha1-mkNrLMd0bKWd56QfpGmz77dr2H4= + dependencies: + immediate "~3.0.5" + lines-and-columns@^1.1.6: version "1.1.6" resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" @@ -4706,6 +4728,13 @@ loader-utils@^2.0.0: emojis-list "^3.0.0" json5 "^2.1.2" +localforage@1.8.1: + version "1.8.1" + resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.8.1.tgz#f6c0a24b41ab33b10e4dc84342dd696f6f3e3433" + integrity sha512-azSSJJfc7h4bVpi0PGi+SmLQKJl2/8NErI+LhJsrORNikMZnhaQ7rv9fHj+ofwgSHrKRlsDCL/639a6nECIKuQ== + dependencies: + lie "3.1.1" + locate-path@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e"