appsignal 0.12.beta.31 → 0.12.beta.32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/Rakefile +1 -0
  4. data/benchmark.rake +20 -20
  5. data/ext/appsignal_extension.c +31 -23
  6. data/gemfiles/padrino.gemfile +7 -0
  7. data/lib/appsignal.rb +50 -27
  8. data/lib/appsignal/capistrano.rb +2 -1
  9. data/lib/appsignal/config.rb +94 -39
  10. data/lib/appsignal/event_formatter/active_record/sql_formatter.rb +12 -17
  11. data/lib/appsignal/integrations/padrino.rb +65 -0
  12. data/lib/appsignal/integrations/rails.rb +4 -2
  13. data/lib/appsignal/integrations/rake.rb +30 -0
  14. data/lib/appsignal/integrations/sidekiq.rb +2 -2
  15. data/lib/appsignal/integrations/sinatra.rb +0 -1
  16. data/lib/appsignal/js_exception_transaction.rb +4 -9
  17. data/lib/appsignal/params_sanitizer.rb +8 -5
  18. data/lib/appsignal/rack/rails_instrumentation.rb +41 -0
  19. data/lib/appsignal/rack/sinatra_instrumentation.rb +31 -24
  20. data/lib/appsignal/subscriber.rb +2 -9
  21. data/lib/appsignal/transaction.rb +86 -75
  22. data/lib/appsignal/transmitter.rb +30 -3
  23. data/lib/appsignal/version.rb +2 -2
  24. data/spec/lib/appsignal/cli_spec.rb +1 -1
  25. data/spec/lib/appsignal/config_spec.rb +38 -131
  26. data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +27 -29
  27. data/spec/lib/appsignal/extension_spec.rb +11 -29
  28. data/spec/lib/appsignal/integrations/padrino_spec.rb +191 -0
  29. data/spec/lib/appsignal/integrations/rails_spec.rb +3 -4
  30. data/spec/lib/appsignal/integrations/rake_spec.rb +78 -0
  31. data/spec/lib/appsignal/integrations/resque_spec.rb +2 -2
  32. data/spec/lib/appsignal/integrations/sequel_spec.rb +2 -3
  33. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +22 -5
  34. data/spec/lib/appsignal/integrations/sinatra_spec.rb +0 -6
  35. data/spec/lib/appsignal/js_exception_transaction_spec.rb +4 -6
  36. data/spec/lib/appsignal/params_sanitizer_spec.rb +27 -11
  37. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +79 -0
  38. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +71 -71
  39. data/spec/lib/appsignal/subscriber_spec.rb +3 -37
  40. data/spec/lib/appsignal/transaction_spec.rb +290 -155
  41. data/spec/lib/appsignal/transmitter_spec.rb +10 -0
  42. data/spec/lib/appsignal_spec.rb +80 -47
  43. data/spec/spec_helper.rb +21 -2
  44. data/spec/support/helpers/env_helpers.rb +31 -0
  45. data/spec/support/helpers/notification_helpers.rb +1 -30
  46. data/spec/support/helpers/transaction_helpers.rb +7 -7
  47. data/spec/support/project_fixture/config/appsignal.yml +2 -0
  48. metadata +14 -8
  49. data/lib/appsignal/rack/instrumentation.rb +0 -32
  50. data/lib/appsignal/rack/listener.rb +0 -32
  51. data/spec/lib/appsignal/rack/instrumentation_spec.rb +0 -72
  52. data/spec/lib/appsignal/rack/listener_spec.rb +0 -104
@@ -1,32 +0,0 @@
1
- require 'rack'
2
-
3
- module Appsignal
4
- module Rack
5
- class Instrumentation
6
- def initialize(app, options = {})
7
- Appsignal.logger.debug 'Initializing Appsignal::Rack::Instrumentation'
8
- @app, @options = app, options
9
- end
10
-
11
- def call(env)
12
- ActiveSupport::Notifications.instrument(
13
- 'process_action.rack',
14
- raw_payload(env)
15
- ) do |payload|
16
- @app.call(env)
17
- end
18
- end
19
-
20
- def raw_payload(env)
21
- request = @options.fetch(:request_class, ::Rack::Request).new(env)
22
- params = request.public_send(@options.fetch(:params_method, :params))
23
- {
24
- :action => "#{request.request_method}:#{request.path}",
25
- :params => params,
26
- :method => request.request_method,
27
- :path => request.path
28
- }
29
- end
30
- end
31
- end
32
- end
@@ -1,32 +0,0 @@
1
- module Appsignal
2
- module Rack
3
- class Listener
4
- def initialize(app, options = {})
5
- Appsignal.logger.debug 'Initializing Appsignal::Rack::Listener'
6
- @app, @options = app, options
7
- end
8
-
9
- def call(env)
10
- if Appsignal.active?
11
- call_with_appsignal_monitoring(env)
12
- else
13
- @app.call(env)
14
- end
15
- end
16
-
17
- def call_with_appsignal_monitoring(env)
18
- Appsignal::Transaction.create(request_id(env), env)
19
- @app.call(env)
20
- rescue Exception => exception
21
- Appsignal.set_exception(exception)
22
- raise exception
23
- ensure
24
- Appsignal::Transaction.complete_current!
25
- end
26
-
27
- def request_id(env)
28
- env['action_dispatch.request_id'] || SecureRandom.uuid
29
- end
30
- end
31
- end
32
- end
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Appsignal::Rack::Instrumentation do
4
- before :all do
5
- start_agent
6
- @events = []
7
- @subscriber = ActiveSupport::Notifications.subscribe do |*args|
8
- @events << ActiveSupport::Notifications::Event.new(*args)
9
- end
10
- end
11
- after :all do
12
- ActiveSupport::Notifications.unsubscribe(@subscriber)
13
- end
14
-
15
- let(:app) { double(:call => true) }
16
- let(:env) { {} }
17
- let(:middleware) { Appsignal::Rack::Instrumentation.new(app, {}) }
18
-
19
- describe "#call" do
20
- it "should instrument the call" do
21
- app.should_receive(:call).with(env)
22
- middleware.stub(:raw_payload => {})
23
-
24
- middleware.call(env)
25
-
26
- @events.last.name.should == 'process_action.rack'
27
- end
28
- end
29
-
30
- describe "raw_payload" do
31
- let(:env) do
32
- {
33
- 'rack.input' => StringIO.new,
34
- 'REQUEST_METHOD' => 'GET',
35
- 'PATH_INFO' => '/homepage',
36
- 'QUERY_STRING' => 'param=something'
37
- }
38
- end
39
- subject { middleware.raw_payload(env) }
40
-
41
- it { should == {
42
- :action => 'GET:/homepage',
43
- :params => {'param' => 'something'},
44
- :method => 'GET',
45
- :path => '/homepage'
46
- } }
47
- end
48
-
49
- describe "use a custom request class and parameters method" do
50
- let(:request_class) do
51
- double(
52
- new: double(
53
- request_method: 'POST',
54
- path: '/somewhere',
55
- filtered_params: {'param' => 'changed_something'}
56
- )
57
- )
58
- end
59
- let(:options) do
60
- { request_class: request_class, params_method: :filtered_params }
61
- end
62
- let(:middleware) { Appsignal::Rack::Instrumentation.new(app, options) }
63
- subject { middleware.raw_payload(env) }
64
-
65
- it { should == {
66
- :action => 'POST:/somewhere',
67
- :params => {'param' => 'changed_something'},
68
- :method => 'POST',
69
- :path => '/somewhere'
70
- } }
71
- end
72
- end
@@ -1,104 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Appsignal
4
- IgnoreMeError = Class.new(StandardError)
5
- end
6
-
7
- class AppWithError
8
- def self.call(env)
9
- raise Appsignal::IgnoreMeError, 'the roof'
10
- end
11
- end
12
-
13
- describe Appsignal::Rack::Listener do
14
- before :all do
15
- start_agent
16
- end
17
- let(:app) { double(:call => true) }
18
- let(:middleware) { Appsignal::Rack::Listener.new(app, {})}
19
- let(:env) { {} }
20
-
21
- describe '#call' do
22
- let(:current) { double(:request_id => '1', :set_error => true, :transaction_index => 1) }
23
- before do
24
- middleware.stub(:request_id => '1')
25
- Appsignal::Transaction.stub(:current => current)
26
- end
27
-
28
- describe 'around call' do
29
- it 'should create an appsignal transaction' do
30
- Appsignal::Transaction.should_receive(:create).with('1', env)
31
- end
32
-
33
- it 'should call complete! after the call' do
34
- Appsignal::Transaction.should_receive(:complete_current!)
35
- end
36
-
37
- context "when not active" do
38
- before { Appsignal.stub(:active? => false) }
39
-
40
- it 'should not create an appsignal transaction' do
41
- Appsignal::Transaction.should_not_receive(:create)
42
- end
43
- end
44
-
45
- after { middleware.call(env) }
46
- end
47
-
48
- describe 'with exception' do
49
- let(:app) { AppWithError }
50
-
51
- it 'should re-raise the exception' do
52
- expect {
53
- middleware.call(env)
54
- }.to raise_error
55
- end
56
-
57
- it 'should catch the exception and notify the transaction of it' do
58
- current.should_receive(:set_error)
59
- middleware.call(env) rescue nil
60
- end
61
-
62
- context 'when ignoring exception' do
63
- before { Appsignal.stub(:config => {:ignore_exceptions => 'Appsignal::IgnoreMeError'})}
64
-
65
- it 'should re-raise the exception' do
66
- expect {
67
- middleware.call(env)
68
- }.to raise_error
69
- end
70
-
71
- it 'should ignore the error' do
72
- current.should_not_receive(:set_error)
73
- middleware.call(env) rescue nil
74
- end
75
- end
76
-
77
- describe 'after an error' do
78
- it 'should call complete_current! after the call' do
79
- Appsignal::Transaction.should_receive(:complete_current!)
80
- end
81
-
82
- after { middleware.call(env) rescue nil }
83
- end
84
- end
85
- end
86
-
87
- describe "#request_id" do
88
- subject { middleware.request_id(env) }
89
-
90
- context "when Rails provides a request_id" do
91
- let(:env) { {'action_dispatch.request_id' => '1'} }
92
-
93
- it { should == '1' }
94
- end
95
-
96
- context "when Rails does not provide a request_id" do
97
- before do
98
- SecureRandom.stub(:uuid => '2')
99
- end
100
-
101
- it { should == '2' }
102
- end
103
- end
104
- end