stackify-ruby-apm 1.13.2 → 1.14.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 +4 -4
- data/lib/stackify_apm/context_builder.rb +2 -0
- data/lib/stackify_apm/logger/log_device.rb +19 -0
- data/lib/stackify_apm/middleware.rb +4 -0
- data/lib/stackify_apm/normalizers/active_record.rb +17 -0
- data/lib/stackify_apm/spies/dynamo_db.rb +1 -0
- data/lib/stackify_apm/spies/mongo.rb +3 -1
- data/lib/stackify_apm/spies/redis.rb +13 -6
- data/lib/stackify_apm/spies/sinatra_activerecord/mysql_adapter.rb +24 -0
- data/lib/stackify_apm/spies/sinatra_activerecord/postgresql_adapter.rb +10 -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: 81a16e2527e1237952803d7082cd0869b932e2af04dd3263490e5bd6538debbd
|
4
|
+
data.tar.gz: 3df0659ad3e96984f67c9850e69f38c20fae65ced83948b2791a2a9fe63012af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6a34b33a19b3a59c69fdfa105255b234a77b3be6b81a0bbdac68bc39bdc92eb327c33d236d49beb064dafe87b6f4e882df53fb29365b2152572f4d9cf7fdf08
|
7
|
+
data.tar.gz: e05ee709696f67a2bb4c7780a2b762393f5be5507c3af5b327c825e500fd3a18786827f2ba2e8d98df8e926af6cc2d4a5dc79fd380f8392fdd8443e04a998c5c
|
@@ -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
|
@@ -53,6 +53,8 @@ module StackifyRubyAPM
|
|
53
53
|
if okay_to_modify?
|
54
54
|
@configuration.already_instrumented_flag = true
|
55
55
|
if @configuration.rum_enabled.is_a?(TrueClass)
|
56
|
+
# close old response body proxy to close all db connections
|
57
|
+
@rack_body.close if @rack_body.respond_to?(:close)
|
56
58
|
response = Rack::Response.new @rack_body, @rack_status, @rack_headers
|
57
59
|
response.set_cookie(@configuration.rum_cookie_name, value: transaction.id, path: @configuration.rum_cookie_path)
|
58
60
|
resp = response.finish
|
@@ -125,6 +127,8 @@ module StackifyRubyAPM
|
|
125
127
|
end
|
126
128
|
|
127
129
|
def streaming?(env)
|
130
|
+
# Not used
|
131
|
+
# Possible use of ActiveSupport.on_load(:action_controller_base)
|
128
132
|
return false unless defined?(ActionController::Live)
|
129
133
|
|
130
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
|
|
@@ -29,9 +31,13 @@ module StackifyRubyAPM
|
|
29
31
|
private
|
30
32
|
|
31
33
|
def query_variables(payload)
|
34
|
+
adapter_config = lookup_adapter_config
|
32
35
|
props = get_common_db_properties
|
33
36
|
props[:PROVIDER] = get_profiler(lookup_adapter)
|
34
37
|
props[:SQL] = payload[:sql]
|
38
|
+
if adapter_config
|
39
|
+
props[:URL] = "#{adapter_config[:host]}:#{adapter_config[:port]}"
|
40
|
+
end
|
35
41
|
props
|
36
42
|
end
|
37
43
|
|
@@ -42,6 +48,17 @@ module StackifyRubyAPM
|
|
42
48
|
nil
|
43
49
|
end
|
44
50
|
|
51
|
+
def lookup_adapter_config
|
52
|
+
if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('6.1')
|
53
|
+
::ActiveRecord::Base.connection_db_config.to_h
|
54
|
+
else
|
55
|
+
::ActiveRecord::Base.connection_config.to_h
|
56
|
+
end
|
57
|
+
rescue StandardError => error
|
58
|
+
debug '[SqlNormalizer] lookup_adapter_config err: ' + error.inspect.to_s
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
45
62
|
def check_prepared_stmt(statement, payload)
|
46
63
|
if StackifyRubyAPM.agent.config.prefix_enabled
|
47
64
|
case get_profiler(lookup_adapter)
|
@@ -18,11 +18,13 @@ module StackifyRubyAPM
|
|
18
18
|
name = command[0].upcase.to_s
|
19
19
|
type = 'db.redis'
|
20
20
|
redis_details = command[1].is_a?(String) ? command[1].split(':') : []
|
21
|
-
|
21
|
+
# use length instead of .blank?
|
22
|
+
# reason: will throw error if activesupport missing
|
23
|
+
redis_nspace = redis_details.length ? redis_details[0] : ''
|
22
24
|
redis_key = ''
|
23
25
|
|
24
26
|
# Checks CACHEKEY value
|
25
|
-
if
|
27
|
+
if redis_details.length && redis_details[1]
|
26
28
|
# Initially sets the CACHEKEY value
|
27
29
|
args = redis_details[1].split('/')
|
28
30
|
redis_key = args[0]
|
@@ -31,7 +33,11 @@ module StackifyRubyAPM
|
|
31
33
|
# Possible formats:
|
32
34
|
# `<namespace:key/method_name/expires_in=300/ttl=60/>`
|
33
35
|
# `<namespace:key/expires_in=300/ttl=60/>`
|
34
|
-
|
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
|
35
41
|
end
|
36
42
|
|
37
43
|
return call_without_apm(command, &block) if command[0] == :auth
|
@@ -43,10 +49,11 @@ module StackifyRubyAPM
|
|
43
49
|
COMPONENT_CATEGORY: 'Cache',
|
44
50
|
COMPONENT_DETAIL: 'Execute',
|
45
51
|
THREAD_ID: Thread.current.object_id,
|
46
|
-
OPERATION: name
|
52
|
+
OPERATION: name,
|
53
|
+
URL: "#{self.options[:host]}:#{self.options[:port]}"
|
47
54
|
}.tap do |hash|
|
48
|
-
hash[:CACHEKEY] = redis_key unless redis_key.empty?
|
49
|
-
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?
|
50
57
|
end
|
51
58
|
|
52
59
|
ctx = Span::Context.new(context)
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
# Spies for active record when sinatra framework is used and active_record is being extended. (mysql adapter)
|
4
4
|
|
5
|
+
# Not used
|
6
|
+
# Possible use of ActiveSupport.on_load(:active_record)
|
7
|
+
|
5
8
|
require 'stackify_apm/helper/database_helper'
|
6
9
|
|
7
10
|
module StackifyRubyAPM
|
@@ -10,6 +13,7 @@ module StackifyRubyAPM
|
|
10
13
|
# @api private
|
11
14
|
class MysqlAdapterSpy
|
12
15
|
TYPE = 'db.sinatra_active_record.sql'.freeze
|
16
|
+
DEFAULT_PORT = 3306
|
13
17
|
if ActiveRecord::VERSION::MAJOR.to_i >= 5
|
14
18
|
def install
|
15
19
|
ActiveRecord::ConnectionAdapters::MySQL::DatabaseStatements.class_eval do
|
@@ -79,6 +83,7 @@ module StackifyRubyAPM
|
|
79
83
|
props = get_common_db_properties
|
80
84
|
props[:PROVIDER] = 'mysql'
|
81
85
|
props[:SQL] = payload[:sql]
|
86
|
+
props[:URL] = get_host unless !get_host
|
82
87
|
props
|
83
88
|
end
|
84
89
|
|
@@ -87,6 +92,13 @@ module StackifyRubyAPM
|
|
87
92
|
check_prepared_stmt_by_placeholder(payload[:sql].include?('?'), statement, payload)
|
88
93
|
end
|
89
94
|
end
|
95
|
+
|
96
|
+
def get_host
|
97
|
+
query_options = self.raw_connection.query_options.to_h
|
98
|
+
"#{query_options[:host]}:#{query_options[:port] || DEFAULT_PORT}"
|
99
|
+
rescue StandardError => error
|
100
|
+
nil
|
101
|
+
end
|
90
102
|
end
|
91
103
|
end
|
92
104
|
else
|
@@ -112,6 +124,7 @@ module StackifyRubyAPM
|
|
112
124
|
SQL: sql,
|
113
125
|
PROVIDER: 'mysql'
|
114
126
|
)
|
127
|
+
ctx[:URL] = get_host unless !get_host
|
115
128
|
|
116
129
|
result = exec_query_without_apm(sql, name, binds)
|
117
130
|
|
@@ -135,6 +148,7 @@ module StackifyRubyAPM
|
|
135
148
|
SQL: sql,
|
136
149
|
PROVIDER: 'mysql'
|
137
150
|
)
|
151
|
+
ctx[:URL] = get_host unless !get_host
|
138
152
|
|
139
153
|
result = exec_delete_without_apm(sql, name, binds)
|
140
154
|
|
@@ -158,6 +172,7 @@ module StackifyRubyAPM
|
|
158
172
|
SQL: sql,
|
159
173
|
PROVIDER: 'mysql'
|
160
174
|
)
|
175
|
+
ctx[:URL] = get_host unless !get_host
|
161
176
|
|
162
177
|
result = exec_update_without_apm(sql, name, binds)
|
163
178
|
|
@@ -181,6 +196,7 @@ module StackifyRubyAPM
|
|
181
196
|
SQL: sql,
|
182
197
|
PROVIDER: 'mysql'
|
183
198
|
)
|
199
|
+
ctx[:URL] = get_host unless !get_host
|
184
200
|
|
185
201
|
result = exec_insert_without_apm(sql, name, binds, _pk = nil, _sequence_name = nil)
|
186
202
|
|
@@ -188,6 +204,14 @@ module StackifyRubyAPM
|
|
188
204
|
return result
|
189
205
|
end
|
190
206
|
end
|
207
|
+
|
208
|
+
def get_host
|
209
|
+
config = self.config.to_h
|
210
|
+
"#{config[:host]}:#{config[:port] || DEFAULT_PORT}"
|
211
|
+
rescue StandardError => error
|
212
|
+
nil
|
213
|
+
end
|
214
|
+
|
191
215
|
end
|
192
216
|
end
|
193
217
|
end
|
@@ -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
|
|
@@ -80,6 +82,7 @@ module StackifyRubyAPM
|
|
80
82
|
props = get_common_db_properties
|
81
83
|
props[:PROVIDER] = 'postgresql'
|
82
84
|
props[:SQL] = payload[:sql]
|
85
|
+
props[:URL] = get_host unless !get_host
|
83
86
|
props
|
84
87
|
end
|
85
88
|
|
@@ -88,6 +91,13 @@ module StackifyRubyAPM
|
|
88
91
|
check_prepared_stmt_by_placeholder(!!payload[:sql].match(/\$\d/), statement, payload)
|
89
92
|
end
|
90
93
|
end
|
94
|
+
|
95
|
+
def get_host
|
96
|
+
connection = self.raw_connection
|
97
|
+
"#{connection.host}:#{connection.port}"
|
98
|
+
rescue StandardError => error
|
99
|
+
nil
|
100
|
+
end
|
91
101
|
end
|
92
102
|
end
|
93
103
|
end
|
@@ -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.
|
4
|
+
version: 1.14.5
|
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-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|