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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76953d4e093b082edd18b9b64c80f282cef005ca138ded983b5bc88b1545db96
4
- data.tar.gz: 3c1fba2fa393369d38de568f91dbec9d1708a963c5f3802719f285c2e99edefa
3
+ metadata.gz: 207d50046b455753b802c84ef15314d336df3376b986e98f8fff5014aeed6370
4
+ data.tar.gz: bfc2a15d2d26c9aea7263945b6a0f10c02da58f6c1ed0dfb6ea13fc2adcd6c38
5
5
  SHA512:
6
- metadata.gz: d1b9b23f4c1b473fc45850f996701cc33703de8a6937297638d84603a4ce816b2e00cb318d73eca407e073f1f41403d82b9d1bc7305cf4623b47a53965d8b576
7
- data.tar.gz: 517edbe2b9f8ff7e1c5c8ecb381f93fc39a28af406de5c6ec45b5ff3c99a113bd4833482f38f7944f1c542e2a027e2c581c5d36df45d8b1749aefcdc752050df
6
+ metadata.gz: bc2621fd6efa921753d1db81649e7cbff2f26b35350798c82a01a2326752ba2db8e42ccd5de1730a69a9516a849b48943415b9160ffeaa0b70b5baea54f3cb9e
7
+ data.tar.gz: 7f6b9b487101dad81b0b29acfe7c1844d29a778ff48235a9180160c2724dd78a57a8d6eee515169a01e4e36f92156ee9f590aa2a88de4043f1c47de64666d061
@@ -41,6 +41,8 @@ module StackifyRubyAPM
41
41
  end
42
42
 
43
43
  def rails_req?(env)
44
+ # Not used
45
+ # Possible use of ActiveSupport.on_load(:action_dispatch_request)
44
46
  defined?(ActionDispatch::Request) &&
45
47
  env.is_a?(ActionDispatch::Request)
46
48
  end
@@ -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
- ::ActiveRecord::Base.connection_config.to_h
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
- redis_key = args[0..1].join('/') if args.length > 1 && !args[1].include?('=')
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)
@@ -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
@@ -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
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Sets the version of the APM
4
4
  module StackifyRubyAPM
5
- VERSION = '1.14.0'.freeze
5
+ VERSION = '1.14.6'.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.0
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: 2020-09-10 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails