stackify-ruby-apm 1.14.0 → 1.14.6
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 +28 -3
- 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: 207d50046b455753b802c84ef15314d336df3376b986e98f8fff5014aeed6370
|
4
|
+
data.tar.gz: bfc2a15d2d26c9aea7263945b6a0f10c02da58f6c1ed0dfb6ea13fc2adcd6c38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc2621fd6efa921753d1db81649e7cbff2f26b35350798c82a01a2326752ba2db8e42ccd5de1730a69a9516a849b48943415b9160ffeaa0b70b5baea54f3cb9e
|
7
|
+
data.tar.gz: 7f6b9b487101dad81b0b29acfe7c1844d29a778ff48235a9180160c2724dd78a57a8d6eee515169a01e4e36f92156ee9f590aa2a88de4043f1c47de64666d061
|
@@ -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
|
|
@@ -12,8 +14,7 @@ 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
|
+
@type = nil
|
17
18
|
end
|
18
19
|
|
19
20
|
def normalize(_transaction, _name, payload)
|
@@ -23,6 +24,11 @@ module StackifyRubyAPM
|
|
23
24
|
check_prepared_stmt(statement, payload)
|
24
25
|
name = payload[:sql] || payload[:name] || 'Default'
|
25
26
|
context = Span::Context.new(statement)
|
27
|
+
|
28
|
+
if (@type == nil)
|
29
|
+
@type = format('db.%s.sql', lookup_adapter || 'unknown').freeze
|
30
|
+
end
|
31
|
+
|
26
32
|
[name, @type, context]
|
27
33
|
end
|
28
34
|
|
@@ -39,6 +45,21 @@ module StackifyRubyAPM
|
|
39
45
|
props
|
40
46
|
end
|
41
47
|
|
48
|
+
# Ideally the application doesn't connect to the database during boot,
|
49
|
+
# but sometimes it does. In case it did, we want to empty out the
|
50
|
+
# connection pools so that a non-database-using process (e.g. a master
|
51
|
+
# process in a forking server model) doesn't retain a needless
|
52
|
+
# connection. If it was needed, the incremental cost of reestablishing
|
53
|
+
# this connection is trivial: the rest of the pool would need to be
|
54
|
+
# populated anyway.
|
55
|
+
#
|
56
|
+
# Reference: https://github.com/rails/rails/blob/main/activerecord/lib/active_record/railtie.rb#L253
|
57
|
+
#
|
58
|
+
# Miko: Considering we are getting the connection method, it is retrieving connection from the connection pool
|
59
|
+
# Connection Method: lib/active_record/connection_handling.rb#L264
|
60
|
+
# Retrieve Connection: lib/active_record/connection_handling.rb#L309
|
61
|
+
# Handler Retrieve Connection: lib/active_record/connection_adapters/abstract/connection_pool.rb#L1111
|
62
|
+
|
42
63
|
def lookup_adapter
|
43
64
|
::ActiveRecord::Base.connection.adapter_name.downcase
|
44
65
|
rescue StandardError => error
|
@@ -47,7 +68,11 @@ module StackifyRubyAPM
|
|
47
68
|
end
|
48
69
|
|
49
70
|
def lookup_adapter_config
|
50
|
-
::
|
71
|
+
if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('6.1')
|
72
|
+
::ActiveRecord::Base.connection_db_config.to_h
|
73
|
+
else
|
74
|
+
::ActiveRecord::Base.connection_config.to_h
|
75
|
+
end
|
51
76
|
rescue StandardError => error
|
52
77
|
debug '[SqlNormalizer] lookup_adapter_config err: ' + error.inspect.to_s
|
53
78
|
nil
|
@@ -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.6
|
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-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|