scout_apm 2.6.6 → 4.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +49 -0
  3. data/.rubocop.yml +2 -5
  4. data/.travis.yml +3 -7
  5. data/CHANGELOG.markdown +51 -0
  6. data/Gemfile +1 -8
  7. data/gems/rails6.gemfile +1 -1
  8. data/lib/scout_apm.rb +23 -1
  9. data/lib/scout_apm/agent.rb +22 -0
  10. data/lib/scout_apm/agent_context.rb +14 -2
  11. data/lib/scout_apm/background_job_integrations/delayed_job.rb +1 -1
  12. data/lib/scout_apm/background_job_integrations/faktory.rb +103 -0
  13. data/lib/scout_apm/background_job_integrations/sidekiq.rb +2 -2
  14. data/lib/scout_apm/config.rb +17 -2
  15. data/lib/scout_apm/detailed_trace.rb +2 -1
  16. data/lib/scout_apm/environment.rb +17 -1
  17. data/lib/scout_apm/error.rb +27 -0
  18. data/lib/scout_apm/error_service.rb +32 -0
  19. data/lib/scout_apm/error_service/error_buffer.rb +39 -0
  20. data/lib/scout_apm/error_service/error_record.rb +211 -0
  21. data/lib/scout_apm/error_service/ignored_exceptions.rb +66 -0
  22. data/lib/scout_apm/error_service/middleware.rb +32 -0
  23. data/lib/scout_apm/error_service/notifier.rb +33 -0
  24. data/lib/scout_apm/error_service/payload.rb +47 -0
  25. data/lib/scout_apm/error_service/periodic_work.rb +17 -0
  26. data/lib/scout_apm/error_service/railtie.rb +11 -0
  27. data/lib/scout_apm/error_service/sidekiq.rb +80 -0
  28. data/lib/scout_apm/extensions/transaction_callback_payload.rb +1 -1
  29. data/lib/scout_apm/instrument_manager.rb +1 -0
  30. data/lib/scout_apm/instruments/action_controller_rails_3_rails4.rb +47 -26
  31. data/lib/scout_apm/instruments/action_view.rb +21 -8
  32. data/lib/scout_apm/instruments/active_record.rb +17 -28
  33. data/lib/scout_apm/instruments/typhoeus.rb +88 -0
  34. data/lib/scout_apm/layer.rb +1 -1
  35. data/lib/scout_apm/middleware.rb +1 -1
  36. data/lib/scout_apm/remote/server.rb +13 -1
  37. data/lib/scout_apm/reporter.rb +8 -3
  38. data/lib/scout_apm/serializers/payload_serializer_to_json.rb +6 -2
  39. data/lib/scout_apm/slow_policy/age_policy.rb +33 -0
  40. data/lib/scout_apm/slow_policy/percent_policy.rb +22 -0
  41. data/lib/scout_apm/slow_policy/percentile_policy.rb +24 -0
  42. data/lib/scout_apm/slow_policy/policy.rb +21 -0
  43. data/lib/scout_apm/slow_policy/speed_policy.rb +16 -0
  44. data/lib/scout_apm/slow_request_policy.rb +18 -77
  45. data/lib/scout_apm/tracer.rb +2 -2
  46. data/lib/scout_apm/utils/sql_sanitizer.rb +1 -0
  47. data/lib/scout_apm/utils/sql_sanitizer_regex.rb +3 -3
  48. data/lib/scout_apm/utils/sql_sanitizer_regex_1_8_7.rb +1 -0
  49. data/lib/scout_apm/version.rb +1 -1
  50. data/scout_apm.gemspec +6 -6
  51. data/test/unit/agent_context_test.rb +29 -0
  52. data/test/unit/environment_test.rb +2 -2
  53. data/test/unit/error_service/error_buffer_test.rb +25 -0
  54. data/test/unit/error_service/ignored_exceptions_test.rb +49 -0
  55. data/test/unit/serializers/payload_serializer_test.rb +36 -0
  56. data/test/unit/slow_request_policy_test.rb +41 -13
  57. data/test/unit/sql_sanitizer_test.rb +38 -0
  58. data/test/unit/tracer_test.rb +25 -0
  59. metadata +27 -61
  60. data/lib/scout_apm/slow_job_policy.rb +0 -111
  61. data/test/unit/slow_job_policy_test.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73af2b28e0b054233c1ccd48122741d7b8e27adf9c61ee93fea520f7e3a6b3c7
4
- data.tar.gz: 544c20bf5c56478269232f19a792dcbc00c125befb6e5e7b406be04dc954944e
3
+ metadata.gz: 16b10ca7e3c7474546feb2b367438e9fabeb2c799e85608b96afb3ddea37b647
4
+ data.tar.gz: 044ced73909cff452e59bccf14e7dfcf344fd8f6262c5b633b0d3239995609fd
5
5
  SHA512:
6
- metadata.gz: c8558cd998a6c54ca7cd3c3174ba96c28230b0041a49e2d494460116a6f9065ba28f998ce8a74b546f69a8f1d5ec5dd81b9be29e27f4a874f51e1352f02798f0
7
- data.tar.gz: 18f7152a257b7ff61cb0c4953542527a2af25220d726ac26ade9242421f817afc83ce18fa28ea018188215717cedb25336ba79a61572cb706f99f16278be3545
6
+ metadata.gz: c2ae77ef620e77bce7b267fe8c39ff2f91945dfffc3ad008dd01cbd3b45268a8b44624713652d1df2bdeb2789bedb1fdb98aa58742b48326b1821ea01482132d
7
+ data.tar.gz: c533bf6cf2822f7688b4377e9f69e005eb1255c0c03cd000dd5d4edaef74b7761b4b8af9b8d39d1229480fd7f2cd0b0f6bcaf1890be5b3f6a9540bf7f8e03f64
@@ -0,0 +1,49 @@
1
+ name: Tests
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ lint:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - uses: ruby/setup-ruby@v1
12
+ with:
13
+ bundler-cache: true
14
+ ruby-version: 2.6
15
+ - run: bundle exec rubocop
16
+
17
+ test:
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ include:
22
+ - ruby: 2.1
23
+ gemfile: gems/rails3.gemfile
24
+ - ruby: 2.2
25
+ - ruby: 2.3
26
+ - ruby: 2.4
27
+ - ruby: 2.5
28
+ - ruby: 2.6
29
+ - ruby: 2.6
30
+ gemfile: gems/octoshark.gemfile
31
+ - ruby: 2.6
32
+ gemfile: gems/rails3.gemfile
33
+ bundler: 1.17.3
34
+ - ruby: 2.7
35
+ - ruby: 3.0
36
+
37
+ env:
38
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
39
+
40
+ runs-on: ubuntu-latest
41
+
42
+ steps:
43
+ - uses: actions/checkout@v2
44
+ - uses: ruby/setup-ruby@v1
45
+ with:
46
+ bundler-cache: true
47
+ bundler: ${{matrix.bundler}}
48
+ ruby-version: ${{ matrix.ruby }}
49
+ - run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -4,13 +4,10 @@ AllCops:
4
4
  Exclude:
5
5
  - 'test/unit/auto_instrument/*'
6
6
  - vendor/bundle/**/*
7
+ SuggestExtensions: false
7
8
 
8
9
  # 80 is stifling, especially with a few levels of nesting before we even start.
9
10
  # So bump it to 100 to keep really long lines from creeping in.
10
- Metrics/LineLength:
11
+ Layout/LineLength:
11
12
  Enabled: false
12
13
  Max: 100
13
-
14
- Style/HashSyntax:
15
- Enabled: true
16
- EnforcedStyle: hash_rockets
data/.travis.yml CHANGED
@@ -1,15 +1,9 @@
1
1
  language: ruby
2
- dist: trusty
2
+ dist: xenial
3
3
  cache: bundler
4
4
 
5
5
  matrix:
6
6
  include:
7
- - rvm: "1.8.7"
8
- gemfile: gems/rails3.gemfile
9
- - rvm: "1.9.3"
10
- gemfile: gems/rails3.gemfile
11
- - rvm: 2.0
12
- gemfile: gems/rails3.gemfile
13
7
  - rvm: 2.1
14
8
  gemfile: gems/rails3.gemfile
15
9
  - rvm: 2.2
@@ -17,6 +11,8 @@ matrix:
17
11
  - rvm: 2.4
18
12
  - rvm: 2.5
19
13
  - rvm: 2.6
14
+ - rvm: 2.7
15
+ - rvm: 3.0
20
16
  - rvm: 2.6
21
17
  gemfile: gems/octoshark.gemfile
22
18
  - rvm: 2.6
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,54 @@
1
+ # 4.0.4
2
+
3
+ * Add Faktory Support (#385)
4
+ * Remove Regexp hack for 1.8.7 (no longer supported) (#384)
5
+ * More robust DelayedJob detection (#382)
6
+ * Fix kwargs handling in Tracing module (#381)
7
+ # 4.0.3
8
+
9
+ * Handle edge case with nil Typhoeus current-layer (#380)
10
+ * Fix args passing to render_partial (#379)
11
+
12
+ # 4.0.2
13
+
14
+ * Add Typhoeus instrumentation (#376)
15
+
16
+ # 4.0.1
17
+
18
+ * Add support for Ruby 3.0 (#374)
19
+ * Use Github Actions for CI (#370)
20
+ * Fix edge case in sanitization of Postgres SQL (#368)
21
+
22
+ # 4.0.0
23
+
24
+ * Require Ruby >= 2.1 (#270)
25
+ * ErrorService reporting. Enable with `errors_enabled` config setting. (#347)
26
+ * Modular SlowRequestPolicy (#364)
27
+ * Fix deprecation warnings (#354)
28
+
29
+ # 2.6.10
30
+
31
+ * Fix an edge case in JSON serialization (#360)
32
+
33
+ # 2.6.9
34
+
35
+ * Add `ssl_cert_file` config option (#352)
36
+ * Improve sanitization of Postgres UPDATE SQL (#351)
37
+ * Allow custom URL sanitization (#341)
38
+
39
+ # 2.6.8
40
+
41
+ * Lock rake version for 1.8.7 to older version (#329)
42
+ * Delete unneeded .DS_Store file that snuck in (#334)
43
+ * Fix typo in "queue_time_ms"
44
+ * Fix Rails 6 deprecation warning at boot time (#337)
45
+ * Fix partial naming on Rails 6.0 (#339)
46
+ * Support Sidekiq 6.1 instrumentation (#340)
47
+
48
+ # 2.6.7
49
+
50
+ * Remove accidental call to `as_json`
51
+
1
52
  # 2.6.6
2
53
 
3
54
  * Add basic support for parsing Microsoft SQLServer queries (#317)
data/Gemfile CHANGED
@@ -3,11 +3,4 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in scout_apm.gemspec
4
4
  gemspec
5
5
 
6
- # Pin development dependencies more conservatively for Ruby 1.8.7
7
- if RUBY_VERSION <= "1.8.7"
8
- gem "activesupport", "~> 3.2"
9
- gem "i18n", "~> 0.6.11"
10
- gem "pry", "~> 0.9.12"
11
- gem "rake", "~> 10.5"
12
- gem "minitest", "~> 5.11.3"
13
- end
6
+ gem "rake", ">= 12.3.3"
data/gems/rails6.gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  eval_gemfile("../Gemfile")
2
2
 
3
- gem "rails", "~> 6.0.0rc1"
3
+ gem "rails", "~> 6.0"
4
4
  gem "sqlite3", "~> 1.4"
data/lib/scout_apm.rb CHANGED
@@ -58,6 +58,7 @@ require 'scout_apm/server_integrations/webrick'
58
58
  require 'scout_apm/server_integrations/null'
59
59
 
60
60
  require 'scout_apm/background_job_integrations/sidekiq'
61
+ require 'scout_apm/background_job_integrations/faktory'
61
62
  require 'scout_apm/background_job_integrations/delayed_job'
62
63
  require 'scout_apm/background_job_integrations/resque'
63
64
  require 'scout_apm/background_job_integrations/shoryuken'
@@ -78,6 +79,7 @@ require 'scout_apm/histogram'
78
79
 
79
80
  require 'scout_apm/instruments/net_http'
80
81
  require 'scout_apm/instruments/http_client'
82
+ require 'scout_apm/instruments/typhoeus'
81
83
  require 'scout_apm/instruments/moped'
82
84
  require 'scout_apm/instruments/mongoid'
83
85
  require 'scout_apm/instruments/memcached'
@@ -144,8 +146,13 @@ require 'scout_apm/slow_transaction'
144
146
  require 'scout_apm/slow_job_record'
145
147
  require 'scout_apm/detailed_trace'
146
148
  require 'scout_apm/scored_item_set'
149
+
147
150
  require 'scout_apm/slow_request_policy'
148
- require 'scout_apm/slow_job_policy'
151
+ require 'scout_apm/slow_policy/age_policy'
152
+ require 'scout_apm/slow_policy/speed_policy'
153
+ require 'scout_apm/slow_policy/percent_policy'
154
+ require 'scout_apm/slow_policy/percentile_policy'
155
+
149
156
  require 'scout_apm/job_record'
150
157
  require 'scout_apm/request_histograms'
151
158
  require 'scout_apm/transaction_time_consumed'
@@ -186,6 +193,16 @@ require 'scout_apm/tasks/support'
186
193
  require 'scout_apm/extensions/config'
187
194
  require 'scout_apm/extensions/transaction_callback_payload'
188
195
 
196
+ require 'scout_apm/error_service'
197
+ require 'scout_apm/error_service/middleware'
198
+ require 'scout_apm/error_service/notifier'
199
+ require 'scout_apm/error_service/sidekiq'
200
+ require 'scout_apm/error_service/ignored_exceptions'
201
+ require 'scout_apm/error_service/error_buffer'
202
+ require 'scout_apm/error_service/error_record'
203
+ require 'scout_apm/error_service/periodic_work'
204
+ require 'scout_apm/error_service/payload'
205
+
189
206
  if defined?(Rails) && defined?(Rails::VERSION) && defined?(Rails::VERSION::MAJOR) && Rails::VERSION::MAJOR >= 3 && defined?(Rails::Railtie)
190
207
  module ScoutApm
191
208
  class Railtie < Rails::Railtie
@@ -205,6 +222,11 @@ if defined?(Rails) && defined?(Rails::VERSION) && defined?(Rails::VERSION::MAJOR
205
222
  ScoutApm::Agent.instance.context.logger.debug("AutoInstruments is disabled.")
206
223
  end
207
224
 
225
+ if ScoutApm::Agent.instance.context.config.value("errors_enabled")
226
+ app.config.middleware.insert_after ActionDispatch::DebugExceptions, ScoutApm::ErrorService::Middleware
227
+ ScoutApm::ErrorService::Sidekiq.new.install
228
+ end
229
+
208
230
  # Install the middleware every time in development mode.
209
231
  # The middleware is a noop if dev_trace is not enabled in config
210
232
  if Rails.env.development?
@@ -66,6 +66,7 @@ module ScoutApm
66
66
 
67
67
  if context.started?
68
68
  start_background_worker unless background_worker_running?
69
+ start_error_service_background_worker unless error_service_background_worker_running?
69
70
  return
70
71
  end
71
72
 
@@ -81,6 +82,7 @@ module ScoutApm
81
82
  @app_server_load ||= AppServerLoad.new(context).run
82
83
 
83
84
  start_background_worker
85
+ start_error_service_background_worker
84
86
  end
85
87
 
86
88
  def instrument_manager
@@ -198,5 +200,25 @@ module ScoutApm
198
200
  @background_worker &&
199
201
  @background_worker.running?
200
202
  end
203
+
204
+ # seconds to batch error reports
205
+ ERROR_SEND_FREQUENCY = 5
206
+ def start_error_service_background_worker
207
+ periodic_work = ScoutApm::ErrorService::PeriodicWork.new(context)
208
+
209
+ @error_service_background_worker = ScoutApm::BackgroundWorker.new(context, ERROR_SEND_FREQUENCY)
210
+ @error_service_background_worker_thread = Thread.new do
211
+ @error_service_background_worker.start {
212
+ periodic_work.run
213
+ }
214
+ end
215
+ end
216
+
217
+ def error_service_background_worker_running?
218
+ @error_service_background_worker_thread &&
219
+ @error_service_background_worker_thread.alive? &&
220
+ @error_service_background_worker &&
221
+ @error_service_background_worker.running?
222
+ end
201
223
  end
202
224
  end
@@ -96,11 +96,11 @@ module ScoutApm
96
96
  end
97
97
 
98
98
  def slow_request_policy
99
- @slow_request_policy ||= ScoutApm::SlowRequestPolicy.new(self)
99
+ @slow_request_policy ||= ScoutApm::SlowRequestPolicy.new(self).tap{|p| p.add_default_policies }
100
100
  end
101
101
 
102
102
  def slow_job_policy
103
- @slow_job_policy ||= ScoutApm::SlowJobPolicy.new(self)
103
+ @slow_job_policy ||= ScoutApm::SlowRequestPolicy.new(self).tap{|p| p.add_default_policies }
104
104
  end
105
105
 
106
106
  # Maintains a Histogram of insignificant/significant autoinstrument layers.
@@ -142,6 +142,18 @@ module ScoutApm
142
142
  config.value('dev_trace') && environment.env == "development"
143
143
  end
144
144
 
145
+ ###################
146
+ # Error Service #
147
+ ###################
148
+
149
+ def error_buffer
150
+ @error_buffer ||= ScoutApm::ErrorService::ErrorBuffer.new(self)
151
+ end
152
+
153
+ def ignored_exceptions
154
+ @ignored_exceptions ||= ScoutApm::ErrorService::IgnoredExceptions.new(self, config.value('errors_ignored_exceptions'))
155
+ end
156
+
145
157
  #############
146
158
  # Setters #
147
159
  #############
@@ -11,7 +11,7 @@ module ScoutApm
11
11
  end
12
12
 
13
13
  def present?
14
- defined?(::Delayed::Job)
14
+ defined?(::Delayed::Worker)
15
15
  end
16
16
 
17
17
  def forking?
@@ -0,0 +1,103 @@
1
+ module ScoutApm
2
+ module BackgroundJobIntegrations
3
+ class Faktory
4
+ attr_reader :logger
5
+
6
+ def name
7
+ :faktory
8
+ end
9
+
10
+ def present?
11
+ defined?(::Faktory)
12
+ end
13
+
14
+ def forking?
15
+ false
16
+ end
17
+
18
+ def install
19
+ add_middleware
20
+ install_processor
21
+ end
22
+
23
+ def add_middleware
24
+ ::Faktory.configure_worker do |config|
25
+ config.worker_middleware do |chain|
26
+ chain.add FaktoryMiddleware
27
+ end
28
+ end
29
+ end
30
+
31
+ def install_processor
32
+ require 'faktory/processor' # sidekiq v4 has not loaded this file by this point
33
+
34
+ ::Faktory::Processor.class_eval do
35
+ def initialize_with_scout(*args)
36
+ agent = ::ScoutApm::Agent.instance
37
+ agent.start
38
+ initialize_without_scout(*args)
39
+ end
40
+
41
+ alias_method :initialize_without_scout, :initialize
42
+ alias_method :initialize, :initialize_with_scout
43
+ end
44
+ end
45
+ end
46
+
47
+ # We insert this middleware into the Sidekiq stack, to capture each job,
48
+ # and time them.
49
+ class FaktoryMiddleware
50
+ def call(worker_instance, job)
51
+ queue = job["queue"]
52
+
53
+ req = ScoutApm::RequestManager.lookup
54
+ req.annotate_request(:queue_latency => latency(job))
55
+
56
+ begin
57
+ req.start_layer(ScoutApm::Layer.new('Queue', queue))
58
+ started_queue = true
59
+ req.start_layer(ScoutApm::Layer.new('Job', job_class(job)))
60
+ started_job = true
61
+
62
+ yield
63
+ rescue
64
+ req.error!
65
+ raise
66
+ ensure
67
+ req.stop_layer if started_job
68
+ req.stop_layer if started_queue
69
+ end
70
+ end
71
+
72
+ UNKNOWN_CLASS_PLACEHOLDER = 'UnknownJob'.freeze
73
+ ACTIVE_JOB_KLASS = 'ActiveJob::QueueAdapters::FaktoryAdapter::JobWrapper'.freeze
74
+
75
+ def job_class(job)
76
+ job_class = job.fetch('jobtype', UNKNOWN_CLASS_PLACEHOLDER)
77
+
78
+ if job_class == ACTIVE_JOB_KLASS && job.key?('custom') && job['custom'].key?('wrapped')
79
+ begin
80
+ job_class = job['custom']['wrapped']
81
+ rescue
82
+ ACTIVE_JOB_KLASS
83
+ end
84
+ end
85
+
86
+ job_class
87
+ rescue
88
+ UNKNOWN_CLASS_PLACEHOLDER
89
+ end
90
+
91
+ def latency(job, time = Time.now)
92
+ created_at = Time.parse(job['enqueued_at'] || job['created_at'])
93
+ if created_at
94
+ (time - created_at)
95
+ else
96
+ 0
97
+ end
98
+ rescue
99
+ 0
100
+ end
101
+ end
102
+ end
103
+ end
@@ -40,10 +40,10 @@ module ScoutApm
40
40
  require 'sidekiq/processor' # sidekiq v4 has not loaded this file by this point
41
41
 
42
42
  ::Sidekiq::Processor.class_eval do
43
- def initialize_with_scout(boss)
43
+ def initialize_with_scout(*args)
44
44
  agent = ::ScoutApm::Agent.instance
45
45
  agent.start
46
- initialize_without_scout(boss)
46
+ initialize_without_scout(*args)
47
47
  end
48
48
 
49
49
  alias_method :initialize_without_scout, :initialize
@@ -75,11 +75,18 @@ module ScoutApm
75
75
  'revision_sha',
76
76
  'scm_subdirectory',
77
77
  'start_resque_server_instrument',
78
+ 'ssl_cert_file',
78
79
  'uri_reporting',
79
80
  'instrument_http_url_length',
80
81
  'timeline_traces',
81
82
  'auto_instruments',
82
- 'auto_instruments_ignore'
83
+ 'auto_instruments_ignore',
84
+
85
+ # Error Service Related Configuration
86
+ 'errors_enabled',
87
+ 'errors_ignored_exceptions',
88
+ 'errors_filtered_params',
89
+ 'errors_host',
83
90
  ]
84
91
 
85
92
  ################################################################################
@@ -175,6 +182,9 @@ module ScoutApm
175
182
  'timeline_traces' => BooleanCoercion.new,
176
183
  'auto_instruments' => BooleanCoercion.new,
177
184
  'auto_instruments_ignore' => JsonCoercion.new,
185
+ 'errors_enabled' => BooleanCoercion.new,
186
+ 'errors_ignored_exceptions' => JsonCoercion.new,
187
+ 'errors_filtered_params' => JsonCoercion.new,
178
188
  }
179
189
 
180
190
 
@@ -284,7 +294,12 @@ module ScoutApm
284
294
  'collect_remote_ip' => true,
285
295
  'timeline_traces' => true,
286
296
  'auto_instruments' => false,
287
- 'auto_instruments_ignore' => []
297
+ 'auto_instruments_ignore' => [],
298
+ 'ssl_cert_file' => File.join( File.dirname(__FILE__), *%w[.. .. data cacert.pem] ),
299
+ 'errors_enabled' => false,
300
+ 'errors_ignored_exceptions' => %w(ActiveRecord::RecordNotFound ActionController::RoutingError),
301
+ 'errors_filtered_params' => %w(password s3-key),
302
+ 'errors_host' => 'https://errors.scoutapm.com',
288
303
  }.freeze
289
304
 
290
305
  def value(key)