stackify-ruby-apm 1.14.5 → 1.14.7

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
  SHA256:
3
- metadata.gz: 81a16e2527e1237952803d7082cd0869b932e2af04dd3263490e5bd6538debbd
4
- data.tar.gz: 3df0659ad3e96984f67c9850e69f38c20fae65ced83948b2791a2a9fe63012af
3
+ metadata.gz: 881446a181c81d422cdd81f2de4b4ccef409989171d96a53833bbe425f8105c0
4
+ data.tar.gz: ed31e237779e881ab4a57d7db2c4dcc7936bbe01b6af256ac4f53d9ae4c96054
5
5
  SHA512:
6
- metadata.gz: d6a34b33a19b3a59c69fdfa105255b234a77b3be6b81a0bbdac68bc39bdc92eb327c33d236d49beb064dafe87b6f4e882df53fb29365b2152572f4d9cf7fdf08
7
- data.tar.gz: e05ee709696f67a2bb4c7780a2b762393f5be5507c3af5b327c825e500fd3a18786827f2ba2e8d98df8e926af6cc2d4a5dc79fd380f8392fdd8443e04a998c5c
6
+ metadata.gz: 293677dce94cf22be5e9a45fb1e7d9b7090fcbbe76a4a1bb679da719896d3ced92c5e34bc6ef0315ef8c05c3ee8621bcd51bac552e6f02bfce635aa13205f23e
7
+ data.tar.gz: 581165dd6ee9b10a02d206a7f985b6980ee1ddb46a9a2de05e194a6a9578596114823eff12cd4dab96277e82e533bb9c742c0ee72e109de2a8e819405fb5f4ce
@@ -19,6 +19,8 @@ module DatabaseHelper
19
19
  'db2'
20
20
  elsif driver.include? 'sqlite'
21
21
  'sqlite'
22
+ else
23
+ 'generic'
22
24
  end
23
25
  end
24
26
  # rubocop:enable Metrics/CyclomaticComplexity
@@ -14,8 +14,6 @@ module StackifyRubyAPM
14
14
 
15
15
  def initialize(*args)
16
16
  super(*args)
17
-
18
- @type = format('db.%s.sql', lookup_adapter || 'unknown').freeze
19
17
  end
20
18
 
21
19
  def normalize(_transaction, _name, payload)
@@ -25,7 +23,9 @@ module StackifyRubyAPM
25
23
  check_prepared_stmt(statement, payload)
26
24
  name = payload[:sql] || payload[:name] || 'Default'
27
25
  context = Span::Context.new(statement)
28
- [name, @type, context]
26
+
27
+ type = format('db.%s.sql', lookup_adapter(payload) || 'unknown').freeze
28
+ [name, type, context]
29
29
  end
30
30
 
31
31
  private
@@ -33,7 +33,7 @@ module StackifyRubyAPM
33
33
  def query_variables(payload)
34
34
  adapter_config = lookup_adapter_config
35
35
  props = get_common_db_properties
36
- props[:PROVIDER] = get_profiler(lookup_adapter)
36
+ props[:PROVIDER] = get_profiler(lookup_adapter(payload))
37
37
  props[:SQL] = payload[:sql]
38
38
  if adapter_config
39
39
  props[:URL] = "#{adapter_config[:host]}:#{adapter_config[:port]}"
@@ -41,8 +41,52 @@ module StackifyRubyAPM
41
41
  props
42
42
  end
43
43
 
44
- def lookup_adapter
45
- ::ActiveRecord::Base.connection.adapter_name.downcase
44
+ # Ideally the application doesn't connect to the database during boot,
45
+ # but sometimes it does. In case it did, we want to empty out the
46
+ # connection pools so that a non-database-using process (e.g. a master
47
+ # process in a forking server model) doesn't retain a needless
48
+ # connection. If it was needed, the incremental cost of reestablishing
49
+ # this connection is trivial: the rest of the pool would need to be
50
+ # populated anyway.
51
+ #
52
+ # Reference: https://github.com/rails/rails/blob/main/activerecord/lib/active_record/railtie.rb#L253
53
+ #
54
+ # Miko: Considering we are getting the connection method, it is retrieving connection from the connection pool
55
+ # Connection Method: lib/active_record/connection_handling.rb#L264
56
+ # Retrieve Connection: lib/active_record/connection_handling.rb#L309
57
+ # Handler Retrieve Connection: lib/active_record/connection_adapters/abstract/connection_pool.rb#L1111
58
+
59
+ def lookup_adapter(payload)
60
+ connection = nil
61
+ if (payload.key?(:connection))
62
+ connection = payload[:connection]
63
+ elsif ::ActiveRecord::Base.connection_pool.instance_variable_defined?(:@reserved_connections) and payload.key?(:connection_id)
64
+ connection_id = payload[:connection_id] # Connection ID here is the object_id of the connection object
65
+ connections = ::ActiveRecord::Base.connection_pool.instance_variable_get(:@reserved_connections) # Lets check the reserved connections
66
+
67
+ if (
68
+ (connections.class != nil and connections.respond_to?(:class) and
69
+ (connections.class.to_s == 'ThreadSafe::Cache' or connections.class.to_s == 'Hash')
70
+ ) and connections.size()
71
+ )
72
+ connections.each_value do |val|
73
+ if val.object_id == connection_id
74
+ connection = val
75
+ break
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ if (connection.nil?)
82
+ return 'generic'
83
+ end
84
+
85
+ if (connection.respond_to?(:adapter_name) && connection.adapter_name.nil?)
86
+ return 'generic'
87
+ end
88
+
89
+ connection.adapter_name.downcase
46
90
  rescue StandardError => error
47
91
  debug '[SqlNormalizer] lookup_adapter err: ' + error.inspect.to_s
48
92
  nil
@@ -61,7 +105,7 @@ module StackifyRubyAPM
61
105
 
62
106
  def check_prepared_stmt(statement, payload)
63
107
  if StackifyRubyAPM.agent.config.prefix_enabled
64
- case get_profiler(lookup_adapter)
108
+ case get_profiler(lookup_adapter(payload))
65
109
  when 'generic', 'mysql', 'sqlite', 'oracle', 'db2'
66
110
  check_prepared_stmt_by_placeholder(payload[:sql].include?('?'), statement, payload)
67
111
  when 'postgresql'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Sets the version of the APM
4
4
  module StackifyRubyAPM
5
- VERSION = '1.14.5'.freeze
5
+ VERSION = '1.14.7'.freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackify-ruby-apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.5
4
+ version: 1.14.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-01 00:00:00.000000000 Z
11
+ date: 2021-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails