scout_apm 1.6.4 → 1.6.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4a68db2ae2d5615f89aacc3c015909ee24bc49f
4
- data.tar.gz: e21486b451e768a573c10615042c9b2d183bbb47
3
+ metadata.gz: 63ae601480e206eabc6a2a0f9d5b4a910ff1b96b
4
+ data.tar.gz: 62e2cc35685a98a5ecb13432166ad0b31e5957ec
5
5
  SHA512:
6
- metadata.gz: b6c77fd02eb44509a79f883e27ff4e306e6c96cf063481a617968d0e3b5bd8d6ad9125b3b39247879dfa3c0daba032a48f74c2ddce392fa87864d45aae5a35dd
7
- data.tar.gz: feaf556828e488ebc3c15d951af248ede825af9b2a47b8a13428da6516e4ae377c672564e1594c42370368f784b0d68f2b4eff4d1d82d152a6ad5206d0122a0e
6
+ metadata.gz: 2de68e360bb022bfa74f2442f57fc84fc7914b084c3ef5c21870e79453197a7c2fb6744179f02d4ffbaabe4bbd265c586df0d9d3327f4a0628803bb11bf9de64
7
+ data.tar.gz: 876b496318c21489278202605167d6879636c8363247df4da87301b19625f8a9f691a1b6e71a6ed905ef3af12da2ebd103763fbbb2f3c2bc9b2fdb4a8d3bdaa3
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.6.5
2
+
3
+ * Add Mongoid 5.x support
4
+ * Fix autodetection of mysql databases
5
+
1
6
  # 1.6.4
2
7
 
3
8
  * 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
@@ -37,7 +37,6 @@ module ScoutApm
37
37
  default = :mysql
38
38
 
39
39
  if defined?(ActiveRecord::Base)
40
- config = ActiveRecord::Base.configurations[env]
41
40
  if config && config["adapter"]
42
41
  case config["adapter"].to_s
43
42
  when "postgres" then :postgres
@@ -45,6 +44,7 @@ module ScoutApm
45
44
  when "postgis" then :postgres
46
45
  when "sqlite3" then :sqlite
47
46
  when "mysql" then :mysql
47
+ when "mysql2" then :mysql
48
48
  else default
49
49
  end
50
50
  else
@@ -56,6 +56,12 @@ module ScoutApm
56
56
  rescue
57
57
  default
58
58
  end
59
+
60
+ def raw_database_adapter
61
+ ActiveRecord::Base.configurations[env]["adapter"]
62
+ rescue
63
+ nil
64
+ end
59
65
  end
60
66
  end
61
67
  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 = "1.6.4"
2
+ VERSION = "1.6.5"
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: 1.6.4
4
+ version: 1.6.5
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-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest