stackify-ruby-apm 1.14.2 → 1.14.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stackify_apm/context_builder.rb +2 -0
- data/lib/stackify_apm/helper/database_helper.rb +2 -0
- data/lib/stackify_apm/logger/log_device.rb +19 -0
- data/lib/stackify_apm/middleware.rb +2 -0
- data/lib/stackify_apm/normalizers/active_record.rb +58 -8
- data/lib/stackify_apm/spies/redis.rb +7 -3
- data/lib/stackify_apm/spies/sinatra_activerecord/mysql_adapter.rb +3 -0
- data/lib/stackify_apm/spies/sinatra_activerecord/postgresql_adapter.rb +2 -0
- data/lib/stackify_apm/spies/sinatra_activerecord/sqlite_adapter.rb +2 -0
- data/lib/stackify_apm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 881446a181c81d422cdd81f2de4b4ccef409989171d96a53833bbe425f8105c0
|
4
|
+
data.tar.gz: ed31e237779e881ab4a57d7db2c4dcc7936bbe01b6af256ac4f53d9ae4c96054
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 293677dce94cf22be5e9a45fb1e7d9b7090fcbbe76a4a1bb679da719896d3ced92c5e34bc6ef0315ef8c05c3ee8621bcd51bac552e6f02bfce635aa13205f23e
|
7
|
+
data.tar.gz: 581165dd6ee9b10a02d206a7f985b6980ee1ddb46a9a2de05e194a6a9578596114823eff12cd4dab96277e82e533bb9c742c0ee72e109de2a8e819405fb5f4ce
|
@@ -8,6 +8,7 @@
|
|
8
8
|
module StackifyRubyAPM
|
9
9
|
# @api private
|
10
10
|
class LogDevice < Logger::LogDevice
|
11
|
+
MAX_LOG_FILES_COUNT = 10
|
11
12
|
alias_method 'write_without_apm', 'write'
|
12
13
|
def write(message)
|
13
14
|
if @filename
|
@@ -84,6 +85,24 @@ module StackifyRubyAPM
|
|
84
85
|
def create_logfile(filename)
|
85
86
|
logdev = super
|
86
87
|
File.chmod(0o777, filename)
|
88
|
+
|
89
|
+
begin
|
90
|
+
dir_name = File.dirname(filename)
|
91
|
+
# repath current file due to windows separator \\ doesn't work with Dir.glob
|
92
|
+
dir_name = dir_name.split(File::ALT_SEPARATOR).join(File::SEPARATOR)
|
93
|
+
search_files = File.join("#{dir_name}", "{[!stackify-ruby-apm]*}.log")
|
94
|
+
log_files = Dir.glob(search_files).sort_by { |f| File.stat(f).mtime}.reverse
|
95
|
+
|
96
|
+
if log_files.length > MAX_LOG_FILES_COUNT
|
97
|
+
files_to_delete = log_files[MAX_LOG_FILES_COUNT..-1]
|
98
|
+
files_to_delete.each { |f|
|
99
|
+
File.delete(f) if File.exists? f
|
100
|
+
}
|
101
|
+
end
|
102
|
+
rescue
|
103
|
+
# nothing to do here
|
104
|
+
end
|
105
|
+
|
87
106
|
logdev
|
88
107
|
end
|
89
108
|
# rubocop:enable Style/RescueModifier
|
@@ -127,6 +127,8 @@ module StackifyRubyAPM
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def streaming?(env)
|
130
|
+
# Not used
|
131
|
+
# Possible use of ActiveSupport.on_load(:action_controller_base)
|
130
132
|
return false unless defined?(ActionController::Live)
|
131
133
|
|
132
134
|
env['action_controller.instance'].class.included_modules.include?(ActionController::Live)
|
@@ -1,4 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# Not used
|
3
|
+
# Possible use of ActiveSupport.on_load(:active_record)
|
2
4
|
|
3
5
|
require 'stackify_apm/helper/database_helper'
|
4
6
|
|
@@ -12,8 +14,6 @@ module StackifyRubyAPM
|
|
12
14
|
|
13
15
|
def initialize(*args)
|
14
16
|
super(*args)
|
15
|
-
|
16
|
-
@type = format('db.%s.sql', lookup_adapter || 'unknown').freeze
|
17
17
|
end
|
18
18
|
|
19
19
|
def normalize(_transaction, _name, payload)
|
@@ -23,7 +23,9 @@ module StackifyRubyAPM
|
|
23
23
|
check_prepared_stmt(statement, payload)
|
24
24
|
name = payload[:sql] || payload[:name] || 'Default'
|
25
25
|
context = Span::Context.new(statement)
|
26
|
-
|
26
|
+
|
27
|
+
type = format('db.%s.sql', lookup_adapter(payload) || 'unknown').freeze
|
28
|
+
[name, type, context]
|
27
29
|
end
|
28
30
|
|
29
31
|
private
|
@@ -31,7 +33,7 @@ module StackifyRubyAPM
|
|
31
33
|
def query_variables(payload)
|
32
34
|
adapter_config = lookup_adapter_config
|
33
35
|
props = get_common_db_properties
|
34
|
-
props[:PROVIDER] = get_profiler(lookup_adapter)
|
36
|
+
props[:PROVIDER] = get_profiler(lookup_adapter(payload))
|
35
37
|
props[:SQL] = payload[:sql]
|
36
38
|
if adapter_config
|
37
39
|
props[:URL] = "#{adapter_config[:host]}:#{adapter_config[:port]}"
|
@@ -39,15 +41,63 @@ module StackifyRubyAPM
|
|
39
41
|
props
|
40
42
|
end
|
41
43
|
|
42
|
-
|
43
|
-
|
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
|
44
90
|
rescue StandardError => error
|
45
91
|
debug '[SqlNormalizer] lookup_adapter err: ' + error.inspect.to_s
|
46
92
|
nil
|
47
93
|
end
|
48
94
|
|
49
95
|
def lookup_adapter_config
|
50
|
-
::
|
96
|
+
if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('6.1')
|
97
|
+
::ActiveRecord::Base.connection_db_config.to_h
|
98
|
+
else
|
99
|
+
::ActiveRecord::Base.connection_config.to_h
|
100
|
+
end
|
51
101
|
rescue StandardError => error
|
52
102
|
debug '[SqlNormalizer] lookup_adapter_config err: ' + error.inspect.to_s
|
53
103
|
nil
|
@@ -55,7 +105,7 @@ module StackifyRubyAPM
|
|
55
105
|
|
56
106
|
def check_prepared_stmt(statement, payload)
|
57
107
|
if StackifyRubyAPM.agent.config.prefix_enabled
|
58
|
-
case get_profiler(lookup_adapter)
|
108
|
+
case get_profiler(lookup_adapter(payload))
|
59
109
|
when 'generic', 'mysql', 'sqlite', 'oracle', 'db2'
|
60
110
|
check_prepared_stmt_by_placeholder(payload[:sql].include?('?'), statement, payload)
|
61
111
|
when 'postgresql'
|
@@ -33,7 +33,11 @@ module StackifyRubyAPM
|
|
33
33
|
# Possible formats:
|
34
34
|
# `<namespace:key/method_name/expires_in=300/ttl=60/>`
|
35
35
|
# `<namespace:key/expires_in=300/ttl=60/>`
|
36
|
-
|
36
|
+
if redis_key.nil?
|
37
|
+
redis_key = redis_details[1]
|
38
|
+
else
|
39
|
+
redis_key = args[0..1].join('/') if args.length > 1 && !args[1].include?('=')
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
return call_without_apm(command, &block) if command[0] == :auth
|
@@ -48,8 +52,8 @@ module StackifyRubyAPM
|
|
48
52
|
OPERATION: name,
|
49
53
|
URL: "#{self.options[:host]}:#{self.options[:port]}"
|
50
54
|
}.tap do |hash|
|
51
|
-
hash[:CACHEKEY] = redis_key unless redis_key.empty?
|
52
|
-
hash[:CACHENAME] = redis_nspace unless redis_nspace.empty?
|
55
|
+
hash[:CACHEKEY] = redis_key unless redis_key.nil? || redis_key.empty?
|
56
|
+
hash[:CACHENAME] = redis_nspace unless redis_nspace.nil? || redis_nspace.empty?
|
53
57
|
end
|
54
58
|
|
55
59
|
ctx = Span::Context.new(context)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Spies for active record when sinatra framework is used and active_record is being extended. (mysql adapter)
|
4
|
+
# Not used
|
5
|
+
# Possible use of ActiveSupport.on_load(:active_record)
|
4
6
|
|
5
7
|
require 'stackify_apm/helper/database_helper'
|
6
8
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Spies for active record when sinatra framework is used and active_record is being extended. (mysql adapter)
|
4
|
+
# Not used
|
5
|
+
# Possible use of ActiveSupport.on_load(:active_record)
|
4
6
|
|
5
7
|
require 'stackify_apm/helper/database_helper'
|
6
8
|
|
data/lib/stackify_apm/version.rb
CHANGED
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.
|
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:
|
11
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|