stackify-ruby-apm 1.17.0 → 1.17.1

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
  SHA256:
3
- metadata.gz: 2e7111fe28e3f3d664a3ee3859b710ca68ad9419dff7be6bf08790c1c33daf93
4
- data.tar.gz: 3db3dd30f3a82d751e649c5096fd27da82664184c24b9b434610a0ecac05b21b
3
+ metadata.gz: 95f66de5cfc9c86486d1d9be9083f3d86300ee9d546ee23c56a493bb99ab8fbf
4
+ data.tar.gz: ead544f89afaab3ccd1f77f249eff2cc76815353b4eb5ca8bd680937c4fa07da
5
5
  SHA512:
6
- metadata.gz: 41712bd53c97a593907924abefbdeb4421a9487a7622b568d65fa3bbf30d678208d2477a51b9253e98172976ed541d16bf4ce36db48d240d99ff4d125fef7f45
7
- data.tar.gz: e1413677db26b8548e83ce3a49d72394256b156feed4a9181f400edab0db46b180a3f6d86f1a737007756cc5edf64984dac1fa1ef2ac766a496489b5dabbdfe3
6
+ metadata.gz: 40e949476ed9c2b35420f574850c5e52086ff7f5c617a09728d62a2449bcc0b6d93af75271bf800b7718dcea122ebe819b8f9d0316d97e78b667667393dc99df
7
+ data.tar.gz: de9e2587b22f07aea878e714153ee19d60efe7a397363d2df5cdeed96051f62a4797580a61b83a41c3adde28446c1e1bf7f604afd30a5ba1bd662052e466c5ad
@@ -20,21 +20,22 @@ module StackifyRubyAPM
20
20
  def normalize(_transaction, _name, payload)
21
21
  return :skip if %w[SCHEMA CACHE].include?(payload[:name])
22
22
 
23
- statement = query_variables(payload)
24
- check_prepared_stmt(statement, payload)
23
+ adapter = lookup_adapter(payload)
24
+ statement = query_variables(payload, adapter)
25
+ check_prepared_stmt(statement, payload, adapter)
25
26
  name = payload[:sql] || payload[:name] || 'Default'
26
27
  context = Span::Context.new(statement)
27
28
 
28
- type = format('db.%s.sql', lookup_adapter(payload) || 'unknown').freeze
29
+ type = format('db.%s.sql', adapter || 'unknown').freeze
29
30
  [name, type, context]
30
31
  end
31
32
 
32
33
  private
33
34
 
34
- def query_variables(payload)
35
+ def query_variables(payload, adapter)
35
36
  adapter_config = lookup_adapter_config
36
37
  props = get_common_db_properties
37
- props[:PROVIDER] = get_profiler(lookup_adapter(payload))
38
+ props[:PROVIDER] = get_profiler(adapter)
38
39
  props[:SQL] = payload[:sql]
39
40
  if adapter_config
40
41
  props[:URL] = "#{adapter_config[:host]}:#{adapter_config[:port]}"
@@ -58,52 +59,44 @@ module StackifyRubyAPM
58
59
  # Handler Retrieve Connection: lib/active_record/connection_adapters/abstract/connection_pool.rb#L1111
59
60
 
60
61
  def lookup_adapter(payload)
61
- connection = nil
62
+ # If connection is explicitly set
62
63
  if (payload.key?(:connection))
63
64
  connection = payload[:connection]
64
- elsif ::ActiveRecord::Base.connection_pool.instance_variable_defined?(:@reserved_connections) and payload.key?(:connection_id)
65
- connection_id = payload[:connection_id] # Connection ID here is the object_id of the connection object
66
- connections = ::ActiveRecord::Base.connection_pool.instance_variable_get(:@reserved_connections) # Lets check the reserved connections
67
-
68
- if (
69
- (connections.class != nil and connections.respond_to?(:class) and
70
- (connections.class.to_s == 'ThreadSafe::Cache' or connections.class.to_s == 'Hash')
71
- ) and connections.size()
72
- )
73
- connections.each_value do |val|
74
- if val.object_id == connection_id
75
- connection = val
65
+ if (connection.respond_to?(:adapter_name) && !connection.adapter_name.nil?)
66
+ return connection.adapter_name.downcase
67
+ end
68
+ elsif ::ActiveRecord::Base.respond_to?(:connection_handler) && ::ActiveRecord::Base.connection_handler.connection_pool_list.size() > 0 && payload.key?(:connection_id)
69
+ connection_id = payload[:connection_id]
70
+ connection = nil
71
+ connection_pool = nil
72
+ connection_pool_list = ::ActiveRecord::Base.connection_handler.connection_pool_list
73
+ connection_pool_list.each do |pool|
74
+ pool.instance_variable_get(:@connections).each do |conn|
75
+ if conn.object_id == connection_id
76
+ connection = conn
76
77
  break
77
78
  end
78
79
  end
79
80
  end
80
- end
81
81
 
82
- if (connection.nil?)
83
- if ::ActiveRecord::Base.respond_to?(:connection)
84
- return ::ActiveRecord::Base.connection.adapter_name.downcase
85
- else
86
- return 'generic'
82
+ if (!connection.nil? && connection.respond_to?(:adapter_name))
83
+ return connection.adapter_name.downcase
87
84
  end
88
85
  end
89
-
90
- if (connection.respond_to?(:adapter_name) && connection.adapter_name.nil?)
91
- if ::ActiveRecord::Base.respond_to?(:connection)
92
- return ::ActiveRecord::Base.connection.adapter_name.downcase
93
- else
94
- return 'generic'
86
+ if (::ActiveRecord::Base.respond_to?(:connection_pool) && ::ActiveRecord::Base.connection_pool)
87
+ base_connection_pool = ::ActiveRecord::Base.connection_pool
88
+ if (base_connection_pool.respond_to?(:config))
89
+ return base_connection_pool.config[:adapter]
90
+ end
91
+ if (base_connection_pool.respond_to?(:db_config))
92
+ return base_connection_pool.db_config[:adapter]
95
93
  end
96
94
  end
97
95
 
98
- connection.adapter_name.downcase
96
+ return 'generic'
99
97
  rescue StandardError => error
100
98
  debug '[SqlNormalizer] lookup_adapter err: ' + error.inspect.to_s
101
- # do a last fail safe check before returning nil
102
- if ::ActiveRecord::Base.respond_to?(:connection)
103
- ::ActiveRecord::Base.connection.adapter_name.downcase
104
- else
105
- nil
106
- end
99
+ return 'generic'
107
100
  end
108
101
 
109
102
  def lookup_adapter_config
@@ -121,9 +114,9 @@ module StackifyRubyAPM
121
114
  nil
122
115
  end
123
116
 
124
- def check_prepared_stmt(statement, payload)
117
+ def check_prepared_stmt(statement, payload, adapter)
125
118
  if StackifyRubyAPM.agent.config.prefix_enabled
126
- case get_profiler(lookup_adapter(payload))
119
+ case get_profiler(adapter)
127
120
  when 'generic', 'mysql', 'sqlite', 'oracle', 'db2'
128
121
  check_prepared_stmt_by_placeholder(payload[:sql].include?('?'), statement, payload)
129
122
  when 'postgresql'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Sets the version of the APM:
4
4
  module StackifyRubyAPM
5
- VERSION = '1.17.0'.freeze
5
+ VERSION = '1.17.1'.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.17.0
4
+ version: 1.17.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-05 00:00:00.000000000 Z
11
+ date: 2024-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails