Log Ruby and Rails deprecations
What does this MR do?
We are working on Ruby 3 compatibility, and a common source of problems has been deprecations that were warnings in Ruby 2.7 and have turned into errors in Ruby 3.
We already detect some of these in CI, but for anything that is not covered by tests, we also want to make sure we catch it in production before switching to the new VM.
To that end this MR introduces a new logger, Gitlab::DeprecationJsonLogger
, which logs to a new file log/deprecation_json.log
. The logger uses a two-pronged approach:
- For Ruby(-gem)s deprecation warnings, it utilizes the
ruby-warning
gem to log deprecation warnings emitted throughKernel#warn
to our logger. This will still output them to stderr as well. - For Rails deprecation warnings, it hooks into Rails'
deprecation.rails
warning via anActiveSupport::Notifications
subscriber.
This is done in a new initializer that runs early on in the initializer chain (though there might be code that executes in front of it, that should be OK, since we're mostly looking for unknown issues elsewhere in the code base here.)
NOTE that this behavior is enabled only in development
by default. Other environments needs to opt-in via the GITLAB_LOG_DEPRECATIONS
env var. This seemed like the safest approach to me. I tried using FFs but failed, since some rake tasks that were emitting warnings this way were crashing due to the database not being up.
Sample output:
{
"severity": "INFO",
"time": "2021-07-26T11:41:35.056Z",
"correlation_id": "cec7a2ef0e3bd1ace12433c505a660b5",
"message": "DEPRECATION WARNING: ABC will be removed (called from block (3 levels) in <main> at /home/git/gitlab/spec/initializers/0_log_deprecations_spec.rb:31)"
"source": "rails"
}
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) - [-] I have tested this MR in all supported browsers, or it's not needed.
-
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Related to #333330 (closed)