Sha256: 1dbabcef19366c84a32676cde6cd095c68de7261a68e86369b240d13237be746
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
# frozen_string_literal: true module SpartanAPM module Instrumentation # Base class for describing how to inject instrumentation code into another class. # This class should be extended and the subclass should set the klass, name, and methods # attributes in the constructor. class Base # The class that should be instrumented. attr_accessor :klass # The component name that metrics should be recorded as. attr_accessor :name # Flag indicating if metrics should be captured exclusively. attr_accessor :exclusive # List of instance methods to instrument. attr_accessor :methods # Inject instrumentation code into the specified class' methods. def instrument! raise ArgumentError.new("klass not specified") unless klass raise ArgumentError.new("name not specified") unless name Instrumentation.instrument!(klass, name, methods, exclusive: exclusive, module_name: "#{self.class.name.split("::").last}Instrumentation") end # Determine if the instrumentation definition is valid. def valid? return false if klass.nil? || name.nil? all_methods = klass.public_instance_methods + klass.protected_instance_methods + klass.private_instance_methods Array(methods).all? { |m| all_methods.include?(m) } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spartan_apm-0.0.0.rc1 | lib/spartan_apm/instrumentation/base.rb |