Welcome to mirror list, hosted at ThFree Co, Russian Federation.

00_deprecations.rb « initializers « config - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c5f9833822dbf282ab9570957b5451afdd03fac5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

if Rails.env.production?
  ActiveSupport::Deprecation.silenced = !Gitlab::Utils.to_boolean(ENV['GITLAB_LOG_DEPRECATIONS'])
  ActiveSupport::Deprecation.behavior = :notify
  # Disallowed deprecation warnings are silenced in production. For performance
  # reasons we even skip the definition of `ActiveSupport::Deprecation.disallowed_warnings`
  # in production.
  # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/92557#note_1032212676 for benchmarks.
  ActiveSupport::Deprecation.disallowed_behavior = :silence
else
  ActiveSupport::Deprecation.silenced = false
  ActiveSupport::Deprecation.behavior = [:stderr, :notify]
  ActiveSupport::Deprecation.disallowed_behavior = :raise

  rails7_deprecation_warnings = [
    # https://gitlab.com/gitlab-org/gitlab/-/issues/366910
    /no longer takes non-deterministic result/,
    # https://gitlab.com/gitlab-org/gitlab/-/issues/339739
    /ActiveModel::Errors/,
    # https://gitlab.com/gitlab-org/gitlab/-/issues/342492
    /Rendering actions with '\.' in the name is deprecated/,
    # https://gitlab.com/gitlab-org/gitlab/-/issues/333086
    /default_hash is deprecated/,
    # https://gitlab.com/gitlab-org/gitlab/-/issues/369970
    /Passing an Active Record object to `\w+` directly is deprecated/
  ]

  ActiveSupport::Deprecation.disallowed_warnings = rails7_deprecation_warnings
end

unless ActiveSupport::Deprecation.silenced
  # Log deprecation warnings emitted through Kernel#warn, such as from gems or
  # the Ruby VM.
  actions = {
    /is deprecated/ => ->(warning) do
      Gitlab::DeprecationJsonLogger.info(message: warning.strip, source: 'ruby')
      # Returning :default means we continue emitting this to stderr as well.
      :default
    end
  }

  # Use `warning` gem to intercept Ruby warnings and add our own action hook.
  Warning.process('', actions)

  # Log deprecation warnings emitted from Rails (see ActiveSupport::Deprecation).
  ActiveSupport::Notifications.subscribe('deprecation.rails') do |_name, _start, _finish, _id, payload|
    Gitlab::DeprecationJsonLogger.info(message: payload[:message].strip, source: 'rails')
  end
end