appsignal 0.11.18 → 0.12.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/.gitignore +6 -0
  2. data/CHANGELOG.md +4 -38
  3. data/Rakefile +14 -6
  4. data/appsignal.gemspec +3 -1
  5. data/benchmark.rake +12 -16
  6. data/ext/appsignal_extension.c +183 -0
  7. data/ext/extconf.rb +39 -0
  8. data/gemfiles/capistrano2.gemfile +0 -1
  9. data/gemfiles/capistrano3.gemfile +0 -1
  10. data/gemfiles/rails-4.2.gemfile +1 -1
  11. data/lib/appsignal.rb +23 -61
  12. data/lib/appsignal/capistrano.rb +1 -2
  13. data/lib/appsignal/config.rb +13 -1
  14. data/lib/appsignal/event_formatter.rb +67 -0
  15. data/lib/appsignal/event_formatter/action_view/render_formatter.rb +23 -0
  16. data/lib/appsignal/event_formatter/active_record/sql_formatter.rb +74 -0
  17. data/lib/appsignal/event_formatter/moped/query_formatter.rb +80 -0
  18. data/lib/appsignal/event_formatter/net_http/request_formatter.rb +13 -0
  19. data/lib/appsignal/instrumentations/net_http.rb +6 -4
  20. data/lib/appsignal/integrations/resque.rb +2 -10
  21. data/lib/appsignal/integrations/sidekiq.rb +2 -2
  22. data/lib/appsignal/integrations/sinatra.rb +1 -0
  23. data/lib/appsignal/js_exception_transaction.rb +44 -28
  24. data/lib/appsignal/marker.rb +11 -13
  25. data/lib/appsignal/params_sanitizer.rb +5 -8
  26. data/lib/appsignal/rack/instrumentation.rb +2 -0
  27. data/lib/appsignal/rack/js_exception_catcher.rb +1 -0
  28. data/lib/appsignal/rack/listener.rb +1 -1
  29. data/lib/appsignal/rack/sinatra_instrumentation.rb +2 -12
  30. data/lib/appsignal/subscriber.rb +59 -0
  31. data/lib/appsignal/transaction.rb +117 -174
  32. data/lib/appsignal/transmitter.rb +8 -37
  33. data/lib/appsignal/version.rb +2 -1
  34. data/spec/lib/appsignal/config_spec.rb +25 -4
  35. data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +42 -0
  36. data/spec/lib/appsignal/{aggregator/middleware/active_record_sanitizer_spec.rb → event_formatter/active_record/sql_formatter_spec.rb} +61 -61
  37. data/spec/lib/appsignal/{event/moped_event_spec.rb → event_formatter/moped/query_formatter_spec.rb} +32 -78
  38. data/spec/lib/appsignal/event_formatter/net_http/request_formatter_spec.rb +26 -0
  39. data/spec/lib/appsignal/event_formatter_spec.rb +102 -0
  40. data/spec/lib/appsignal/extension_spec.rb +75 -0
  41. data/spec/lib/appsignal/instrumentations/net_http_spec.rb +20 -4
  42. data/spec/lib/appsignal/integrations/delayed_job_spec.rb +3 -2
  43. data/spec/lib/appsignal/integrations/rails_spec.rb +0 -7
  44. data/spec/lib/appsignal/integrations/resque_spec.rb +51 -55
  45. data/spec/lib/appsignal/integrations/sequel_spec.rb +8 -3
  46. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +4 -21
  47. data/spec/lib/appsignal/integrations/sinatra_spec.rb +0 -6
  48. data/spec/lib/appsignal/js_exception_transaction_spec.rb +57 -60
  49. data/spec/lib/appsignal/params_sanitizer_spec.rb +11 -27
  50. data/spec/lib/appsignal/rack/listener_spec.rb +6 -6
  51. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +2 -43
  52. data/spec/lib/appsignal/subscriber_spec.rb +162 -0
  53. data/spec/lib/appsignal/transaction_spec.rb +283 -615
  54. data/spec/lib/appsignal/transmitter_spec.rb +3 -32
  55. data/spec/lib/appsignal_spec.rb +41 -90
  56. data/spec/lib/generators/appsignal/appsignal_generator_spec.rb +0 -17
  57. data/spec/spec_helper.rb +18 -22
  58. data/spec/support/helpers/notification_helpers.rb +1 -1
  59. data/spec/support/helpers/time_helpers.rb +11 -0
  60. data/spec/support/helpers/transaction_helpers.rb +6 -18
  61. data/spec/support/project_fixture/config/appsignal.yml +1 -2
  62. metadata +68 -78
  63. checksums.yaml +0 -7
  64. data/gemfiles/padrino-0.13.gemfile +0 -7
  65. data/gemfiles/resque.gemfile +0 -5
  66. data/lib/appsignal/agent.rb +0 -217
  67. data/lib/appsignal/aggregator.rb +0 -67
  68. data/lib/appsignal/aggregator/middleware.rb +0 -4
  69. data/lib/appsignal/aggregator/middleware/action_view_sanitizer.rb +0 -23
  70. data/lib/appsignal/aggregator/middleware/active_record_sanitizer.rb +0 -65
  71. data/lib/appsignal/aggregator/middleware/chain.rb +0 -101
  72. data/lib/appsignal/aggregator/middleware/delete_blanks.rb +0 -16
  73. data/lib/appsignal/aggregator/post_processor.rb +0 -32
  74. data/lib/appsignal/event.rb +0 -20
  75. data/lib/appsignal/event/moped_event.rb +0 -90
  76. data/lib/appsignal/integrations/padrino.rb +0 -64
  77. data/lib/appsignal/integrations/passenger.rb +0 -13
  78. data/lib/appsignal/integrations/rake.rb +0 -29
  79. data/lib/appsignal/integrations/unicorn.rb +0 -25
  80. data/lib/appsignal/ipc.rb +0 -68
  81. data/lib/appsignal/transaction/formatter.rb +0 -85
  82. data/lib/appsignal/transaction/params_sanitizer.rb +0 -4
  83. data/lib/appsignal/zipped_payload.rb +0 -37
  84. data/spec/lib/appsignal/agent_spec.rb +0 -592
  85. data/spec/lib/appsignal/aggregator/middleware/action_view_sanitizer_spec.rb +0 -44
  86. data/spec/lib/appsignal/aggregator/middleware/chain_spec.rb +0 -168
  87. data/spec/lib/appsignal/aggregator/middleware/delete_blanks_spec.rb +0 -37
  88. data/spec/lib/appsignal/aggregator/post_processor_spec.rb +0 -99
  89. data/spec/lib/appsignal/aggregator_spec.rb +0 -186
  90. data/spec/lib/appsignal/event_spec.rb +0 -48
  91. data/spec/lib/appsignal/integrations/padrino_spec.rb +0 -171
  92. data/spec/lib/appsignal/integrations/passenger_spec.rb +0 -22
  93. data/spec/lib/appsignal/integrations/rake_spec.rb +0 -92
  94. data/spec/lib/appsignal/integrations/unicorn_spec.rb +0 -48
  95. data/spec/lib/appsignal/ipc_spec.rb +0 -128
  96. data/spec/lib/appsignal/transaction/formatter_spec.rb +0 -247
  97. data/spec/lib/appsignal/zipped_payload_spec.rb +0 -42
@@ -1,247 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Appsignal::Transaction::Formatter do
4
- before :all do
5
- start_agent
6
- end
7
-
8
- let(:klass) { Appsignal::Transaction::Formatter }
9
- let(:formatter) { klass.new(transaction) }
10
- subject { formatter }
11
- before { transaction.stub(:fullpath => '/foo') }
12
-
13
- describe "#to_hash" do
14
- subject { formatter.to_hash }
15
-
16
- context "with a regular request" do
17
- let(:transaction) { regular_transaction }
18
- before { transaction.truncate! }
19
-
20
- its(:keys) { should =~ [:request_id, :log_entry, :failed] }
21
- its([:request_id]) { should == '1' }
22
- its([:log_entry]) { should == {
23
- :action => "BlogPostsController#show",
24
- :duration => be_within(0.01).of(100.0),
25
- :end => 1389783600.1,
26
- :environment => {},
27
- :kind => "http_request",
28
- :path => "/foo",
29
- :session_data => {},
30
- :revision => nil,
31
- :params => {},
32
- :time => 1389783600.0,
33
- } }
34
- its([:events]) { should be_nil }
35
- its([:failed]) { should be_false }
36
- end
37
-
38
- context "with a regular request when queue time is present" do
39
- let(:transaction) { regular_transaction_with_x_request_start }
40
- before { transaction.truncate! }
41
-
42
- context "log_entry content" do
43
- subject { formatter.to_hash[:log_entry] }
44
-
45
- its([:queue_duration]) { should be_within(0.01).of(40.0) }
46
- end
47
- end
48
-
49
- context "when the APP_REVISION environment variable is present" do
50
- let(:transaction) { regular_transaction }
51
- before do
52
- Appsignal.agent.stub(:revision => 'foo')
53
- end
54
-
55
- it "should store the APP_REVISION" do
56
- subject.to_hash[:log_entry][:revision].should == 'foo'
57
- end
58
- end
59
-
60
- context "with a background request without payload" do
61
- let(:transaction) do
62
- Appsignal::Transaction.new(
63
- '123',
64
- {},
65
- {
66
- :kind => 'web',
67
- :action => 'foo#bar',
68
- :params => {'foo' => 'bar'}
69
- }
70
- )
71
- end
72
-
73
- before { transaction.send(:add_sanitized_context!) }
74
-
75
- it "should get the kind and action from the transaction" do
76
- subject.to_hash.should == {
77
- :request_id => '123',
78
- :log_entry => {
79
- :path => '/foo',
80
- :kind => 'web',
81
- :action => 'foo#bar',
82
- :time => nil,
83
- :environment => {},
84
- :session_data => {},
85
- :revision => nil,
86
- :params => {'foo' => 'bar'}
87
- },
88
- :failed => false
89
- }
90
- end
91
- end
92
-
93
- context "with an exception request" do
94
- let(:transaction) { transaction_with_exception }
95
-
96
- its(:keys) { should =~ [:request_id, :log_entry, :failed, :exception] }
97
- its([:request_id]) { should == '1' }
98
- its([:failed]) { should be_true }
99
-
100
- context "log_entry content" do
101
- subject { formatter.to_hash[:log_entry] }
102
-
103
- its([:tags]) { should == {'user_id' => 123} }
104
- its([:action]) { should == 'BlogPostsController#show' }
105
- its([:params]) { should == {'action' => 'show', 'controller' => 'blog_posts', 'id' => '1'} }
106
-
107
- context "when send_params in the config is false" do
108
- before { Appsignal.config.config_hash[:send_params] = false }
109
- after { Appsignal.config.config_hash[:send_params] = true }
110
-
111
- it "should not send the params" do
112
- subject[:params].should be_nil
113
- end
114
- end
115
- end
116
-
117
- context "exception content" do
118
- subject { formatter.to_hash[:exception] }
119
-
120
- it "should set the exception" do
121
- subject.should eql(transaction_with_exception.exception)
122
- end
123
- its(:keys) { should =~ [:exception, :message, :backtrace] }
124
- its([:exception]) { should == 'ArgumentError' }
125
- its([:message]) { should == 'oh no' }
126
- end
127
- end
128
-
129
- context "with a slow request" do
130
- let(:transaction) { slow_transaction }
131
-
132
- its(:keys) { should =~ [:request_id, :log_entry, :failed, :events] }
133
- its([:request_id]) { should == '1' }
134
- its([:log_entry]) { should == {
135
- :action => "BlogPostsController#show",
136
- :duration => be_within(0.01).of(200.0),
137
- :end => 1389783600.200002,
138
- :environment => {},
139
- :params => {
140
- 'action' => 'show',
141
- 'controller' => 'blog_posts',
142
- 'id' => '1'
143
- },
144
- :kind => "http_request",
145
- :path => "/blog",
146
- :session_data => {},
147
- :revision => nil,
148
- :time => 1389783600.0,
149
- :db_runtime => 500,
150
- :view_runtime => 500,
151
- :request_format => 'html',
152
- :request_method => 'GET',
153
- :status => '200'
154
- } }
155
- its([:failed]) { should be_false }
156
-
157
- context "when send_params in the config is false" do
158
- before { Appsignal.config.config_hash[:send_params] = false }
159
- after { Appsignal.config.config_hash[:send_params] = true }
160
-
161
- it "should not send the params" do
162
- subject[:log_entry][:params].should be_nil
163
- end
164
- end
165
-
166
- context "events content" do
167
- subject { formatter.to_hash[:events] }
168
-
169
- its(:length) { should == 1 }
170
- its(:first) { should == {
171
- :name => "query.mongoid",
172
- :duration => be_within(0.01).of(100.0),
173
- :time => 1389783600.0,
174
- :end => 1389783600.1,
175
- :payload => {
176
- :path => "/blog",
177
- :action => "show",
178
- :controller => "BlogPostsController",
179
- :params => {
180
- 'action' => 'show',
181
- 'controller' => 'blog_posts',
182
- 'id' => '1'
183
- },
184
- :request_format => "html",
185
- :request_method => "GET",
186
- :status => "200",
187
- :view_runtime => 500,
188
- :db_runtime => 500
189
- }
190
- } }
191
- end
192
- end
193
-
194
- context "with a background request" do
195
- let(:payload) { create_background_payload }
196
- let(:transaction) { background_job_transaction({}, payload) }
197
-
198
- its(:keys) { should =~ [:request_id, :log_entry, :failed] }
199
- its([:request_id]) { should == '1' }
200
- its([:log_entry]) { should == {
201
- :action => "BackgroundJob#perform",
202
- :duration => be_within(0.01).of(100.0),
203
- :end => 1389783600.1,
204
- :queue_duration => 10000.0,
205
- :priority => 1,
206
- :attempts => 0,
207
- :queue => 'default',
208
- :environment => {},
209
- :kind => "background_job",
210
- :path => "/foo",
211
- :session_data => {},
212
- :params => {},
213
- :revision => nil,
214
- :time => 1389783600.0,
215
- } }
216
- its([:failed]) { should be_false }
217
-
218
- context "when queue_time is zero" do
219
- let(:payload) { create_background_payload(:queue_start => 0) }
220
-
221
- context "log entry" do
222
- subject { formatter.to_hash[:log_entry] }
223
-
224
- its([:queue_duration]) { should be_nil }
225
- end
226
- end
227
- end
228
- end
229
-
230
- describe "#clean_backtrace" do
231
- let(:transaction) { regular_transaction }
232
-
233
- context "when backtrace is nil" do
234
- let(:error) { double(:backtrace => nil) }
235
-
236
- it "should not raise an error when backtrace is `nil`" do
237
- expect {
238
- formatter.send(:clean_backtrace, error)
239
- }.to_not raise_error
240
- end
241
-
242
- it "should always return an array" do
243
- expect( formatter.send(:clean_backtrace, error) ).to be_a(Array)
244
- end
245
- end
246
- end
247
- end
@@ -1,42 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Appsignal::ZippedPayload do
6
- describe "#initialize" do
7
- it "should initialize a new `Appsignal::ZippedPayload` and zip the body" do
8
- payload = Appsignal::ZippedPayload.new({'the' => 'payload'})
9
-
10
- expect( payload.body ).to eql(Zlib::Deflate.deflate(
11
- "{\"the\":\"payload\"}",
12
- Zlib::BEST_SPEED
13
- ))
14
- end
15
- end
16
-
17
- describe ".json_generate" do
18
- subject { Appsignal::ZippedPayload.send(:json_generate, body) }
19
-
20
- context "with a valid body" do
21
- let(:body) { {'the' => 'payload'} }
22
-
23
- it { should == "{\"the\":\"payload\"}" }
24
- end
25
-
26
- context "with a body that contains strings with invalid utf-8 content" do
27
- let(:string_with_invalid_utf8) { [0x61, 0x61, 0x85].pack('c*') }
28
- let(:body) { {
29
- 'field_one' => [0x61, 0x61].pack('c*'),
30
- 'field_two' => string_with_invalid_utf8,
31
- 'field_three' => [
32
- 'one', string_with_invalid_utf8
33
- ],
34
- 'field_four' => {
35
- 'one' => string_with_invalid_utf8
36
- }
37
- } }
38
-
39
- it { should == "{\"field_one\":\"aa\",\"field_two\":\"aa�\",\"field_three\":[\"one\",\"aa�\"],\"field_four\":{\"one\":\"aa�\"}}" }
40
- end
41
- end
42
- end