appsignal 0.10.6 → 0.11.0.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Appsignal::Event do
4
+
5
+ describe "#sanitize!" do
6
+ let(:payload) { {:foo => 'bar'} }
7
+ let(:event) { Appsignal::Event.new('event.test', 1, 2, 3, payload) }
8
+
9
+ it "should call the sanitizer" do
10
+ expect( Appsignal::ParamsSanitizer ).to receive(:sanitize).with(payload)
11
+ event.sanitize!
12
+ end
13
+
14
+ it "should store the result on the payload" do
15
+ Appsignal::ParamsSanitizer.stub(:sanitize => {:foo => 'sanitized'})
16
+ expect {
17
+ event.sanitize!
18
+ }.to change(event, :payload).from(:foo => 'bar').to(:foo => 'sanitized')
19
+ end
20
+ end
21
+
22
+ describe "#truncate!" do
23
+ let(:payload) { {:foo => 'bar'} }
24
+ let(:event) { Appsignal::Event.new('event.test', 1, 2, 3, payload) }
25
+
26
+ it "should remove the payload" do
27
+ expect {
28
+ event.truncate!
29
+ }.to change(event, :payload).from(:foo => 'bar').to({})
30
+ end
31
+ end
32
+
33
+ describe ".event_for_instrumentation" do
34
+ context "with non-moped event" do
35
+ it "should instantiate a new Appsignal::Event" do
36
+ expect( Appsignal::Event ).to receive(:new)
37
+ Appsignal::Event.event_for_instrumentation('query.active_record')
38
+ end
39
+ end
40
+
41
+ context "with moped event" do
42
+ it "should instantiate a moped event" do
43
+ expect( Appsignal::Event::MopedEvent ).to receive(:new)
44
+ Appsignal::Event.event_for_instrumentation('query.moped')
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ unless running_jruby?
5
+ describe Appsignal::IPC do
6
+ before :all do
7
+ start_agent
8
+ end
9
+ after :all do
10
+ Appsignal::IPC::Client.stop
11
+ Appsignal::IPC::Server.stop
12
+ end
13
+
14
+ subject { Appsignal::IPC }
15
+
16
+ describe ".forked!" do
17
+ it "should stop the server, start the client and stop the appsignal thread" do
18
+ Appsignal::IPC::Server.should_receive(:stop)
19
+ Appsignal::IPC::Client.should_receive(:start)
20
+ Appsignal.agent.should_receive(:stop_thread)
21
+
22
+ subject.forked!
23
+ end
24
+ end
25
+
26
+ describe Appsignal::IPC::Server do
27
+ subject { Appsignal::IPC::Server }
28
+
29
+ describe ".start" do
30
+ before do
31
+ FileUtils.rm_rf(File.join(project_fixture_path, 'tmp'))
32
+ Process.stub(:pid => 100)
33
+ end
34
+
35
+ it "should start a DRb server" do
36
+ DRb.should_receive(:start_service).with(
37
+ instance_of(String),
38
+ Appsignal::IPC::Server
39
+ )
40
+ subject.start
41
+ subject.uri.should == 'drbunix:/tmp/appsignal-100'
42
+ end
43
+
44
+ context "when a tmp path exists in the project path" do
45
+ before do
46
+ FileUtils.mkdir_p(File.join(project_fixture_path, 'tmp'))
47
+ end
48
+
49
+ it "should use a uri in the project path" do
50
+ subject.start
51
+ subject.uri.should == "drbunix:#{project_fixture_path}/tmp/appsignal-100"
52
+ end
53
+ end
54
+ end
55
+
56
+ describe ".stop" do
57
+ it "should stop the DRb server" do
58
+ DRb.should_receive(:stop_service)
59
+ subject.stop
60
+ end
61
+ end
62
+
63
+ describe ".enqueue" do
64
+ let(:transaction) { regular_transaction }
65
+
66
+ it "should enqueue" do
67
+ Appsignal.agent.aggregator.has_transactions?.should be_false
68
+ subject.enqueue(transaction)
69
+ Appsignal.agent.aggregator.has_transactions?.should be_true
70
+ end
71
+ end
72
+ end
73
+
74
+ describe Appsignal::IPC::Client do
75
+ before do
76
+ Appsignal::IPC::Client.stop
77
+ end
78
+
79
+ subject { Appsignal::IPC::Client }
80
+
81
+ describe ".start" do
82
+ it "should start the client" do
83
+ subject.active?.should be_false
84
+
85
+ subject.start
86
+
87
+ subject.server.should be_instance_of(DRbObject)
88
+ subject.active?.should be_true
89
+ end
90
+ end
91
+
92
+ describe ".stop" do
93
+ it "should stop the client" do
94
+ subject.start
95
+ subject.stop
96
+
97
+ subject.server.should be_nil
98
+ subject.active?.should be_false
99
+ end
100
+ end
101
+
102
+ describe ".enqueue" do
103
+ let(:transaction) { regular_transaction }
104
+
105
+ it "should send the transaction to the server" do
106
+ subject.start
107
+ subject.server.should_receive(:enqueue).with(transaction)
108
+ subject.enqueue(transaction)
109
+ end
110
+ end
111
+ end
112
+
113
+ describe "integration between client and server" do
114
+ it "should enqueue a transaction on the master" do
115
+ Appsignal::IPC::Server.start
116
+
117
+ fork do
118
+ Appsignal::IPC.forked!
119
+ Appsignal::IPC::Client.enqueue(regular_transaction)
120
+ end
121
+
122
+ Appsignal.agent.should_receive(:enqueue).with(instance_of(Appsignal::Transaction))
123
+
124
+ sleep 1 # Wait for the forked process to do it's work
125
+ end
126
+ end
127
+ end
128
+ end
@@ -6,8 +6,8 @@ class ErrorOnInspect
6
6
  end
7
7
  end
8
8
 
9
- describe Appsignal::Transaction::ParamsSanitizer do
10
- let(:klass) { Appsignal::Transaction::ParamsSanitizer }
9
+ describe Appsignal::ParamsSanitizer do
10
+ let(:klass) { Appsignal::ParamsSanitizer }
11
11
  let(:file) { uploaded_file }
12
12
  let(:params) do
13
13
  {
@@ -230,6 +230,16 @@ describe Appsignal::Transaction do
230
230
  end
231
231
  end
232
232
 
233
+ describe "clear_events!" do
234
+ let(:transaction) { slow_transaction }
235
+
236
+ it "should remove events from the transaction" do
237
+ expect {
238
+ transaction.clear_events!
239
+ }.to change(transaction.events, :length).from(1).to(0)
240
+ end
241
+ end
242
+
233
243
  describe "#truncate!" do
234
244
  subject { slow_transaction }
235
245
  before { subject.set_tags('a' => 'b') }
@@ -244,7 +254,7 @@ describe Appsignal::Transaction do
244
254
  end
245
255
 
246
256
  it "should not truncate twice" do
247
- subject.process_action_event.payload.should_receive(:clear).once
257
+ subject.process_action_event.should_receive(:truncate!).once
248
258
  subject.events.should_receive(:clear).once
249
259
 
250
260
  subject.truncate!
@@ -254,17 +264,17 @@ describe Appsignal::Transaction do
254
264
 
255
265
  describe "#convert_values_to_primitives!" do
256
266
  let(:transaction) { slow_transaction }
257
- let(:action_event_payload) { transaction.process_action_event.payload }
258
- let(:event_payload) { transaction.events.first.payload }
267
+ let(:action_event) { transaction.process_action_event }
268
+ let(:event) { transaction.events.first }
259
269
  let(:weird_class) { Class.new }
260
270
  let(:smash) { Smash.new.merge!(:foo => 'bar') }
261
271
 
262
272
  context "with values that need to be converted" do
263
273
  context "process action event payload" do
264
- subject { action_event_payload }
274
+ subject { action_event.payload }
265
275
  before do
266
- action_event_payload.clear
267
- action_event_payload.merge!(
276
+ action_event.payload.clear
277
+ action_event.payload.merge!(
268
278
  :model => {:with => [:weird, weird_class]},
269
279
  )
270
280
  transaction.convert_values_to_primitives!
@@ -278,10 +288,10 @@ describe Appsignal::Transaction do
278
288
  end
279
289
 
280
290
  context "payload of events" do
281
- subject { event_payload }
291
+ subject { event.payload }
282
292
  before do
283
- event_payload.clear
284
- event_payload.merge!(
293
+ event.payload.clear
294
+ event.payload.merge!(
285
295
  :weird => weird_class,
286
296
  :smash => smash
287
297
  )
@@ -298,22 +308,22 @@ describe Appsignal::Transaction do
298
308
  subject { transaction.convert_values_to_primitives! }
299
309
 
300
310
  it "doesn't change the action event payload" do
301
- before = action_event_payload.dup
311
+ before = action_event.payload.dup
302
312
  subject
303
- action_event_payload.should == before
313
+ action_event.payload.should == before
304
314
  end
305
315
 
306
316
  it " doesn't change the event payloads" do
307
- before = event_payload.dup
317
+ before = event.payload.dup
308
318
  subject
309
- event_payload.should == before
319
+ event.payload.should == before
310
320
  end
311
321
 
312
322
  it "should not covert to primitives twice" do
313
323
  transaction.convert_values_to_primitives!
314
324
  transaction.have_values_been_converted_to_primitives?.should be_true
315
325
 
316
- Appsignal::Transaction::ParamsSanitizer.should_not_receive(:sanitize!)
326
+ Appsignal::ParamsSanitizer.should_not_receive(:sanitize!)
317
327
  transaction.convert_values_to_primitives!
318
328
  end
319
329
  end
@@ -348,7 +358,7 @@ describe Appsignal::Transaction do
348
358
  describe '#complete!' do
349
359
  let(:event) { double(:event) }
350
360
  before do
351
- Appsignal::Pipe.stub(:current => nil)
361
+ Appsignal::IPC.stub(:current => nil)
352
362
  transaction.set_process_action_event(notification_event)
353
363
  end
354
364
 
@@ -387,20 +397,18 @@ describe Appsignal::Transaction do
387
397
  after { transaction.complete! }
388
398
  end
389
399
 
390
- context 'when using pipes' do
391
- let(:pipe) { double }
400
+ context 'when using IPC' do
392
401
  before do
393
- Appsignal::Pipe.stub(:current => pipe)
394
- pipe.stub(:write => true)
402
+ Appsignal::IPC::Client.start
395
403
  transaction.stub(:convert_values_to_primitives! => true)
396
404
  end
397
-
398
- it "should send itself trough the pipe" do
399
- pipe.should_receive(:write).with(transaction)
405
+ after do
406
+ Appsignal::IPC::Client.stop
400
407
  end
401
408
 
402
- it "should convert itself to primitives" do
409
+ it "should convert to primitves and send itself trough the pipe" do
403
410
  transaction.should_receive(:convert_values_to_primitives!)
411
+ Appsignal::IPC::Client.should_receive(:enqueue).with(transaction)
404
412
  end
405
413
 
406
414
  after { transaction.complete! }
@@ -565,7 +573,7 @@ describe Appsignal::Transaction do
565
573
  end
566
574
 
567
575
  it "passes the session data into the params sanitizer" do
568
- Appsignal::Transaction::ParamsSanitizer.should_receive(:sanitize).with({:foo => :bar}).
576
+ Appsignal::ParamsSanitizer.should_receive(:sanitize).with({:foo => :bar}).
569
577
  and_return(:sanitized_foo)
570
578
  subject
571
579
  transaction.sanitized_session_data.should == :sanitized_foo
@@ -584,7 +592,7 @@ describe Appsignal::Transaction do
584
592
  end
585
593
 
586
594
  it "should return an session hash" do
587
- Appsignal::Transaction::ParamsSanitizer.should_receive(:sanitize).with({'foo' => :bar}).
595
+ Appsignal::ParamsSanitizer.should_receive(:sanitize).with({'foo' => :bar}).
588
596
  and_return(:sanitized_foo)
589
597
  subject
590
598
  end
@@ -403,7 +403,7 @@ describe Appsignal do
403
403
  end
404
404
 
405
405
  describe ".send_exception" do
406
- before { Appsignal::Pipe.stub(:current => false) }
406
+ before { Appsignal::IPC.stub(:current => false) }
407
407
  let(:tags) { nil }
408
408
 
409
409
  it "should send the exception to AppSignal" do
@@ -20,6 +20,10 @@ def rails_present?
20
20
  RAILS_PRESENT
21
21
  end
22
22
 
23
+ def running_jruby?
24
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
25
+ end
26
+
23
27
  def capistrano_present?
24
28
  !! Gem.loaded_specs['capistrano']
25
29
  end
@@ -7,7 +7,7 @@ module NotificationHelpers
7
7
  :tid => '1',
8
8
  :payload => create_payload
9
9
  }.merge(args)
10
- ActiveSupport::Notifications::Event.new(
10
+ Appsignal::Event.new(
11
11
  args[:name], args[:start], args[:ending], args[:tid], args[:payload]
12
12
  )
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appsignal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.6
4
+ version: 0.11.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Beekman
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-09-09 00:00:00.000000000 Z
15
+ date: 2014-10-24 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rack
@@ -152,6 +152,8 @@ files:
152
152
  - lib/appsignal/capistrano.rb
153
153
  - lib/appsignal/cli.rb
154
154
  - lib/appsignal/config.rb
155
+ - lib/appsignal/event.rb
156
+ - lib/appsignal/event/moped_event.rb
155
157
  - lib/appsignal/instrumentations/net_http.rb
156
158
  - lib/appsignal/integrations/capistrano/appsignal.cap
157
159
  - lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb
@@ -163,8 +165,9 @@ files:
163
165
  - lib/appsignal/integrations/sidekiq.rb
164
166
  - lib/appsignal/integrations/sinatra.rb
165
167
  - lib/appsignal/integrations/unicorn.rb
168
+ - lib/appsignal/ipc.rb
166
169
  - lib/appsignal/marker.rb
167
- - lib/appsignal/pipe.rb
170
+ - lib/appsignal/params_sanitizer.rb
168
171
  - lib/appsignal/rack/instrumentation.rb
169
172
  - lib/appsignal/rack/listener.rb
170
173
  - lib/appsignal/transaction.rb
@@ -190,6 +193,8 @@ files:
190
193
  - spec/lib/appsignal/auth_check_spec.rb
191
194
  - spec/lib/appsignal/cli_spec.rb
192
195
  - spec/lib/appsignal/config_spec.rb
196
+ - spec/lib/appsignal/event/moped_event_spec.rb
197
+ - spec/lib/appsignal/event_spec.rb
193
198
  - spec/lib/appsignal/instrumentations/net_http_spec.rb
194
199
  - spec/lib/appsignal/integrations/capistrano2_spec.rb
195
200
  - spec/lib/appsignal/integrations/capistrano3_spec.rb
@@ -200,12 +205,12 @@ files:
200
205
  - spec/lib/appsignal/integrations/sidekiq_spec.rb
201
206
  - spec/lib/appsignal/integrations/sinatra_spec.rb
202
207
  - spec/lib/appsignal/integrations/unicorn_spec.rb
208
+ - spec/lib/appsignal/ipc_spec.rb
203
209
  - spec/lib/appsignal/marker_spec.rb
204
- - spec/lib/appsignal/pipe_spec.rb
210
+ - spec/lib/appsignal/params_sanitizer_spec.rb
205
211
  - spec/lib/appsignal/rack/instrumentation_spec.rb
206
212
  - spec/lib/appsignal/rack/listener_spec.rb
207
213
  - spec/lib/appsignal/transaction/formatter_spec.rb
208
- - spec/lib/appsignal/transaction/params_sanitizer_spec.rb
209
214
  - spec/lib/appsignal/transaction_spec.rb
210
215
  - spec/lib/appsignal/transmitter_spec.rb
211
216
  - spec/lib/appsignal_spec.rb
@@ -237,9 +242,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
237
242
  version: 1.9.3
238
243
  required_rubygems_version: !ruby/object:Gem::Requirement
239
244
  requirements:
240
- - - ">="
245
+ - - ">"
241
246
  - !ruby/object:Gem::Version
242
- version: '0'
247
+ version: 1.3.1
243
248
  requirements: []
244
249
  rubyforge_project:
245
250
  rubygems_version: 2.2.2
@@ -257,6 +262,8 @@ test_files:
257
262
  - spec/lib/appsignal/auth_check_spec.rb
258
263
  - spec/lib/appsignal/cli_spec.rb
259
264
  - spec/lib/appsignal/config_spec.rb
265
+ - spec/lib/appsignal/event/moped_event_spec.rb
266
+ - spec/lib/appsignal/event_spec.rb
260
267
  - spec/lib/appsignal/instrumentations/net_http_spec.rb
261
268
  - spec/lib/appsignal/integrations/capistrano2_spec.rb
262
269
  - spec/lib/appsignal/integrations/capistrano3_spec.rb
@@ -267,12 +274,12 @@ test_files:
267
274
  - spec/lib/appsignal/integrations/sidekiq_spec.rb
268
275
  - spec/lib/appsignal/integrations/sinatra_spec.rb
269
276
  - spec/lib/appsignal/integrations/unicorn_spec.rb
277
+ - spec/lib/appsignal/ipc_spec.rb
270
278
  - spec/lib/appsignal/marker_spec.rb
271
- - spec/lib/appsignal/pipe_spec.rb
279
+ - spec/lib/appsignal/params_sanitizer_spec.rb
272
280
  - spec/lib/appsignal/rack/instrumentation_spec.rb
273
281
  - spec/lib/appsignal/rack/listener_spec.rb
274
282
  - spec/lib/appsignal/transaction/formatter_spec.rb
275
- - spec/lib/appsignal/transaction/params_sanitizer_spec.rb
276
283
  - spec/lib/appsignal/transaction_spec.rb
277
284
  - spec/lib/appsignal/transmitter_spec.rb
278
285
  - spec/lib/appsignal_spec.rb