scout_apm 2.6.1 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 302bcce1cb8a4e8e1a000857fed8764438486e8d9a1c7df47c4cd9af475d6468
4
- data.tar.gz: ff41334b370a15f45262c5fc6e215400c100f13beb41cd4bbafcbe2800e1ad9f
3
+ metadata.gz: bfac08a037b046a0775634ea7ba351a9e3310c3eb4ea3bedd0571bead3984379
4
+ data.tar.gz: 4218e6a354d14dfc920cf34f86dd556c25e2fe8be04f78d43963ea00ad7ec9a9
5
5
  SHA512:
6
- metadata.gz: 50e3e4e094927f4add2b1839a9f4b5d8ded24785fc52fce7e37d5931c12e685b0be0234c3c2c5714cc366dcf4dc3dbe0c8f3d8d949e871a552011c558d65e6a5
7
- data.tar.gz: 83f98b354e219d40b449df8e7ae121bf0f084e8ac7d7ac7c0d71c32c295791779a6c8720551e92e73f7a4592dfad9d10d709c47e619dc797c6557a8ac7523679
6
+ metadata.gz: 87aa046c482068c6bd85c14fa9550796099fb6517fd17eeb10888f61d6ccd4ed724e51deb57c6c9598d556f5f7f48a4faed4457d4c2c0e6d4eaf97c66e4004df
7
+ data.tar.gz: ac15c172111160f119c56cae0bdd6494704b481bb02a22a97cd5d373fafa3e5d747039c412b3bc50cf0e1f293b0c32542fbbd8a2547cdbbaf918898f5c382901
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,9 @@
1
+ # 2.6.2
2
+
3
+ * Fix Autoinstruments logging when running without ActiveSupport (#290)
4
+ * Fix edge-case Autoinstruments syntax error (#287)
5
+ * Fix invalid syntax for running on Ruby 1.8.7
6
+
1
7
  # 2.6.1
2
8
 
3
9
  * Logging total autoinstrumented spans and the ratio of significant to total spans (#283).
data/Gemfile CHANGED
@@ -9,4 +9,5 @@ if RUBY_VERSION <= "1.8.7"
9
9
  gem "i18n", "~> 0.6.11"
10
10
  gem "pry", "~> 0.9.12"
11
11
  gem "rake", "~> 10.5"
12
+ gem "minitest", "~> 5.11.3"
12
13
  end
@@ -1,8 +1,10 @@
1
1
 
2
2
  module ScoutApm
3
- def self.AutoInstrument(name, backtrace, file_name)
3
+ def self.AutoInstrument(name, backtrace)
4
4
  request = ScoutApm::RequestManager.lookup
5
5
 
6
+ file_name, _ = backtrace.first.split(":", 2)
7
+
6
8
  begin
7
9
  layer = ScoutApm::Layer.new('AutoInstrument', name)
8
10
  layer.backtrace = backtrace
@@ -73,7 +73,7 @@ module ScoutApm
73
73
  bt = ["#{file_name}:#{line}:in `#{method_name}'"]
74
74
 
75
75
  return [
76
- "::ScoutApm::AutoInstrument("+ source.dump + ",#{bt}" + ",'#{file_name}'" + "){",
76
+ "::ScoutApm::AutoInstrument("+ source.dump + ",#{bt}){",
77
77
  "}"
78
78
  ]
79
79
  end
@@ -102,6 +102,10 @@ module ScoutApm
102
102
  return
103
103
  end
104
104
 
105
+ def on_op_asgn(node)
106
+ process(node.children[2])
107
+ end
108
+
105
109
  def on_or_asgn(node)
106
110
  process(node.children[1])
107
111
  end
@@ -12,19 +12,24 @@ module ScoutApm
12
12
  ScoutApm::Debug.instance.call_periodic_hooks
13
13
  @reporting.process_metrics
14
14
  clean_old_percentiles
15
- log_layer_histograms
15
+
16
+ if context.config.value('auto_instruments')
17
+ log_autoinstrument_significant_counts rescue nil
18
+ end
16
19
  end
17
20
 
18
21
  private
19
22
 
20
- def log_layer_histograms
23
+ def log_autoinstrument_significant_counts
21
24
  # Ex key/value -
22
25
  # "/Users/dlite/projects/scout/apm/app/controllers/application_controller.rb"=>[[0.0, 689], [1.0, 16]]
23
26
  hists = context.auto_instruments_layer_histograms.as_json
24
- hists_summary = hists.map { |k,v|
27
+ hists_summary = hists.map { |file, buckets|
28
+ total = buckets.map(&:last).inject(0) { |sum, count| sum + count }
29
+ significant = (buckets.last.last / total.to_f).round(2)
25
30
  [
26
- k,
27
- {:total => total=v.map(&:last).inject(:+), :significant => (v.last.last/total.to_f).round(2)}
31
+ file,
32
+ {:total => total, :significant => significant}
28
33
  ]
29
34
  }.to_h
30
35
  context.logger.debug("AutoInstrument Significant Layer Histograms: #{hists_summary.pretty_inspect}")
@@ -23,7 +23,11 @@ module ScoutApm
23
23
  end
24
24
 
25
25
  def as_json
26
- @histograms.as_json
26
+ Hash[
27
+ @histograms.map{ |key, histogram|
28
+ [key, histogram.as_json]
29
+ }
30
+ ]
27
31
  end
28
32
 
29
33
  def add(item, value)
@@ -1,3 +1,3 @@
1
1
  module ScoutApm
2
- VERSION = "2.6.1"
2
+ VERSION = "2.6.2"
3
3
  end
@@ -1,26 +1,31 @@
1
1
 
2
2
  class Assignments
3
+ def test_op_asgn
4
+ foo.bar += ::ScoutApm::AutoInstrument("User.size",["ROOT/test/unit/auto_instrument/assignments.rb:4:in `test_op_asgn'"]){User.size}
5
+ foo.bar -= ::ScoutApm::AutoInstrument("User.size",["ROOT/test/unit/auto_instrument/assignments.rb:5:in `test_op_asgn'"]){User.size}
6
+ end
7
+
3
8
  def nested_assignment
4
- @email ||= if (email = ::ScoutApm::AutoInstrument("session[\"email\"]",["BACKTRACE"],'FILE_NAME'){session["email"]}).present?
5
- ::ScoutApm::AutoInstrument("User.where(email: email).first",["BACKTRACE"],'FILE_NAME'){User.where(email: email).first}
9
+ @email ||= if (email = ::ScoutApm::AutoInstrument("session[\"email\"]",["ROOT/test/unit/auto_instrument/assignments.rb:9:in `nested_assignment'"]){session["email"]}).present?
10
+ ::ScoutApm::AutoInstrument("User.where(email: email).first",["ROOT/test/unit/auto_instrument/assignments.rb:10:in `nested_assignment'"]){User.where(email: email).first}
6
11
  else
7
12
  nil
8
13
  end
9
14
  end
10
15
 
11
16
  def paginate_collection(coll)
12
- page = (::ScoutApm::AutoInstrument("params[:page].present?",["BACKTRACE"],'FILE_NAME'){params[:page].to_i} : 1)
13
- per_page = (::ScoutApm::AutoInstrument("params[:per_page].present?",["BACKTRACE"],'FILE_NAME'){params[:per_page].to_i} : 20)
14
- pagination, self.collection = ::ScoutApm::AutoInstrument("pagy(...",["BACKTRACE"],'FILE_NAME'){pagy(
17
+ page = (::ScoutApm::AutoInstrument("params[:page].present?",["ROOT/test/unit/auto_instrument/assignments.rb:17:in `paginate_collection'"]){params[:page].present?} ? ::ScoutApm::AutoInstrument("params[:page].to_i",["ROOT/test/unit/auto_instrument/assignments.rb:17:in `paginate_collection'"]){params[:page].to_i} : 1)
18
+ per_page = (::ScoutApm::AutoInstrument("params[:per_page].present?",["ROOT/test/unit/auto_instrument/assignments.rb:18:in `paginate_collection'"]){params[:per_page].present?} ? ::ScoutApm::AutoInstrument("params[:per_page].to_i",["ROOT/test/unit/auto_instrument/assignments.rb:18:in `paginate_collection'"]){params[:per_page].to_i} : 20)
19
+ pagination, self.collection = ::ScoutApm::AutoInstrument("pagy(...",["ROOT/test/unit/auto_instrument/assignments.rb:19:in `paginate_collection'"]){pagy(
15
20
  coll,
16
21
  items: per_page,
17
22
  page: page
18
23
  )}
19
- ::ScoutApm::AutoInstrument("headers[PAGINATION_TOTAL_HEADER] = pagination.count.to_s",["BACKTRACE"],'FILE_NAME'){headers[PAGINATION_TOTAL_HEADER] = pagination.count.to_s}
20
- ::ScoutApm::AutoInstrument("headers[PAGINATION_TOTAL_PAGES_HEADER] = pagination.pages.to_s",["BACKTRACE"],'FILE_NAME'){headers[PAGINATION_TOTAL_PAGES_HEADER] = pagination.pages.to_s}
21
- ::ScoutApm::AutoInstrument("headers[PAGINATION_PER_PAGE_HEADER] = per_page.to_s",["BACKTRACE"],'FILE_NAME'){headers[PAGINATION_PER_PAGE_HEADER] = per_page.to_s}
22
- ::ScoutApm::AutoInstrument("headers[PAGINATION_PAGE_HEADER] = pagination.page.to_s",["BACKTRACE"],'FILE_NAME'){headers[PAGINATION_PAGE_HEADER] = pagination.page.to_s}
23
- ::ScoutApm::AutoInstrument("headers[PAGINATION_NEXT_PAGE_HEADER] = pagination.next.to_s",["BACKTRACE"],'FILE_NAME'){headers[PAGINATION_NEXT_PAGE_HEADER] = pagination.next.to_s}
24
- ::ScoutApm::AutoInstrument("collection",["BACKTRACE"],'FILE_NAME'){collection}
24
+ ::ScoutApm::AutoInstrument("headers[PAGINATION_TOTAL_HEADER] = pagination.count.to_s",["ROOT/test/unit/auto_instrument/assignments.rb:24:in `paginate_collection'"]){headers[PAGINATION_TOTAL_HEADER] = pagination.count.to_s}
25
+ ::ScoutApm::AutoInstrument("headers[PAGINATION_TOTAL_PAGES_HEADER] = pagination.pages.to_s",["ROOT/test/unit/auto_instrument/assignments.rb:25:in `paginate_collection'"]){headers[PAGINATION_TOTAL_PAGES_HEADER] = pagination.pages.to_s}
26
+ ::ScoutApm::AutoInstrument("headers[PAGINATION_PER_PAGE_HEADER] = per_page.to_s",["ROOT/test/unit/auto_instrument/assignments.rb:26:in `paginate_collection'"]){headers[PAGINATION_PER_PAGE_HEADER] = per_page.to_s}
27
+ ::ScoutApm::AutoInstrument("headers[PAGINATION_PAGE_HEADER] = pagination.page.to_s",["ROOT/test/unit/auto_instrument/assignments.rb:27:in `paginate_collection'"]){headers[PAGINATION_PAGE_HEADER] = pagination.page.to_s}
28
+ ::ScoutApm::AutoInstrument("headers[PAGINATION_NEXT_PAGE_HEADER] = pagination.next.to_s",["ROOT/test/unit/auto_instrument/assignments.rb:28:in `paginate_collection'"]){headers[PAGINATION_NEXT_PAGE_HEADER] = pagination.next.to_s}
29
+ ::ScoutApm::AutoInstrument("collection",["ROOT/test/unit/auto_instrument/assignments.rb:29:in `paginate_collection'"]){collection}
25
30
  end
26
31
  end
@@ -1,5 +1,10 @@
1
1
 
2
2
  class Assignments
3
+ def test_op_asgn
4
+ foo.bar += User.size
5
+ foo.bar -= User.size
6
+ end
7
+
3
8
  def nested_assignment
4
9
  @email ||= if (email = session["email"]).present?
5
10
  User.where(email: email).first
@@ -3,47 +3,47 @@ class ClientsController < ApplicationController
3
3
  before_action :check_authorization
4
4
 
5
5
  def index
6
- if ::ScoutApm::AutoInstrument("params[:status] == \"activated\"",["BACKTRACE"],'FILE_NAME'){params[:status] == "activated"}
7
- @clients = ::ScoutApm::AutoInstrument("Client.activated",["BACKTRACE"],'FILE_NAME'){Client.activated}
6
+ if ::ScoutApm::AutoInstrument("params[:status] == \"activated\"",["ROOT/test/unit/auto_instrument/controller.rb:6:in `index'"]){params[:status] == "activated"}
7
+ @clients = ::ScoutApm::AutoInstrument("Client.activated",["ROOT/test/unit/auto_instrument/controller.rb:7:in `index'"]){Client.activated}
8
8
  else
9
- @clients = ::ScoutApm::AutoInstrument("Client.inactivated",["BACKTRACE"],'FILE_NAME'){Client.inactivated}
9
+ @clients = ::ScoutApm::AutoInstrument("Client.inactivated",["ROOT/test/unit/auto_instrument/controller.rb:9:in `index'"]){Client.inactivated}
10
10
  end
11
11
  end
12
12
 
13
13
  def create
14
- @client = ::ScoutApm::AutoInstrument("Client.new(params[:client])",["BACKTRACE"],'FILE_NAME'){Client.new(params[:client])}
15
- if ::ScoutApm::AutoInstrument("@client.save",["BACKTRACE"],'FILE_NAME'){@client.save}
16
- ::ScoutApm::AutoInstrument("redirect_to @client",["BACKTRACE"],'FILE_NAME'){redirect_to @client}
14
+ @client = ::ScoutApm::AutoInstrument("Client.new(params[:client])",["ROOT/test/unit/auto_instrument/controller.rb:14:in `create'"]){Client.new(params[:client])}
15
+ if ::ScoutApm::AutoInstrument("@client.save",["ROOT/test/unit/auto_instrument/controller.rb:15:in `create'"]){@client.save}
16
+ ::ScoutApm::AutoInstrument("redirect_to @client",["ROOT/test/unit/auto_instrument/controller.rb:16:in `create'"]){redirect_to @client}
17
17
  else
18
18
  # This line overrides the default rendering behavior, which
19
19
  # would have been to render the "create" view.
20
- ::ScoutApm::AutoInstrument("render \"new\"",["BACKTRACE"],'FILE_NAME'){render "new"}
20
+ ::ScoutApm::AutoInstrument("render \"new\"",["ROOT/test/unit/auto_instrument/controller.rb:20:in `create'"]){render "new"}
21
21
  end
22
22
  end
23
23
 
24
24
  def edit
25
- @client = ::ScoutApm::AutoInstrument("Client.new(params[:client])",["BACKTRACE"],'FILE_NAME'){Client.new(params[:client])}
25
+ @client = ::ScoutApm::AutoInstrument("Client.new(params[:client])",["ROOT/test/unit/auto_instrument/controller.rb:25:in `edit'"]){Client.new(params[:client])}
26
26
 
27
- if ::ScoutApm::AutoInstrument("request.post?",["BACKTRACE"],'FILE_NAME'){request.post?}
28
- ::ScoutApm::AutoInstrument("@client.transaction do...",["BACKTRACE"],'FILE_NAME'){@client.transaction do
27
+ if ::ScoutApm::AutoInstrument("request.post?",["ROOT/test/unit/auto_instrument/controller.rb:27:in `edit'"]){request.post?}
28
+ ::ScoutApm::AutoInstrument("@client.transaction do...",["ROOT/test/unit/auto_instrument/controller.rb:28:in `edit'"]){@client.transaction do
29
29
  @client.update_attributes(params[:client])
30
30
  end}
31
31
  end
32
32
  end
33
33
 
34
34
  def data
35
- @clients = ::ScoutApm::AutoInstrument("Client.all",["BACKTRACE"],'FILE_NAME'){Client.all}
35
+ @clients = ::ScoutApm::AutoInstrument("Client.all",["ROOT/test/unit/auto_instrument/controller.rb:35:in `data'"]){Client.all}
36
36
 
37
- formatter = ::ScoutApm::AutoInstrument("proc do |row|...",["BACKTRACE"],'FILE_NAME'){proc do |row|
37
+ formatter = ::ScoutApm::AutoInstrument("proc do |row|...",["ROOT/test/unit/auto_instrument/controller.rb:37:in `data'"]){proc do |row|
38
38
  row.to_json
39
39
  end}
40
40
 
41
- ::ScoutApm::AutoInstrument("respond_with @clients.each(&formatter).join(\"\\n\"), :content_type => 'FILE_NAME'}
41
+ ::ScoutApm::AutoInstrument("respond_with @clients.each(&formatter).join(\"\\n\"), :content_type => 'application/json; boundary=NL'",["ROOT/test/unit/auto_instrument/controller.rb:41:in `data'"]){respond_with @clients.each(&formatter).join("\n"), :content_type => 'application/json; boundary=NL'}
42
42
  end
43
43
 
44
44
  def things
45
45
  x = {}
46
46
  x[:this] ||= 'foo'
47
- x[:that] &&= ::ScoutApm::AutoInstrument("'FILE_NAME'.size}
47
+ x[:that] &&= ::ScoutApm::AutoInstrument("'foo'.size",["ROOT/test/unit/auto_instrument/controller.rb:47:in `things'"]){'foo'.size}
48
48
  end
49
49
  end
@@ -3,6 +3,8 @@ require 'test_helper'
3
3
  require 'scout_apm/auto_instrument'
4
4
 
5
5
  class AutoInstrumentTest < Minitest::Test
6
+ ROOT = File.expand_path("../../", __dir__)
7
+
6
8
  def source_path(name)
7
9
  File.expand_path("auto_instrument/#{name}.rb", __dir__)
8
10
  end
@@ -19,9 +21,7 @@ class AutoInstrumentTest < Minitest::Test
19
21
  # test controller.rb file, which will be different on different environments.
20
22
  # This normalizes backtraces across environments.
21
23
  def normalize_backtrace(string)
22
- string
23
- .gsub(/\[".+auto_instrument\/.+?:.+?"\]/,'["BACKTRACE"]')
24
- .gsub(/'.+auto_instrument\/.+'/,"'FILE_NAME'")
24
+ string.gsub(ROOT, "ROOT")
25
25
  end
26
26
 
27
27
  # Use this to automatically update the test fixtures.
@@ -33,18 +33,21 @@ class AutoInstrumentTest < Minitest::Test
33
33
 
34
34
  def test_controller_rewrite
35
35
  # update_instrumented_source("controller")
36
+
36
37
  assert_equal instrumented_source("controller"),
37
38
  normalize_backtrace(::ScoutApm::AutoInstrument::Rails.rewrite(source_path("controller")))
38
39
  end
39
40
 
40
41
  def test_rescue_from_rewrite
41
42
  # update_instrumented_source("rescue_from")
43
+
42
44
  assert_equal instrumented_source("rescue_from"),
43
45
  normalize_backtrace(::ScoutApm::AutoInstrument::Rails.rewrite(source_path("rescue_from")))
44
46
  end
45
47
 
46
48
  def test_assignments_rewrite
47
49
  # update_instrumented_source("assignments")
50
+
48
51
  assert_equal instrumented_source("assignments"),
49
52
  normalize_backtrace(::ScoutApm::AutoInstrument::Rails.rewrite(source_path("assignments")))
50
53
  end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ require 'scout_apm/request_histograms'
4
+
5
+ class RequestHistogramsTest < Minitest::Test
6
+ def test_as_json_without_activesupport
7
+ rh = ScoutApm::RequestHistograms.new
8
+
9
+ rh.add("foo", 1)
10
+ rh.add("foo", 2)
11
+ rh.add("bar", 3)
12
+
13
+ j = rh.as_json
14
+ assert_equal 2, j.size
15
+ assert_equal ["bar", "foo"], j.keys.sort
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.1
4
+ version: 2.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Haynes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-09-23 00:00:00.000000000 Z
12
+ date: 2019-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -423,6 +423,7 @@ files:
423
423
  - test/unit/remote/test_message.rb
424
424
  - test/unit/remote/test_router.rb
425
425
  - test/unit/remote/test_server.rb
426
+ - test/unit/request_histograms_test.rb
426
427
  - test/unit/scored_item_set_test.rb
427
428
  - test/unit/serializers/payload_serializer_test.rb
428
429
  - test/unit/slow_job_policy_test.rb
@@ -457,7 +458,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
457
458
  - !ruby/object:Gem::Version
458
459
  version: '0'
459
460
  requirements: []
460
- rubygems_version: 3.0.6
461
+ rubygems_version: 3.0.4
461
462
  signing_key:
462
463
  specification_version: 4
463
464
  summary: Ruby application performance monitoring
@@ -500,6 +501,7 @@ test_files:
500
501
  - test/unit/remote/test_message.rb
501
502
  - test/unit/remote/test_router.rb
502
503
  - test/unit/remote/test_server.rb
504
+ - test/unit/request_histograms_test.rb
503
505
  - test/unit/scored_item_set_test.rb
504
506
  - test/unit/serializers/payload_serializer_test.rb
505
507
  - test/unit/slow_job_policy_test.rb