Open jmarsh24 opened 1 year ago
Add the sentry-ruby
and sentry-rails
gems to your Gemfile
.
# Gemfile
gem 'sentry-ruby'
gem 'sentry-rails'
Create an initializer config/initializers/sentry.rb
with the following configuration:
# config/initializers/sentry.rb
Sentry.init do |config|
config.dsn = Config.sentry_dsn!
config.breadcrumbs_logger = [:active_support_logger, :http_logger]
config.environment = Rails.env
config.release = Config.release_version
config.sanitize_fields = %w(password credit_card)
config.enabled_environments = %w(production staging)
end
Replace 'https://YOUR_SENTRY_DSN'
with your actual Sentry DSN.
Run the following command to add @sentry/browser
to your project:
yarn add @sentry/browser
Create a separate file or include this in your main Typescript file to initiate Sentry:
// javascript/lib/error-tracking.ts
import * as Sentry from '@sentry/browser';
Sentry.init({
dsn: import.meta.env.SENTRY_DSN,
environment: import.meta.env.SENTRY_ENVIRONMENT || import.meta.env.RAILS_ENV,
});
Add rails credentials:edit
to the rails encrypted credentials folder. (Be sure that you have the master.key copied from heroku RAILS_MASTER_KEY).
SENTRY_DSN=https://YOUR_SENTRY_DSN
Replace 'https://YOUR_SENTRY_DSN'
with your actual Sentry DSN.
# app/controllers/application_controller.rb
before_action :set_sentry_context
def set_sentry_context
Sentry.set_context("Request ID", { request_id: request.uuid })
end
Add the route at the top of the config/routes.rb
:
# config/routes.rb
match "/404", to: "errors#not_found", via: :all
match "/500", to: "errors#internal_server_error", via: :all
Create an ErrorsController
.
# app/controllers/errors_controller.rb
class ErrorsController < ApplicationController
skip_after_action :verify_authorized, only: [:not_found, :internal_server_error]
skip_before_action :assign_user, only: [:not_found, :internal_server_error]
skip_before_action :check_locale
before_action :assign_exception
before_action :capture_exception
def not_found
render status: :not_found
end
def internal_server_error
render status: :internal_server_error
end
private
def assign_exception
@exception = request.env["action_dispatch.exception"]
end
def capture_exception
Rails.error.report(@exception, handled: true)
end
end
<!-- app/views/errors/internal_server_error.html.slim -->
= request.uuid
Follow these initial steps when an error is reported:
@JensRavens, @danieldiekmeier, and @Adeynack I have created a simple guide based on anymator to add error tracking with sentry. Is there anything you would like to add above?
Where should this documentation live?
We could also consider to hook up projects/organization GitHub with sentry so it automatically creates issues for us so we don't have to do it manually. I don't have permissions on any project or the organization to see these settings though so @JensRavens or @ckroter would have to do it.
https://docs.sentry.io/product/integrations/source-code-mgmt/github/ https://resources.github.com/actions/integrating-with-sentry/
I think we don't have to add the Request ID to Sentry manually, Sentry seems to support this out of the box: https://github.com/getsentry/sentry-ruby/pull/1120
Where should this documentation live?
I still cannot offer a clear answer to that. @JensRavens what's our stance there at the moment? What about a markdown file? Should it be here in shimmer
, or should it be in development-environment
? Or in the Handbook?