Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Fix and improve error reporting #4740

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ gem 'sentry-ruby', '~> 5.17'
gem 'sentry-sidekiq', '~> 5.18'
gem 'sidekiq', '~> 7.2'
gem 'sidekiq-cron', '~> 1.12'
gem 'stackprof', '~> 0.2'
gem 'stimulus-rails', '~> 1.3'
gem 'turbo-rails', '~> 2.0'
gem 'view_component', '~> 3.12'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ GEM
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
stackprof (0.2.26)
statsd-ruby (1.5.0)
stimulus-rails (1.3.3)
railties (>= 6.0.0)
Expand Down Expand Up @@ -635,6 +636,7 @@ DEPENDENCIES
sidekiq (~> 7.2)
sidekiq-cron (~> 1.12)
simplecov (~> 0.22)
stackprof (~> 0.2)
stimulus-rails (~> 1.3)
turbo-rails (~> 2.0)
vcr (~> 6.2)
Expand Down
30 changes: 0 additions & 30 deletions app/javascript/error_tracking.js

This file was deleted.

1 change: 1 addition & 0 deletions app/javascript/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './src/sentry';
import './controllers';
import '@hotwired/turbo-rails';
import './src/custom_turbo_stream_actions';
21 changes: 21 additions & 0 deletions app/javascript/src/sentry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable no-undef, no-unused-expressions */

const {
SENTRY_DSN, currentUserSignedIn, currentUserId, currentUsername,
} = window;

window.Sentry = window.Sentry || {};
window.Sentry && Sentry.onLoad && Sentry.onLoad(() => {
Sentry.init({
dsn: SENTRY_DSN,
environment: 'production',
debug: true,
});

if (currentUserSignedIn) {
Sentry.setUser({
id: currentUserId,
name: currentUsername,
});
}
});
14 changes: 0 additions & 14 deletions app/views/layouts/_error_tracking.html.erb

This file was deleted.

8 changes: 3 additions & 5 deletions app/views/layouts/admin/base.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<!DOCTYPE html>
<html lang="en" id="root-element" class="<%= current_theme.name %> h-full">
<head>
<% content_for :error_tracking do %>
<%= render 'layouts/error_tracking' %>
<% end %>
<title>
<%= content_for(:title) || 'Admin | The Odin Project' %>
</title>
Expand All @@ -26,8 +23,9 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">

<%= stylesheet_link_tag 'application', 'main', media: 'all', 'data-turbo-track': 'reload' %>
<%= javascript_include_tag 'main', 'data-turbo-track': 'reload', defer: true %>
<%= stylesheet_link_tag 'application', 'main', media: 'all', data: { turbo_track: 'reload' } %>
<%= render 'shared/sentry' %>
<%= javascript_include_tag 'main', defer: true, data: { turbo_track: 'reload' } %>
</head>

<body class="h-full bg-white text-gray-600 dark:bg-gray-900 dark:text-gray-300">
Expand Down
8 changes: 3 additions & 5 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<!DOCTYPE html>
<html lang="en" id="root-element" class="<%= current_theme.name %>">
<head>
<% content_for :error_tracking do %>
<%= render 'layouts/error_tracking' %>
<% end %>
<title>
<%= content_for(:title) || 'Your Career in Web Development Starts Here | The Odin Project' %>
</title>
Expand All @@ -24,9 +21,10 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">

<%= stylesheet_link_tag 'application', 'main', media: 'all', 'data-turbo-track': 'reload' %>
<%= stylesheet_link_tag 'application', 'main', media: 'all', data: { turbo_track: 'reload' } %>
<%= render 'shared/sentry' %>
<%= render 'shared/analytics' %>
<%= javascript_include_tag 'main', 'data-turbo-track': 'reload', type: 'module' %>
<%= javascript_include_tag 'main', defer: true, data: { turbo_track: 'reload' } %>
</head>

<body class="h-full bg-gray-50 text-gray-600 dark:bg-gray-900 dark:text-gray-300">
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/component_preview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Component Previews
</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%= stylesheet_link_tag 'application', 'main' media: 'all', 'data-turbo-track': 'reload' %>
<%= javascript_include_tag 'main', 'data-turbo-track': 'reload', defer: true %>
<%= stylesheet_link_tag 'application', 'main', media: 'all', data: { turbo_track: 'reload' } %>
<%= javascript_include_tag 'main', defer: true, data: { turbo_track: 'reload' } %>
</head>
<body style="padding: 20px">
<div style="
Expand Down
7 changes: 5 additions & 2 deletions app/views/layouts/errors.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
<%= content_for(:title) || 'Your Career in Web Development Starts Here | The Odin Project' %>
</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%= stylesheet_link_tag 'application', 'main', media: 'all', 'data-turbo-track': 'reload' %>
<%= javascript_include_tag 'main', 'data-turbo-track': 'reload', defer: true %>

<%= stylesheet_link_tag 'application', 'main', media: 'all', data: { turbo_track: 'reload' } %>
<%= render 'shared/sentry' %>
<%= render 'shared/analytics' %>
<%= javascript_include_tag 'main', defer: true, data: { turbo_track: 'reload' } %>
</head>
<body class="text-center h-screen m-0">
<main class="grid place-items-center min-h-screen">
Expand Down
13 changes: 13 additions & 0 deletions app/views/shared/_sentry.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% if Rails.env.production? %>
<script src="https://js.sentry-cdn.com/88c85c7e3b5b4548a663b61da9beea2a.min.js" crossorigin="anonymous"></script>

<script type='text/javascript'>
window.SENTRY_DSN = "<%= ENV['SENTRY_DSN'] %>"
window.currentUserSignedIn = "<%= user_signed_in? %>"

<% if defined?(current_user) && current_user.present? %>
window.currentUserId = "<%= current_user.id %>"
window.currentUserName = "<%= current_user.username %>"
<% end %>
</script>
<% end %>
13 changes: 9 additions & 4 deletions config/initializers/sentry.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
Sentry.init do |config|
config.dsn = ENV['SENTRY_DSN']
config.breadcrumbs_logger = [:active_support_logger]

config.enabled_environments = %w[production]
config.breadcrumbs_logger = %i[active_support_logger http_logger]
config.send_default_pii = true

# enable tracing
config.traces_sample_rate = 0.1

# enable profiling
# this is relative to traces_sample_rate
config.profiles_sample_rate = 1.0

filter = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters)
config.before_send = lambda { |event, _|
filter.filter(event.to_hash)
}

config.send_default_pii = true
end
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"@hotwired/stimulus": "^3.2.2",
"@hotwired/turbo-rails": "^8.0.2",
"@rails/request.js": "^0.0.9",
"@sentry/browser": "^7.108.0",
"@stimulus/polyfills": "^2.0.0",
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.10",
Expand Down
71 changes: 0 additions & 71 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.