scout_apm 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +11 -0
- data/lib/scout_apm.rb +1 -0
- data/lib/scout_apm/agent.rb +10 -4
- data/lib/scout_apm/app_server_load.rb +1 -0
- data/lib/scout_apm/context.rb +79 -78
- data/lib/scout_apm/environment.rb +4 -3
- data/lib/scout_apm/server_integrations/null.rb +4 -0
- data/lib/scout_apm/server_integrations/passenger.rb +4 -0
- data/lib/scout_apm/server_integrations/puma.rb +4 -0
- data/lib/scout_apm/server_integrations/rainbows.rb +4 -0
- data/lib/scout_apm/server_integrations/thin.rb +4 -0
- data/lib/scout_apm/server_integrations/unicorn.rb +4 -0
- data/lib/scout_apm/server_integrations/webrick.rb +4 -0
- data/lib/scout_apm/utils/installed_gems.rb +18 -0
- data/lib/scout_apm/version.rb +1 -1
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: b13f09a100d1842c8aa30d4b494907796b30dac4
         | 
| 4 | 
            +
              data.tar.gz: 94b7e8b9ce5bc0a884db7df223728fda3d475dd6
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2692fa9370afc2fd71ae1c8a6985a535174ce0607b048dc5ceb653149b3fb2dfe2fdf2411f25f36f58f3bbfa46fa49bb79cf0fa929e74d4d6028596c3ebfafad
         | 
| 7 | 
            +
              data.tar.gz: 5529282c94ea75dbfb6f6c7bab6b12634880f6e8942452a510db90d9eac09857f8843d1658c1d252c4eab1b3bad5463aca69113a13f2a28eed60f68a35d61f30
         | 
    
        data/CHANGELOG.markdown
    CHANGED
    
    | @@ -1,3 +1,14 @@ | |
| 1 | 
            +
            # 0.1.10
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            * Prevent instrumentation in non-web contexts. Prevents agent running in rails
         | 
| 4 | 
            +
              console, sidekiq, and similar contexts.
         | 
| 5 | 
            +
            * Send active Gems with App Load message
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            # 0.1.9
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            * Added environment (production, development, etc) to App Load message
         | 
| 10 | 
            +
            * Bugfix in Reporter class
         | 
| 11 | 
            +
             | 
| 1 12 | 
             
            # 0.1.8
         | 
| 2 13 |  | 
| 3 14 | 
             
            * Ping APM on Application Load
         | 
    
        data/lib/scout_apm.rb
    CHANGED
    
    
    
        data/lib/scout_apm/agent.rb
    CHANGED
    
    | @@ -52,12 +52,12 @@ module ScoutApm | |
| 52 52 | 
             
                    return false
         | 
| 53 53 | 
             
                  end
         | 
| 54 54 |  | 
| 55 | 
            -
                  if ! | 
| 56 | 
            -
                    logger.warn "An application name  | 
| 55 | 
            +
                  if !environment.application_name
         | 
| 56 | 
            +
                    logger.warn "An application name could not be determined. Specify the :name value in scout_apm.yml. Not starting agent."
         | 
| 57 57 | 
             
                    return false
         | 
| 58 58 | 
             
                  end
         | 
| 59 59 |  | 
| 60 | 
            -
                  if !environment. | 
| 60 | 
            +
                  if !environment.app_server_integration.found?
         | 
| 61 61 | 
             
                    logger.warn "Couldn't find a supported app server. Not starting agent."
         | 
| 62 62 | 
             
                    return false
         | 
| 63 63 | 
             
                  end
         | 
| @@ -83,7 +83,8 @@ module ScoutApm | |
| 83 83 |  | 
| 84 84 | 
             
                  logger.info "Starting monitoring for [#{environment.application_name}]. Framework [#{environment.framework}] App Server [#{environment.app_server}]."
         | 
| 85 85 |  | 
| 86 | 
            -
                  load_instruments
         | 
| 86 | 
            +
                  load_instruments if should_load_instruments?
         | 
| 87 | 
            +
             | 
| 87 88 | 
             
                  @samplers = [
         | 
| 88 89 | 
             
                    ScoutApm::Instruments::Process::ProcessCpu.new(environment.processors, logger),
         | 
| 89 90 | 
             
                    ScoutApm::Instruments::Process::ProcessMemory.new(logger)
         | 
| @@ -168,9 +169,14 @@ module ScoutApm | |
| 168 169 | 
             
                  logger.debug "Done creating worker thread."
         | 
| 169 170 | 
             
                end
         | 
| 170 171 |  | 
| 172 | 
            +
                def should_load_instruments?
         | 
| 173 | 
            +
                  environment.app_server_integration.found?
         | 
| 174 | 
            +
                end
         | 
| 175 | 
            +
             | 
| 171 176 | 
             
                # Loads the instrumention logic.
         | 
| 172 177 | 
             
                def load_instruments
         | 
| 173 178 | 
             
                  logger.debug "Installing instrumentation"
         | 
| 179 | 
            +
             | 
| 174 180 | 
             
                  case environment.framework
         | 
| 175 181 | 
             
                  when :rails
         | 
| 176 182 | 
             
                    require File.expand_path(File.join(File.dirname(__FILE__),'instruments/rails/action_controller_instruments.rb'))
         | 
| @@ -24,6 +24,7 @@ module ScoutApm | |
| 24 24 | 
             
                    :hostname           => ScoutApm::Environment.instance.hostname,
         | 
| 25 25 | 
             
                    :database_engine    => ScoutApm::Environment.instance.database_engine,
         | 
| 26 26 | 
             
                    :application_name   => ScoutApm::Environment.instance.application_name,
         | 
| 27 | 
            +
                    :libraries          => ScoutApm::Utils::InstalledGems.new.run,
         | 
| 27 28 | 
             
                  }
         | 
| 28 29 | 
             
                end
         | 
| 29 30 | 
             
              end
         | 
    
        data/lib/scout_apm/context.rb
    CHANGED
    
    | @@ -3,103 +3,104 @@ | |
| 3 3 | 
             
            # There are 2 types of context: User and Extra.
         | 
| 4 4 | 
             
            # For user-specific context, use @Context#add_user@.
         | 
| 5 5 | 
             
            # For misc context, use @Context#add@.
         | 
| 6 | 
            -
             | 
| 6 | 
            +
            module ScoutApm
         | 
| 7 | 
            +
              class Context
         | 
| 8 | 
            +
                def initialize
         | 
| 9 | 
            +
                  @extra = {}
         | 
| 10 | 
            +
                  @user = {}
         | 
| 11 | 
            +
                end
         | 
| 7 12 |  | 
| 8 | 
            -
             | 
| 9 | 
            -
                 | 
| 10 | 
            -
                 | 
| 11 | 
            -
             | 
| 13 | 
            +
                # Generates a hash representation of the Context.
         | 
| 14 | 
            +
                # Example: {:monthly_spend => 100, :user => {:ip => '127.0.0.1'}}
         | 
| 15 | 
            +
                def to_hash
         | 
| 16 | 
            +
                  @extra.merge({:user => @user})
         | 
| 17 | 
            +
                end
         | 
| 12 18 |  | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
                @extra.merge({:user => @user})
         | 
| 17 | 
            -
              end
         | 
| 19 | 
            +
                def self.current
         | 
| 20 | 
            +
                  Thread.current[:scout_context] ||= new
         | 
| 21 | 
            +
                end
         | 
| 18 22 |  | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 23 | 
            +
                def self.clear!
         | 
| 24 | 
            +
                  Thread.current[:scout_context] = nil
         | 
| 25 | 
            +
                end
         | 
| 22 26 |  | 
| 23 | 
            -
             | 
| 24 | 
            -
                 | 
| 25 | 
            -
             | 
| 27 | 
            +
                # Add context
         | 
| 28 | 
            +
                # ScoutApm::Context.add(account: current_account.name)
         | 
| 29 | 
            +
                def add(hash)
         | 
| 30 | 
            +
                  update_context(:extra,hash)
         | 
| 31 | 
            +
                end
         | 
| 26 32 |  | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
                update_context(:extra,hash)
         | 
| 31 | 
            -
              end
         | 
| 33 | 
            +
                def add_user(hash)
         | 
| 34 | 
            +
                  update_context(:user,hash)
         | 
| 35 | 
            +
                end
         | 
| 32 36 |  | 
| 33 | 
            -
             | 
| 34 | 
            -
                 | 
| 35 | 
            -
             | 
| 37 | 
            +
                # Convenience accessor so you can just call @ScoutAPM::Context#add@
         | 
| 38 | 
            +
                def self.add(hash)
         | 
| 39 | 
            +
                  self.current.add(hash)
         | 
| 40 | 
            +
                end
         | 
| 36 41 |  | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 42 | 
            +
                # Convenience accessor so you can just call @ScoutAPM::Context#add_user@
         | 
| 43 | 
            +
                def self.add_user(hash)
         | 
| 44 | 
            +
                  self.current.add_user(hash)
         | 
| 45 | 
            +
                end
         | 
| 41 46 |  | 
| 42 | 
            -
             | 
| 43 | 
            -
              def self.add_user(hash)
         | 
| 44 | 
            -
                self.current.add_user(hash)
         | 
| 45 | 
            -
              end
         | 
| 47 | 
            +
                private
         | 
| 46 48 |  | 
| 47 | 
            -
             | 
| 49 | 
            +
                def update_context(attr,hash)
         | 
| 50 | 
            +
                  valid_hash = Hash.new
         | 
| 51 | 
            +
                  # iterate over the hash of new context, adding to the valid_hash if validation checks pass.
         | 
| 52 | 
            +
                  hash.each do |key,value|
         | 
| 53 | 
            +
                    # does both checks so we can get logging info on the value even if the key is invalid.
         | 
| 54 | 
            +
                    key_valid = key_valid?({key => value})
         | 
| 55 | 
            +
                    value_valid = value_valid?({key => value})
         | 
| 56 | 
            +
                    if key_valid and value_valid
         | 
| 57 | 
            +
                      valid_hash[key] = value
         | 
| 58 | 
            +
                    end
         | 
| 59 | 
            +
                  end
         | 
| 48 60 |  | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
                # iterate over the hash of new context, adding to the valid_hash if validation checks pass.
         | 
| 52 | 
            -
                hash.each do |key,value|
         | 
| 53 | 
            -
                  # does both checks so we can get logging info on the value even if the key is invalid.
         | 
| 54 | 
            -
                  key_valid = key_valid?({key => value})
         | 
| 55 | 
            -
                  value_valid = value_valid?({key => value})
         | 
| 56 | 
            -
                  if key_valid and value_valid
         | 
| 57 | 
            -
                    valid_hash[key] = value
         | 
| 61 | 
            +
                  if valid_hash.any?
         | 
| 62 | 
            +
                    instance_variable_get("@#{attr.to_s}").merge!(valid_hash)
         | 
| 58 63 | 
             
                  end
         | 
| 59 64 | 
             
                end
         | 
| 60 65 |  | 
| 61 | 
            -
                if  | 
| 62 | 
            -
             | 
| 66 | 
            +
                # Returns true if the obj is one of the provided valid classes.
         | 
| 67 | 
            +
                def valid_type?(classes, obj)
         | 
| 68 | 
            +
                  valid_type = false
         | 
| 69 | 
            +
                  classes.each do |klass|
         | 
| 70 | 
            +
                    if obj.is_a?(klass)
         | 
| 71 | 
            +
                      valid_type = true
         | 
| 72 | 
            +
                      break
         | 
| 73 | 
            +
                    end
         | 
| 74 | 
            +
                  end
         | 
| 75 | 
            +
                  valid_type
         | 
| 63 76 | 
             
                end
         | 
| 64 | 
            -
              end
         | 
| 65 77 |  | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
                  if  | 
| 71 | 
            -
                     | 
| 72 | 
            -
             | 
| 78 | 
            +
                # take the entire Hash vs. just the value so the logger output is more helpful on error.
         | 
| 79 | 
            +
                def value_valid?(key_value)
         | 
| 80 | 
            +
                  # ensure one of our accepted types.
         | 
| 81 | 
            +
                  value = key_value.values.last
         | 
| 82 | 
            +
                  if !valid_type?([String, Symbol, Numeric, Time, Date, TrueClass, FalseClass],value)
         | 
| 83 | 
            +
                    ScoutApm::Agent.instance.logger.warn "The value for [#{key_value.keys.first}] is not a valid type [#{value.class}]."
         | 
| 84 | 
            +
                  false
         | 
| 85 | 
            +
                  else
         | 
| 86 | 
            +
                    true
         | 
| 73 87 | 
             
                  end
         | 
| 74 88 | 
             
                end
         | 
| 75 | 
            -
                valid_type
         | 
| 76 | 
            -
              end
         | 
| 77 89 |  | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 90 | 
            +
                # for consistently with #value_valid?, takes a hash eventhough the value isn't yet used.
         | 
| 91 | 
            +
                def key_valid?(key_value)
         | 
| 92 | 
            +
                  key = key_value.keys.first
         | 
| 93 | 
            +
                  # ensure a string or a symbol
         | 
| 94 | 
            +
                  if !valid_type?([String, Symbol],key)
         | 
| 95 | 
            +
                    ScoutApm::Agent.instance.logger.warn "The key [#{key}] is not a valid type [#{key.class}]."
         | 
| 96 | 
            +
                    return false
         | 
| 97 | 
            +
                  end
         | 
| 98 | 
            +
                  # only alphanumeric, dash, and underscore allowed.
         | 
| 99 | 
            +
                  if key.to_s.match(/[^\w-]/)
         | 
| 100 | 
            +
                    ScoutApm::Agent.instance.logger.warn "They key name [#{key}] is not valid."
         | 
| 101 | 
            +
                    return false
         | 
| 102 | 
            +
                  end
         | 
| 86 103 | 
             
                  true
         | 
| 87 104 | 
             
                end
         | 
| 88 105 | 
             
              end
         | 
| 89 | 
            -
             | 
| 90 | 
            -
              # for consistently with #value_valid?, takes a hash eventhough the value isn't yet used.
         | 
| 91 | 
            -
              def key_valid?(key_value)
         | 
| 92 | 
            -
                key = key_value.keys.first
         | 
| 93 | 
            -
                # ensure a string or a symbol
         | 
| 94 | 
            -
                if !valid_type?([String, Symbol],key)
         | 
| 95 | 
            -
                  ScoutApm::Agent.instance.logger.warn "The key [#{key}] is not a valid type [#{key.class}]."
         | 
| 96 | 
            -
                  return false
         | 
| 97 | 
            -
                end
         | 
| 98 | 
            -
                # only alphanumeric, dash, and underscore allowed.
         | 
| 99 | 
            -
                if key.to_s.match(/[^\w-]/)
         | 
| 100 | 
            -
                  ScoutApm::Agent.instance.logger.warn "They key name [#{key}] is not valid."
         | 
| 101 | 
            -
                  return false
         | 
| 102 | 
            -
                end
         | 
| 103 | 
            -
                true
         | 
| 104 | 
            -
              end
         | 
| 105 106 | 
             
            end
         | 
| @@ -47,9 +47,10 @@ module ScoutApm | |
| 47 47 | 
             
                    config = ActiveRecord::Base.connection_config
         | 
| 48 48 | 
             
                    if config && config[:adapter]
         | 
| 49 49 | 
             
                      case config[:adapter]
         | 
| 50 | 
            -
                      when "postgres" | 
| 51 | 
            -
                      when " | 
| 52 | 
            -
                      when " | 
| 50 | 
            +
                      when "postgres"   then :postgres
         | 
| 51 | 
            +
                      when "postgresql" then :postgres
         | 
| 52 | 
            +
                      when "sqlite3"    then :sqlite
         | 
| 53 | 
            +
                      when "mysql"      then :mysql
         | 
| 53 54 | 
             
                      else default
         | 
| 54 55 | 
             
                      end
         | 
| 55 56 | 
             
                    else
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            module ScoutApm
         | 
| 2 | 
            +
              module Utils
         | 
| 3 | 
            +
                class InstalledGems
         | 
| 4 | 
            +
                  attr_reader :logger
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def initialize(logger=ScoutApm::Agent.instance.logger)
         | 
| 7 | 
            +
                    @logger = logger
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def run
         | 
| 11 | 
            +
                    Bundler.rubygems.all_specs.map {|spec| [spec.name, spec.version.to_s] }
         | 
| 12 | 
            +
                  rescue => e
         | 
| 13 | 
            +
                    logger.warn("Couldn't fetch Gem information: #{e.message}")
         | 
| 14 | 
            +
                    []
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
            end
         | 
    
        data/lib/scout_apm/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: scout_apm
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.10
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Derek Haynes
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2015-08- | 
| 12 | 
            +
            date: 2015-08-31 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: minitest
         | 
| @@ -107,6 +107,7 @@ files: | |
| 107 107 | 
             
            - lib/scout_apm/stack_item.rb
         | 
| 108 108 | 
             
            - lib/scout_apm/store.rb
         | 
| 109 109 | 
             
            - lib/scout_apm/tracer.rb
         | 
| 110 | 
            +
            - lib/scout_apm/utils/installed_gems.rb
         | 
| 110 111 | 
             
            - lib/scout_apm/utils/null_logger.rb
         | 
| 111 112 | 
             
            - lib/scout_apm/utils/sql_sanitizer.rb
         | 
| 112 113 | 
             
            - lib/scout_apm/utils/sql_sanitizer_regex.rb
         |