config/initializers/zz_metrics.rb
# Autoload all classes that we want to instrument, and instrument the methods we
# need. This takes the Gitlab::Metrics::Instrumentation module as an argument so
# that we can stub it for testing, as it is only called when metrics are
# enabled.
#
# rubocop:disable Metrics/AbcSize
Autoload all classes that we want to instrument, and instrument the methods we
need. This takes the Gitlab::Metrics::Instrumentation module as an argument so
that we can stub it for testing, as it is only called when metrics are
enabled.


Autoload all classes that we want to instrument and instrument the methods we need . This takes the Gitlab :: Metrics :: Instrumentation module as an argument so that we can stub it for testing as it is only called when metrics are enabled .
def instrument_classes(instrumentation)
  instrumentation.instrument_instance_methods(Gitlab::Shell)
  instrumentation.instrument_methods(Gitlab::Git)
  Gitlab::Git.constants.each do |name|
    const = Gitlab::Git.const_get(name, false)
    next unless const.is_a?(Module)
    instrumentation.instrument_methods(const)
    instrumentation.instrument_instance_methods(const)
  end
  paths_to_instrument = {
    %w(app finders)                => %w(app finders),
    %w(app mailers emails)         => %w(app mailers),
    %w(app services [^concerns]**) => %w(app services),
    %w(lib gitlab conflicts)       => ['lib'],
    %w(lib gitlab email message)   => ['lib'],
    %w(lib gitlab checks)          => ['lib']
  }
  paths_to_instrument.each do |(path, prefix)|
    prefix = Rails.root.join(*prefix)
    Dir[Rails.root.join(*path + ['*.rb'])].each do |file_path|
      path = Pathname.new(file_path).relative_path_from(prefix)
      const = path.to_s.sub('.rb', '').camelize.constantize
      instrumentation.instrument_methods(const)
      instrumentation.instrument_instance_methods(const)
    end
  end
  instrumentation.instrument_methods(Premailer::Adapter::Nokogiri)
  instrumentation.instrument_instance_methods(Premailer::Adapter::Nokogiri)
  instrumentation.instrument_methods(Banzai::Renderer)
  instrumentation.instrument_methods(Banzai::Querying)
  instrumentation.instrument_instance_methods(Banzai::ObjectRenderer)
  instrumentation.instrument_instance_methods(Banzai::ReferenceRedactor)
  [Issuable, Mentionable, Participable].each do |klass|
    instrumentation.instrument_instance_methods(klass)
    instrumentation.instrument_instance_methods(klass::ClassMethods)
  end
  instrumentation.instrument_methods(Gitlab::ReferenceExtractor)
  instrumentation.instrument_instance_methods(Gitlab::ReferenceExtractor)
  instrumentation.instrument_instance_methods(Gitlab::GitAccess)
  instrumentation.instrument_instance_methods(Gitlab::GitAccessWiki)
  instrumentation.instrument_instance_methods(API::Helpers)
  instrumentation.instrument_instance_methods(RepositoryCheck::SingleRepositoryWorker)
  instrumentation.instrument_instance_methods(Rouge::Formatters::HTMLGitlab)
  [:XML, :HTML].each do |namespace|
    namespace_mod = Nokogiri.const_get(namespace, false)
    instrumentation.instrument_methods(namespace_mod)
    instrumentation.instrument_methods(namespace_mod::Document)
  end
  instrumentation.instrument_methods(Rinku)
  instrumentation.instrument_instance_methods(Repository)
  instrumentation.instrument_methods(Gitlab::Highlight)
  instrumentation.instrument_instance_methods(Gitlab::Highlight)
  Gitlab.ee do
    instrumentation.instrument_instance_methods(Elastic::Latest::GitInstanceProxy)
    instrumentation.instrument_instance_methods(Elastic::Latest::GitClassProxy)
    instrumentation.instrument_instance_methods(Search::GlobalService)
    instrumentation.instrument_instance_methods(Search::ProjectService)
    instrumentation.instrument_instance_methods(Gitlab::Elastic::SearchResults)
    instrumentation.instrument_instance_methods(Gitlab::Elastic::ProjectSearchResults)
    instrumentation.instrument_instance_methods(Gitlab::Elastic::Indexer)
    instrumentation.instrument_instance_methods(Gitlab::Elastic::SnippetSearchResults)
    instrumentation.instrument_methods(Gitlab::Elastic::Helper)
    instrumentation.instrument_instance_methods(Elastic::ApplicationVersionedSearch)
    instrumentation.instrument_instance_methods(Elastic::ProjectsSearch)
    instrumentation.instrument_instance_methods(Elastic::RepositoriesSearch)
    instrumentation.instrument_instance_methods(Elastic::SnippetsSearch)
    instrumentation.instrument_instance_methods(Elastic::WikiRepositoriesSearch)
    instrumentation.instrument_instance_methods(Gitlab::BitbucketImport::Importer)
    instrumentation.instrument_instance_methods(Bitbucket::Connection)
    instrumentation.instrument_instance_methods(Geo::RepositorySyncWorker)
  end
  instrumentation.instrument_method(Project, :visible_to_user)
  instrumentation.instrument_instance_method(MergeRequestDiff, :load_commits)
end
def instrument_classes ( instrumentation ) instrumentation . instrument_instance_methods ( Gitlab :: Shell ) instrumentation . instrument_methods ( Gitlab :: Git ) Gitlab :: Git . constants . each do | name | const = Gitlab :: Git . const_get ( name , false ) next unless const . is_a? ( Module ) instrumentation . instrument_methods ( const ) instrumentation . instrument_instance_methods ( const ) end paths_to_instrument = { %w( app finders ) => %w( app finders ) , %w( app mailers emails ) => %w( app mailers ) , %w( app services [^concerns]** ) => %w( app services ) , %w( lib gitlab conflicts ) => [ 'lib' ] , %w( lib gitlab email message ) => [ 'lib' ] , %w( lib gitlab checks ) => [ 'lib' ] } paths_to_instrument . each do | ( path , prefix ) | prefix = Rails . root . join ( * prefix ) Dir [ Rails . root . join ( * path + [ '*.rb' ] ) ] . each do | file_path | path = Pathname . new ( file_path ) . relative_path_from ( prefix ) const = path . to_s . sub ( '.rb' , '' ) . camelize . constantize instrumentation . instrument_methods ( const ) instrumentation . instrument_instance_methods ( const ) end end instrumentation . instrument_methods ( Premailer :: Adapter :: Nokogiri ) instrumentation . instrument_instance_methods ( Premailer :: Adapter :: Nokogiri ) instrumentation . instrument_methods ( Banzai :: Renderer ) instrumentation . instrument_methods ( Banzai :: Querying ) instrumentation . instrument_instance_methods ( Banzai :: ObjectRenderer ) instrumentation . instrument_instance_methods ( Banzai :: ReferenceRedactor ) [ Issuable , Mentionable , Participable ] . each do | klass | instrumentation . instrument_instance_methods ( klass ) instrumentation . instrument_instance_methods ( klass :: ClassMethods ) end instrumentation . instrument_methods ( Gitlab :: ReferenceExtractor ) instrumentation . instrument_instance_methods ( Gitlab :: ReferenceExtractor ) instrumentation . instrument_instance_methods ( Gitlab :: GitAccess ) instrumentation . instrument_instance_methods ( Gitlab :: GitAccessWiki ) instrumentation . instrument_instance_methods ( API :: Helpers ) instrumentation . instrument_instance_methods ( RepositoryCheck :: SingleRepositoryWorker ) instrumentation . instrument_instance_methods ( Rouge :: Formatters :: HTMLGitlab ) [ :XML , :HTML ] . each do | namespace | namespace_mod = Nokogiri . const_get ( namespace , false ) instrumentation . instrument_methods ( namespace_mod ) instrumentation . instrument_methods ( namespace_mod :: Document ) end instrumentation . instrument_methods ( Rinku ) instrumentation . instrument_instance_methods ( Repository ) instrumentation . instrument_methods ( Gitlab :: Highlight ) instrumentation . instrument_instance_methods ( Gitlab :: Highlight ) Gitlab . ee do instrumentation . instrument_instance_methods ( Elastic :: Latest :: GitInstanceProxy ) instrumentation . instrument_instance_methods ( Elastic :: Latest :: GitClassProxy ) instrumentation . instrument_instance_methods ( Search :: GlobalService ) instrumentation . instrument_instance_methods ( Search :: ProjectService ) instrumentation . instrument_instance_methods ( Gitlab :: Elastic :: SearchResults ) instrumentation . instrument_instance_methods ( Gitlab :: Elastic :: ProjectSearchResults ) instrumentation . instrument_instance_methods ( Gitlab :: Elastic :: Indexer ) instrumentation . instrument_instance_methods ( Gitlab :: Elastic :: SnippetSearchResults ) instrumentation . instrument_methods ( Gitlab :: Elastic :: Helper ) instrumentation . instrument_instance_methods ( Elastic :: ApplicationVersionedSearch ) instrumentation . instrument_instance_methods ( Elastic :: ProjectsSearch ) instrumentation . instrument_instance_methods ( Elastic :: RepositoriesSearch ) instrumentation . instrument_instance_methods ( Elastic :: SnippetsSearch ) instrumentation . instrument_instance_methods ( Elastic :: WikiRepositoriesSearch ) instrumentation . instrument_instance_methods ( Gitlab :: BitbucketImport :: Importer ) instrumentation . instrument_instance_methods ( Bitbucket :: Connection ) instrumentation . instrument_instance_methods ( Geo :: RepositorySyncWorker ) end instrumentation . instrument_method ( Project , :visible_to_user ) instrumentation . instrument_instance_method ( MergeRequestDiff , :load_commits ) end
Autoload all classes that we want to instrument, and instrument the methods we
need.
Autoload all classes that we want to instrument and instrument the methods we need .
# Path to search => prefix to strip from constant # Don't instrument `app/services/concerns` # It contains modules that are included in the services. # The services themselves are instrumented so the methods from the modules # are included. # Instrument the classes used for checking if somebody has push access. # This is a Rails scope so we have to instrument it manually. # Needed for https://gitlab.com/gitlab-org/gitlab-foss/issues/30224#note_32306159
instrumentation
<not_specific>