scout_apm 2.0.0.pre7 → 2.0.0.pre8

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: c342425ce84acb55c8b62c2674eb94ec618746e6
4
- data.tar.gz: 64d5f991d966e16b108ab7e61737c4f6836958b2
3
+ metadata.gz: bdef63b6e4340550876655a7d9d8544e6667730d
4
+ data.tar.gz: af94bc60dd3364790210017f5615fa39b14e63ef
5
5
  SHA512:
6
- metadata.gz: fe0fc8bd013cb679a6eefcae6523fd7dd61023189550f4e2dd1d865328d6bfb40d04186496b3dd9184d02937e578fb8dee74e88028d2dc68d3ccbc40ab937256
7
- data.tar.gz: 6fd06f39a67c1f44549cb06c31129866cdf37a9f442225ff469667a86bab9a495252a4c6ac5c93135a54293df4e886743cad20d49cad78ccd9921b9704b73fe7
6
+ metadata.gz: b49b704dd2d10cc5ecc896e640f527cc0c4f740c3905ad786c4a651bf4b561f3d51585f73f9338afaaa61f05ecc979e0c8e6f375ad41c2989144bdb804ca5c5b
7
+ data.tar.gz: 9665d168ed2418c293c7f3fc73a0ab36919f34f5984dd38a756db30b1aa9f5383d01242c254a46603d15fabda5058b9e342ed097cc004312273d0f22f171c375
data/CHANGELOG.markdown CHANGED
@@ -10,6 +10,15 @@
10
10
  * Remove unused & old references to Stackprof
11
11
  * Fixing exception on load if no config file is provided
12
12
 
13
+ # 1.6.6
14
+
15
+ * Bugfix related to DB detection
16
+
17
+ # 1.6.5
18
+
19
+ * Add Mongoid 5.x support
20
+ * Fix autodetection of mysql databases
21
+
13
22
  # 1.6.4
14
23
 
15
24
  * Add Grape instrumentation
@@ -34,7 +34,8 @@ module ScoutApm
34
34
  :app_server => ScoutApm::Environment.instance.app_server,
35
35
  :ruby_version => RUBY_VERSION,
36
36
  :hostname => ScoutApm::Environment.instance.hostname,
37
- :database_engine => ScoutApm::Environment.instance.database_engine,
37
+ :database_engine => ScoutApm::Environment.instance.database_engine, # Detected
38
+ :database_adapter => ScoutApm::Environment.instance.raw_database_adapter, # Raw
38
39
  :application_name => ScoutApm::Environment.instance.application_name,
39
40
  :libraries => ScoutApm::Utils::InstalledGems.new.run,
40
41
  :paas => ScoutApm::Environment.instance.platform_integration.name
@@ -40,10 +40,10 @@ module ScoutApm
40
40
  # Load up a config instance, attempting to load a yaml file. Allows a
41
41
  # definite location if requested, or will attempt to load the default
42
42
  # configuration file: APP_ROOT/config/scout_apm.yml
43
- def self.with_file(file_path=nil)
43
+ def self.with_file(file_path=nil, config={})
44
44
  overlays = [
45
45
  ConfigEnvironment.new,
46
- ConfigFile.new(file_path),
46
+ ConfigFile.new(file_path, config[:file]),
47
47
  ConfigDefaults.new,
48
48
  ]
49
49
  new(overlays)
@@ -104,7 +104,8 @@ module ScoutApm
104
104
  # is not found, inaccessbile, or unparsable, log a message to that effect,
105
105
  # and move on.
106
106
  class ConfigFile
107
- def initialize(file_path=nil)
107
+ def initialize(file_path=nil, config={})
108
+ @config = config || {}
108
109
  @resolved_file_path = file_path || determine_file_path
109
110
  load_file(@resolved_file_path)
110
111
  end
@@ -162,9 +163,8 @@ module ScoutApm
162
163
  end
163
164
 
164
165
  def app_environment
165
- ScoutApm::Environment.instance.env
166
+ @config[:environment] || ScoutApm::Environment.instance.env
166
167
  end
167
-
168
168
  def logger
169
169
  if ScoutApm::Agent.instance.logger
170
170
  return ScoutApm::Agent.instance.logger
@@ -58,7 +58,13 @@ module ScoutApm
58
58
  end
59
59
 
60
60
  def reporter
61
- @reporter ||= ScoutApm::Reporter.new(:deploy_hook, ScoutApm::Agent.instance.config, @logger)
61
+ config = if env == ''
62
+ ScoutApm::Agent.instance.config
63
+ else
64
+ ScoutApm::Config.with_file(nil, {:file => { :environment => env }}) # instantiate our own config, with an overridden environment for the deploy-to app name instead of deploy-from app name)
65
+ end
66
+
67
+ @reporter ||= ScoutApm::Reporter.new(:deploy_hook, config, @logger)
62
68
  end
63
69
 
64
70
  def deploy_data
@@ -70,6 +70,10 @@ module ScoutApm
70
70
  framework_integration.database_engine
71
71
  end
72
72
 
73
+ def raw_database_adapter
74
+ framework_integration.raw_database_adapter
75
+ end
76
+
73
77
  def processors
74
78
  @processors ||= begin
75
79
  proc_file = '/proc/cpuinfo'
@@ -37,18 +37,14 @@ module ScoutApm
37
37
  default = :mysql
38
38
 
39
39
  if defined?(ActiveRecord::Base)
40
- config = ActiveRecord::Base.configurations[env]
41
- if config && config["adapter"]
42
- case config["adapter"].to_s
43
- when "postgres" then :postgres
44
- when "postgresql" then :postgres
45
- when "postgis" then :postgres
46
- when "sqlite3" then :sqlite
47
- when "mysql" then :mysql
48
- else default
49
- end
50
- else
51
- default
40
+ case raw_database_adapter
41
+ when "postgres" then :postgres
42
+ when "postgresql" then :postgres
43
+ when "postgis" then :postgres
44
+ when "sqlite3" then :sqlite
45
+ when "mysql" then :mysql
46
+ when "mysql2" then :mysql
47
+ else default
52
48
  end
53
49
  else
54
50
  default
@@ -56,6 +52,12 @@ module ScoutApm
56
52
  rescue
57
53
  default
58
54
  end
55
+
56
+ def raw_database_adapter
57
+ ActiveRecord::Base.configurations[env]["adapter"]
58
+ rescue
59
+ nil
60
+ end
59
61
  end
60
62
  end
61
63
  end
@@ -37,14 +37,16 @@ module ScoutApm
37
37
  default = :postgres
38
38
 
39
39
  @database_engine = if defined?(ActiveRecord::Base)
40
- adapter = get_database_adapter # can be nil
40
+ adapter = raw_database_adapter # can be nil
41
41
 
42
42
  case adapter.to_s
43
43
  when "postgres" then :postgres
44
44
  when "postgresql" then :postgres
45
45
  when "postgis" then :postgres
46
46
  when "sqlite3" then :sqlite
47
+ when "sqlite" then :sqlite
47
48
  when "mysql" then :mysql
49
+ when "mysql2" then :mysql
48
50
  else default
49
51
  end
50
52
  else
@@ -53,7 +55,7 @@ module ScoutApm
53
55
  end
54
56
  end
55
57
 
56
- def get_database_adapter
58
+ def raw_database_adapter
57
59
  adapter = if ActiveRecord::Base.respond_to?(:connection_config)
58
60
  ActiveRecord::Base.connection_config[:adapter].to_s
59
61
  else
@@ -30,6 +30,10 @@ module ScoutApm
30
30
  def database_engine
31
31
  :mysql
32
32
  end
33
+
34
+ def raw_database_adapter
35
+ :mysql
36
+ end
33
37
  end
34
38
  end
35
39
  end
@@ -37,6 +37,10 @@ module ScoutApm
37
37
  def database_engine
38
38
  :mysql
39
39
  end
40
+
41
+ def raw_database_adapter
42
+ :mysql
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -19,14 +19,86 @@ module ScoutApm
19
19
  if defined?(::Mongoid) and !defined?(::Moped)
20
20
  ScoutApm::Agent.instance.logger.info "Instrumenting Mongoid"
21
21
 
22
- ::Mongoid::Collection.class_eval do
23
- include ScoutApm::Tracer
24
- (::Mongoid::Collections::Operations::ALL - [:<<, :[]]).each do |method|
25
- instrument_method method, :type => "MongoDB", :name => '#{@klass}/' + method.to_s
22
+ ### OLD (2.x) mongoids
23
+ if defined?(::Mongoid::Collection)
24
+ ::Mongoid::Collection.class_eval do
25
+ include ScoutApm::Tracer
26
+ (::Mongoid::Collections::Operations::ALL - [:<<, :[]]).each do |method|
27
+ instrument_method method, :type => "MongoDB", :name => '#{@klass}/' + method.to_s
28
+ end
29
+ end
30
+ end
31
+
32
+ ### See moped instrument for Moped driven deploys
33
+
34
+ ### 5.x Mongoid
35
+ if mongoid_v5? && defined?(::Mongoid::Contextual::Mongo)
36
+ # All the public methods from Mongoid::Contextual::Mongo.
37
+ # TODO: Geo and MapReduce support (?). They are in other Contextual::* classes
38
+ methods = [
39
+ :count, :delete, :destroy, :distinct, :each,
40
+ :explain, :find_first, :find_one_and_delete, :find_one_and_replace,
41
+ :find_one_and_update, :first, :geo_near, :initialize, :last,
42
+ :length, :limit, :map, :map_reduce, :pluck,
43
+ :skip, :sort, :update, :update_all,
44
+ ]
45
+ # :exists?,
46
+
47
+ methods.each do |method|
48
+ if ::Mongoid::Contextual::Mongo.method_defined?(method)
49
+ with_scout_instruments = %Q|
50
+ def #{method}_with_scout_instruments(*args)
51
+
52
+ req = ScoutApm::RequestManager.lookup
53
+ *db, collection = view.collection.namespace.split(".")
54
+
55
+ name = collection + "/#{method}"
56
+ filter = ScoutApm::Instruments::Mongoid.anonymize_filter(view.filter)
57
+
58
+ layer = ScoutApm::Layer.new("MongoDB", name)
59
+ layer.desc = filter.inspect
60
+
61
+ req.start_layer( layer )
62
+ begin
63
+ #{method}_without_scout_instruments
64
+ ensure
65
+ req.stop_layer
66
+ end
67
+ end
68
+
69
+ alias_method :#{method}_without_scout_instruments, :#{method}
70
+ alias_method :#{method}, :#{method}_with_scout_instruments
71
+ |
72
+
73
+ ::Mongoid::Contextual::Mongo.class_eval(with_scout_instruments)
74
+ end
26
75
  end
27
76
  end
28
77
  end
29
78
  end
79
+
80
+ def mongoid_v5?
81
+ if defined?(::Mongoid::VERSION)
82
+ ::Mongoid::VERSION =~ /\A5/
83
+ else
84
+ false
85
+ end
86
+ end
87
+
88
+
89
+ # Example of what a filter looks like: => {"founded"=>{"$gte"=>"1980-1-1"}, "name"=>{"$in"=>["Tool", "Deftones", "Melvins"]}}
90
+ # Approach: find every leaf-node, clear it. inspect the whole thing when done.
91
+ def self.anonymize_filter(filter)
92
+ Hash[
93
+ filter.map do |k,v|
94
+ if v.is_a? Hash
95
+ [k, anonymize_filter(v)]
96
+ else
97
+ [k, "?"]
98
+ end
99
+ end
100
+ ]
101
+ end
30
102
  end
31
103
  end
32
104
  end
@@ -1,4 +1,4 @@
1
1
  module ScoutApm
2
- VERSION = "2.0.0.pre7"
2
+ VERSION = "2.0.0.pre8"
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: 2.0.0.pre7
4
+ version: 2.0.0.pre8
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: 2016-07-08 00:00:00.000000000 Z
12
+ date: 2016-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rusage