Sha256: c587f875e8a5a94b57c06da71ed2c8ac2380137f8a28a8e0395a877cf2bcb13b

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

# encoding: utf-8

require 'one_apm/support/library_detection'

module OneApm
  class Probe
    module Instrumentation

      # install instrumentations for the current framework
      def install_instrumentation
        return if @instrumented

        @instrumented = true

        # Instrumentation for the key code points inside rails for monitoring by OneApm.
        # note this file is loaded only if the oneapm agent is enabled (through config/oneapm.yml)
        instrumentation_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'inst'))
        Dir.glob("#{instrumentation_path}/**/*.rb").each do |inst_file|
          load_instrumentation_files inst_file
        end
        detect_dependencies
        OneApm::Manager.logger.info "Finished instrumentation"
      end

      def load_instrumentation_files pattern
        Dir.glob(pattern) { |file| require_instrumentation(file.to_s) }
      end

      def detect_dependencies
        LibraryDetection.detect!
      end

      # require specified instrumentation
      def require_instrumentation file
        require file
      rescue => e
        OneApm::Manager.logger.warn "Error loading instrumentation file '#{file}':", e
      end

      def install_shim
        # Once we install instrumentation, you can't undo that by installing the shim.
        if @instrumented
          OneApm::Manager.logger.error "Cannot install the Agent shim after instrumentation has already been installed!"
          OneApm::Manager.logger.error caller.join("\n")
        else
          OneApm::Manager.agent = OneApm::Agent::ShimAgent.instance
        end
      end

      def add_instrumentation pattern
        if @instrumented
          load_instrumentation_files pattern
        else
          @instrumentation_files << pattern
        end
      end
    end
    include Instrumentation
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oneapm_rpm-1.1.3 lib/one_apm/probe/instrumentation.rb