traceview 3.7.1 → 3.8.0

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
  SHA1:
3
- metadata.gz: 359b1bc8a9eb076726debdfa9877132b49553360
4
- data.tar.gz: 38ec6fb80ca0e77367fb9d41c30f67bbf62b9ce0
3
+ metadata.gz: 1290a31bde98b6d4248897cf8e17f5e515818c16
4
+ data.tar.gz: 26e335a7365cfdc38c667520fa5f37f97517cc1c
5
5
  SHA512:
6
- metadata.gz: 5c9e9093ce6b0354ff054a3384554eb676d6e9189f0199a99b44ef74c74d3356ed39578ed6aef875b35b32ff45165807979ac6fce96cdef9eabc8609a1d4c26e
7
- data.tar.gz: 412b1d24a644d99a09890aad627a0eacfa57f18a063fae98a612fcb55100a37288eb00dd7709572240f74c686ea7425f83aefe68ef952671690def8abb31e69d
6
+ metadata.gz: fb16839d64fe8562ef5e0e8afe8ff6448d773b38889d5b146b309addda5156503d0d34c03a76a940e226eb7e3ed1d6e01cb8e487d0d7ab6132dcb80369238c65
7
+ data.tar.gz: 7be6d76914a3be0e20513956794d9790d185de3eb5c22c21cc2bbcdadcdd6ee531f1ff956e45c7dd18bd78a2ae0a92c400d44b8283f9d34ea7058afc67f1025d
data/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ https://github.com/appneta/oboe-ruby/releases
4
4
 
5
5
  Dates in this file are in the format MM/DD/YYYY.
6
6
 
7
+ # traceview 3.8.0
8
+
9
+ This minor release includes the following new feature:
10
+
11
+ * New instrumentation for Rails API based controllers: #166
12
+
13
+ Pushed to Rubygems:
14
+
15
+ https://rubygems.org/gems/traceview/versions/3.8.0
16
+ https://rubygems.org/gems/traceview/versions/3.8.0-java
17
+
7
18
  # traceview 3.7.1
8
19
 
9
20
  This patch release includes the following fixes:
data/Rakefile CHANGED
@@ -25,7 +25,14 @@ Rake::TestTask.new do |t|
25
25
  when /rails/
26
26
  # Pre-load rails to get the major version number
27
27
  require 'rails'
28
- t.test_files = FileList["test/frameworks/rails#{Rails::VERSION::MAJOR}x_test.rb"]
28
+
29
+ if Rails::VERSION::MAJOR == 5
30
+ t.test_files = FileList["test/frameworks/rails#{Rails::VERSION::MAJOR}x_test.rb"] +
31
+ FileList["test/frameworks/rails#{Rails::VERSION::MAJOR}x_api_test.rb"]
32
+ else
33
+ t.test_files = FileList["test/frameworks/rails#{Rails::VERSION::MAJOR}x_test.rb"]
34
+ end
35
+
29
36
  when /frameworks/
30
37
  t.test_files = FileList['test/frameworks/sinatra*_test.rb'] +
31
38
  FileList['test/frameworks/padrino*_test.rb'] +
@@ -21,7 +21,7 @@ group :development, :test do
21
21
  gem 'puma', '< 3.0'
22
22
  else
23
23
  gem 'rake'
24
- gem 'bson', '~> 3.0'
24
+ gem 'bson', '~> 4.0'
25
25
  gem 'puma', '< 3.1.0'
26
26
  end
27
27
  end
@@ -41,7 +41,7 @@ end
41
41
  if RUBY_VERSION < '1.9.3'
42
42
  gem 'mongo', '1.12.5'
43
43
  else
44
- gem 'mongo', '2.0.6'
44
+ gem 'mongo'
45
45
  end
46
46
 
47
47
  gem 'cassandra'
@@ -11,8 +11,8 @@ module TraceView
11
11
  module Config
12
12
  @@config = {}
13
13
 
14
- @@instrumentation = [:action_controller, :action_view, :active_record,
15
- :bunnyclient, :bunnyconsumer, :cassandra, :curb,
14
+ @@instrumentation = [:action_controller, :action_controller_api, :action_view,
15
+ :active_record, :bunnyclient, :bunnyconsumer, :cassandra, :curb,
16
16
  :dalli, :delayed_jobclient, :delayed_jobworker,
17
17
  :em_http_request, :excon, :faraday, :grape,
18
18
  :httpclient, :nethttp, :memcached,
@@ -44,6 +44,7 @@ module TraceView
44
44
 
45
45
  # Set collect_backtraces defaults
46
46
  TraceView::Config[:action_controller][:collect_backtraces] = true
47
+ TraceView::Config[:action_controller_api][:collect_backtraces] = true
47
48
  TraceView::Config[:active_record][:collect_backtraces] = true
48
49
  TraceView::Config[:bunnyclient][:collect_backtraces] = false
49
50
  TraceView::Config[:bunnyconsumer][:collect_backtraces] = false
@@ -72,9 +72,18 @@ module TraceView
72
72
  end
73
73
  end
74
74
 
75
+ # ActionController::Base
75
76
  if defined?(ActionController::Base) && TraceView::Config[:action_controller][:enabled]
76
- TraceView.logger.info '[traceview/loading] Instrumenting actioncontroler' if TraceView::Config[:verbose]
77
+ TraceView.logger.info '[traceview/loading] Instrumenting actioncontroller' if TraceView::Config[:verbose]
77
78
  require "traceview/frameworks/rails/inst/action_controller#{Rails::VERSION::MAJOR}"
78
79
  ::TraceView::Util.send_include(::ActionController::Base, TraceView::Inst::ActionController)
79
80
  end
81
+
82
+ # ActionController::API (Rails 5+)
83
+ if defined?(ActionController::API) && TraceView::Config[:action_controller_api][:enabled]
84
+ TraceView.logger.info '[traceview/loading] Instrumenting actioncontroller api' if TraceView::Config[:verbose]
85
+ require "traceview/frameworks/rails/inst/action_controller#{Rails::VERSION::MAJOR}_api"
86
+ ::TraceView::Util.send_include(::ActionController::API, TraceView::Inst::ActionControllerAPI)
87
+ end
88
+
80
89
  # vim:set expandtab:tabstop=2
@@ -0,0 +1,39 @@
1
+ # Copyright (c) 2016 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ module TraceView
5
+ module Inst
6
+ #
7
+ # ActionController
8
+ #
9
+ # This modules contains the instrumentation code specific
10
+ # to Rails v5
11
+ #
12
+ module ActionControllerAPI
13
+ include ::TraceView::Inst::RailsBase
14
+
15
+ def self.included(base)
16
+ base.class_eval do
17
+ alias_method_chain :process_action, :traceview
18
+ alias_method_chain :render, :traceview
19
+ end
20
+ end
21
+
22
+ def process_action_with_traceview(method_name, *args)
23
+ report_kvs = {
24
+ :Controller => self.class.name,
25
+ :Action => self.action_name,
26
+ }
27
+
28
+ TraceView::API.log_entry('rails-api', report_kvs)
29
+ process_action_without_traceview(method_name, *args)
30
+
31
+ rescue Exception => e
32
+ TraceView::API.log_exception(nil, e) if log_rails_error?(e)
33
+ raise
34
+ ensure
35
+ TraceView::API.log_exit('rails-api')
36
+ end
37
+ end
38
+ end
39
+ end
@@ -7,8 +7,8 @@ module TraceView
7
7
  # traceview.gemspec during gem build process
8
8
  module Version
9
9
  MAJOR = 3
10
- MINOR = 7
11
- PATCH = 1
10
+ MINOR = 8
11
+ PATCH = 0
12
12
  BUILD = nil
13
13
 
14
14
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -0,0 +1,103 @@
1
+ # Copyright (c) 2015 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ require "minitest_helper"
5
+
6
+ if defined?(::Rails)
7
+
8
+ describe "Rails5xAPI" do
9
+ before do
10
+ clear_all_traces
11
+ ENV['DBTYPE'] = "postgresql" unless ENV['DBTYPE']
12
+ end
13
+
14
+ it "should trace a request to a rails api stack" do
15
+
16
+ uri = URI.parse('http://127.0.0.1:8150/monkey/hello')
17
+ r = Net::HTTP.get_response(uri)
18
+
19
+ traces = get_all_traces
20
+
21
+ traces.count.must_equal 7
22
+ unless defined?(JRUBY_VERSION)
23
+ # We don't test this under JRuby because the Java instrumentation
24
+ # for the DB drivers doesn't use our test reporter hence we won't
25
+ # see all trace events. :-( To be improved.
26
+ valid_edges?(traces).must_equal true
27
+ end
28
+ validate_outer_layers(traces, 'rack')
29
+
30
+ traces[0]['Layer'].must_equal "rack"
31
+ traces[0]['Label'].must_equal "entry"
32
+ traces[0]['URL'].must_equal "/monkey/hello"
33
+
34
+ traces[1]['Layer'].must_equal "rack"
35
+ traces[1]['Label'].must_equal "info"
36
+
37
+ traces[2]['Layer'].must_equal "rails-api"
38
+ traces[2]['Label'].must_equal "entry"
39
+ traces[2]['Controller'].must_equal "MonkeyController"
40
+ traces[2]['Action'].must_equal "hello"
41
+
42
+ traces[3]['Layer'].must_equal "actionview"
43
+ traces[3]['Label'].must_equal "entry"
44
+
45
+ traces[4]['Layer'].must_equal "actionview"
46
+ traces[4]['Label'].must_equal "exit"
47
+
48
+ traces[5]['Layer'].must_equal "rails-api"
49
+ traces[5]['Label'].must_equal "exit"
50
+
51
+ traces[6]['Layer'].must_equal "rack"
52
+ traces[6]['Label'].must_equal "exit"
53
+
54
+ # Validate the existence of the response header
55
+ r.header.key?('X-Trace').must_equal true
56
+ r.header['X-Trace'].must_equal traces[6]['X-Trace']
57
+ end
58
+
59
+ it "should capture errors" do
60
+ uri = URI.parse('http://127.0.0.1:8150/monkey/error')
61
+ r = Net::HTTP.get_response(uri)
62
+
63
+ traces = get_all_traces
64
+
65
+ traces.count.must_equal 6
66
+ unless defined?(JRUBY_VERSION)
67
+ # We don't test this under JRuby because the Java instrumentation
68
+ # for the DB drivers doesn't use our test reporter hence we won't
69
+ # see all trace events. :-( To be improved.
70
+ valid_edges?(traces).must_equal true
71
+ end
72
+ validate_outer_layers(traces, 'rack')
73
+
74
+ traces[0]['Layer'].must_equal "rack"
75
+ traces[0]['Label'].must_equal "entry"
76
+ traces[0]['URL'].must_equal "/monkey/error"
77
+
78
+ traces[1]['Layer'].must_equal "rack"
79
+ traces[1]['Label'].must_equal "info"
80
+
81
+ traces[2]['Layer'].must_equal "rails-api"
82
+ traces[2]['Label'].must_equal "entry"
83
+ traces[2]['Controller'].must_equal "MonkeyController"
84
+ traces[2]['Action'].must_equal "error"
85
+
86
+ traces[3]['Label'].must_equal "error"
87
+ traces[3]['ErrorClass'].must_equal "RuntimeError"
88
+ traces[3]['ErrorMsg'].must_equal "Rails API fake error from controller"
89
+ traces[3].key?('Backtrace').must_equal true
90
+
91
+ traces[4]['Layer'].must_equal "rails-api"
92
+ traces[4]['Label'].must_equal "exit"
93
+
94
+ traces[5]['Layer'].must_equal "rack"
95
+ traces[5]['Label'].must_equal "exit"
96
+
97
+ # Validate the existence of the response header
98
+ r.header.key?('X-Trace').must_equal true
99
+ r.header['X-Trace'].must_equal traces[5]['X-Trace']
100
+ end
101
+
102
+ end
103
+ end
@@ -59,6 +59,7 @@ when /delayed_job/
59
59
 
60
60
  when /rails5/
61
61
  require './test/servers/rails5x_8140'
62
+ require './test/servers/rails5x_api_8150'
62
63
 
63
64
  when /rails4/
64
65
  require './test/servers/rails4x_8140'
@@ -0,0 +1,109 @@
1
+ # Taken from: https://www.amberbit.com/blog/2014/2/14/putting-ruby-on-rails-on-a-diet/
2
+ # Port of https://gist.github.com/josevalim/1942658 to Rails 4
3
+ # Original author: Jose Valim
4
+ # Updated by: Peter Giacomo Lombardo
5
+ #
6
+ # Run this file with:
7
+ #
8
+ # bundle exec RAILS_ENV=production rackup -p 3000 -s thin
9
+ #
10
+ # And access:
11
+ #
12
+ # http://localhost:3000/hello/world
13
+ #
14
+ # The following lines should come as no surprise. Except by
15
+ # ActionController::Metal, it follows the same structure of
16
+ # config/application.rb, config/environment.rb and config.ru
17
+ # existing in any Rails 4 app. Here they are simply in one
18
+ # file and without the comments.
19
+ #
20
+
21
+ # Set the database. Default is postgresql.
22
+ if ENV['DBTYPE'] == 'mysql2'
23
+ TraceView::Test.set_mysql2_env
24
+ elsif ENV['DBTYPE'] == 'postgresql'
25
+ TraceView::Test.set_postgresql_env
26
+ else
27
+ TV.logger.warn "Unidentified DBTYPE: #{ENV['DBTYPE']}" unless ENV['DBTYPE'] == "postgresql"
28
+ TV.logger.debug "Defaulting to postgres DB for background Rails server."
29
+ TraceView::Test.set_postgresql_env
30
+ end
31
+
32
+ require "rails"
33
+ # Pick the frameworks you want:
34
+ require "active_model/railtie"
35
+ require "active_job/railtie"
36
+ require "active_record/railtie"
37
+ require "action_controller/railtie"
38
+ require "action_mailer/railtie"
39
+ require "action_view/railtie"
40
+ require "action_cable/engine"
41
+ # require "sprockets/railtie"
42
+ require "rails/test_unit/railtie"
43
+
44
+ require 'rack/handler/puma'
45
+ require File.expand_path(File.dirname(__FILE__) + '/../models/widget')
46
+
47
+ TraceView.logger.info "[traceview/info] Starting background utility rails app on localhost:8150."
48
+
49
+ ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
50
+
51
+ unless ActiveRecord::Base.connection.table_exists? 'widgets'
52
+ ActiveRecord::Migration.run(CreateWidgets)
53
+ end
54
+
55
+ module Rails50APIStack
56
+ class Application < Rails::Application
57
+ config.api_only = true
58
+
59
+ routes.append do
60
+ get "/monkey/hello" => "monkey#hello"
61
+ get "/monkey/error" => "monkey#error"
62
+ end
63
+
64
+ # Enable cache classes. Production style.
65
+ config.cache_classes = true
66
+ config.eager_load = false
67
+
68
+ # uncomment below to display errors
69
+ # config.consider_all_requests_local = true
70
+
71
+ config.active_support.deprecation = :stderr
72
+
73
+ # Here you could remove some middlewares, for example
74
+ # Rack::Lock, ActionDispatch::Flash and ActionDispatch::BestStandardsSupport below.
75
+ # The remaining stack is printed on rackup (for fun!).
76
+ # Rails API has config.middleware.api_only! to get
77
+ # rid of browser related middleware.
78
+ config.middleware.delete Rack::Lock
79
+ config.middleware.delete ActionDispatch::Flash
80
+
81
+ # We need a secret token for session, cookies, etc.
82
+ config.secret_token = "48837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
83
+ config.secret_key_base = "2049671-96803948"
84
+ end
85
+ end
86
+
87
+ #################################################
88
+ # Controllers
89
+ #################################################
90
+
91
+ class MonkeyController < ActionController::API
92
+ def hello
93
+ #render :json => { :Response => "Hello API!"}.to_json
94
+ # Work around for Rails beta issue with rendering json
95
+ render :plain => { :Response => "Hello API!"}.to_json, content_type: 'application/json'
96
+ end
97
+
98
+ def error
99
+ raise "Rails API fake error from controller"
100
+ end
101
+ end
102
+
103
+ Rails50APIStack::Application.initialize!
104
+
105
+ Thread.new do
106
+ Rack::Handler::Puma.run(Rails50APIStack::Application.to_app, {:Host => '127.0.0.1', :Port => 8150})
107
+ end
108
+
109
+ sleep(2)
@@ -30,9 +30,10 @@ describe "TraceView::Config" do
30
30
  instrumentation = TraceView::Config.instrumentation
31
31
 
32
32
  # Verify the number of individual instrumentations
33
- instrumentation.count.must_equal 29
33
+ instrumentation.count.must_equal 30
34
34
 
35
35
  TraceView::Config[:action_controller][:enabled].must_equal true
36
+ TraceView::Config[:action_controller_api][:enabled].must_equal true
36
37
  TraceView::Config[:action_view][:enabled].must_equal true
37
38
  TraceView::Config[:active_record][:enabled].must_equal true
38
39
  TraceView::Config[:bunnyclient][:enabled].must_equal true
@@ -63,6 +64,7 @@ describe "TraceView::Config" do
63
64
  TraceView::Config[:typhoeus][:enabled].must_equal true
64
65
 
65
66
  TraceView::Config[:action_controller][:log_args].must_equal true
67
+ TraceView::Config[:action_controller_api][:log_args].must_equal true
66
68
  TraceView::Config[:action_view][:log_args].must_equal true
67
69
  TraceView::Config[:active_record][:log_args].must_equal true
68
70
  TraceView::Config[:bunnyclient][:log_args].must_equal true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traceview
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.1
4
+ version: 3.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Giacomo Lombardo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-30 00:00:00.000000000 Z
12
+ date: 2016-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -158,6 +158,7 @@ files:
158
158
  - lib/traceview/frameworks/rails/inst/action_controller3.rb
159
159
  - lib/traceview/frameworks/rails/inst/action_controller4.rb
160
160
  - lib/traceview/frameworks/rails/inst/action_controller5.rb
161
+ - lib/traceview/frameworks/rails/inst/action_controller5_api.rb
161
162
  - lib/traceview/frameworks/rails/inst/action_view.rb
162
163
  - lib/traceview/frameworks/rails/inst/action_view_2x.rb
163
164
  - lib/traceview/frameworks/rails/inst/action_view_30.rb
@@ -213,6 +214,7 @@ files:
213
214
  - test/frameworks/padrino_test.rb
214
215
  - test/frameworks/rails3x_test.rb
215
216
  - test/frameworks/rails4x_test.rb
217
+ - test/frameworks/rails5x_api_test.rb
216
218
  - test/frameworks/rails5x_test.rb
217
219
  - test/frameworks/sinatra_test.rb
218
220
  - test/instrumentation/bunny_client_test.rb
@@ -269,6 +271,7 @@ files:
269
271
  - test/servers/rails3x_8140.rb
270
272
  - test/servers/rails4x_8140.rb
271
273
  - test/servers/rails5x_8140.rb
274
+ - test/servers/rails5x_api_8150.rb
272
275
  - test/servers/sidekiq.rb
273
276
  - test/servers/sidekiq.yml
274
277
  - test/servers/sidekiq_initializer.rb
@@ -314,6 +317,7 @@ test_files:
314
317
  - test/servers/rails3x_8140.rb
315
318
  - test/servers/rails5x_8140.rb
316
319
  - test/servers/delayed_job.rb
320
+ - test/servers/rails5x_api_8150.rb
317
321
  - test/servers/sidekiq.rb
318
322
  - test/servers/rackapp_8101.rb
319
323
  - test/instrumentation/excon_test.rb
@@ -363,6 +367,7 @@ test_files:
363
367
  - test/frameworks/rails3x_test.rb
364
368
  - test/frameworks/padrino_test.rb
365
369
  - test/frameworks/rails4x_test.rb
370
+ - test/frameworks/rails5x_api_test.rb
366
371
  - test/queues/delayed_job-worker_test.rb
367
372
  - test/queues/delayed_job-client_test.rb
368
373
  - test/support/init_report_test.rb