scout_apm 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36adf5a7555ede28d15fa10c9998f5f0bb033a68
4
- data.tar.gz: 669e743655d365c1ffbe9f6f286386f374784a50
3
+ metadata.gz: b13f09a100d1842c8aa30d4b494907796b30dac4
4
+ data.tar.gz: 94b7e8b9ce5bc0a884db7df223728fda3d475dd6
5
5
  SHA512:
6
- metadata.gz: 01b264703cdaa45a38dd705afec5726211b2a1c23e575c4a0fb0a9f86edbb738cd6aecbaf99e0a828da217abdc5df22850195954e11fd2f9dde7514730e13497
7
- data.tar.gz: bc2f83e3448c141529e24ffd7acaa774ea884665aedcc88879830bd99486225d88f5ed2b099db667ba056dfbf9acb7b86381fe972de6f55865c89899b2724888
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
@@ -28,6 +28,7 @@ require 'scout_apm/app_server_load'
28
28
 
29
29
  require 'scout_apm/utils/sql_sanitizer'
30
30
  require 'scout_apm/utils/null_logger'
31
+ require 'scout_apm/utils/installed_gems'
31
32
  require 'scout_apm/config'
32
33
  require 'scout_apm/environment'
33
34
  require 'scout_apm/agent'
@@ -52,12 +52,12 @@ module ScoutApm
52
52
  return false
53
53
  end
54
54
 
55
- if !Environment.instance.application_name
56
- logger.warn "An application name is required. Specify the :name value in scout_apm.yml. Not starting agent."
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.app_server
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
@@ -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
- class ScoutApm::Context
6
+ module ScoutApm
7
+ class Context
8
+ def initialize
9
+ @extra = {}
10
+ @user = {}
11
+ end
7
12
 
8
- def initialize
9
- @extra = {}
10
- @user = {}
11
- end
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
- # 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
19
+ def self.current
20
+ Thread.current[:scout_context] ||= new
21
+ end
18
22
 
19
- def self.current
20
- Thread.current[:scout_context] ||= new
21
- end
23
+ def self.clear!
24
+ Thread.current[:scout_context] = nil
25
+ end
22
26
 
23
- def self.clear!
24
- Thread.current[:scout_context] = nil
25
- end
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
- # Add context
28
- # ScoutApm::Context.add(account: current_account.name)
29
- def add(hash)
30
- update_context(:extra,hash)
31
- end
33
+ def add_user(hash)
34
+ update_context(:user,hash)
35
+ end
32
36
 
33
- def add_user(hash)
34
- update_context(:user,hash)
35
- end
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
- # Convenience accessor so you can just call @ScoutAPM::Context#add@
38
- def self.add(hash)
39
- self.current.add(hash)
40
- end
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
- # 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
47
+ private
46
48
 
47
- private
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
- 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
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 valid_hash.any?
62
- instance_variable_get("@#{attr.to_s}").merge!(valid_hash)
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
- # 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
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
- # 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
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" then :postgres
51
- when "sqlite3" then :sqlite
52
- when "mysql" then :mysql
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
@@ -25,6 +25,10 @@ module ScoutApm
25
25
  def forking?
26
26
  false
27
27
  end
28
+
29
+ def found?
30
+ false
31
+ end
28
32
  end
29
33
  end
30
34
  end
@@ -30,6 +30,10 @@ module ScoutApm
30
30
  ScoutApm::Agent.instance.shutdown
31
31
  end
32
32
  end
33
+
34
+ def found?
35
+ true
36
+ end
33
37
  end
34
38
  end
35
39
  end
@@ -25,6 +25,10 @@ module ScoutApm
25
25
  rescue
26
26
  logger.warn "Unable to install Puma worker loop: #{$!.message}"
27
27
  end
28
+
29
+ def found?
30
+ true
31
+ end
28
32
  end
29
33
  end
30
34
  end
@@ -31,6 +31,10 @@ module ScoutApm
31
31
  end
32
32
  end
33
33
  end
34
+
35
+ def found?
36
+ true
37
+ end
34
38
  end
35
39
  end
36
40
  end
@@ -35,6 +35,10 @@ module ScoutApm
35
35
  # TODO: What does it mean to install on a non-forking env?
36
36
  def install
37
37
  end
38
+
39
+ def found?
40
+ true
41
+ end
38
42
  end
39
43
  end
40
44
  end
@@ -30,6 +30,10 @@ module ScoutApm
30
30
  end
31
31
  end
32
32
  end
33
+
34
+ def found?
35
+ true
36
+ end
33
37
  end
34
38
  end
35
39
  end
@@ -20,6 +20,10 @@ module ScoutApm
20
20
  # TODO: What does it mean to install on a non-forking env?
21
21
  def install
22
22
  end
23
+
24
+ def found?
25
+ true
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -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
@@ -1,4 +1,4 @@
1
1
  module ScoutApm
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
4
4
 
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.9
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-27 00:00:00.000000000 Z
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