Skip to content

Show request ID on 500 error page

Sean McGivern requested to merge add-correlation-id-to-500-page into master

This adds a custom exceptions app that replaces a magic HTML comment in an error page with some HTML displaying the request ID to the user. It also adds that magic comment to the 500 error page, where it's most useful (as we will want to look up the stack trace corresponding to that request ID for a 500 error).

The reasons for making this a magic HTML comment are:

  1. We don't need separate files that may drift apart from each other. An earlier version of this change added a new 500.html.erb file, which was almost identical to 500.html, just with the addition of some ERb code. If we changed one of those files, we'd need to change both.
  2. If we disable this app, or it doesn't get called for some reason, the user will see no difference in the rendered output.
  3. Similar to the above two reasons, these error pages in public/ are also used by Workhorse in some circumstances to replace the content sent by Rails. This is why we set the X-Gitlab-Custom-Error header when modifying the body, so that Workhorse does not then overwrite the HTML we want to send.

In other words, this should be a purely additive change: if it works, great; if it doesn't, then there should be no difference.

Testing

We can use this diff:

diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 26f56307862..6dafe1fddb5 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -27,6 +27,8 @@ class UsersController < ApplicationController
   feature_category :users
 
   def show
+    raise 'uh oh'
+
     respond_to do |format|
       format.html
 
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 076957f3057..aeccbeaf006 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -10,7 +10,7 @@
 
   # Show full error reports and disable caching
   config.active_record.verbose_query_logs  = true
-  config.consider_all_requests_local       = true
+  config.consider_all_requests_local       = false
 
   if Rails.root.join('tmp', 'caching-dev.txt').exist?
     config.action_controller.perform_caching = true

It's also a good idea to remove -developmentMode from $gdk_root/Procfile's `gitlab-workhorse line, to ensure that Workhorse isn't skipping its own error handler: !77377 (comment 802027702)

Then, visiting a user's profile page will give a 500 error:

image

For #34113 (closed).

Edited by Sean McGivern

Merge request reports