appsignal 0.11.13.beta.2 → 0.11.13.beta.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2d6b6b69b1d8d66673b8322f59914d9b0ee411e
4
- data.tar.gz: 1f10620110c8acc23fb9c0bfdd6eba8e027d262e
3
+ metadata.gz: e82e8a2b0ee5efe8865d8bb8bef7862255e2966c
4
+ data.tar.gz: 2b19926295a4060b742aecd9a7bfa1bda1ab3431
5
5
  SHA512:
6
- metadata.gz: 968ef086fccf1833f3f6049dc16b800c8488069252a700424bc98d03cb58164f2ebd0d4b0a11bcba7464b1d9f2af67e1482d78790886c4fa76be117068263ad0
7
- data.tar.gz: 96225881c0898a7a0febb304cd0253cdf5237729c1b5e89af777ac15bf08845b9ea1c7943ad834b02e638f3810bfdfd92210f346df8a8795b6410f1b2c582502
6
+ metadata.gz: b4fdd6810b6997212c6eac458185efb503c505f214547541357bec9c1f5c3138ca9e1535c716594bc2eaba79c29a1c6bb3496a017b3a3066216aba6ae22a5c75
7
+ data.tar.gz: 014ce4f570b63b9856639378bfe3a1153d4dfcf83358ceef38ede6d5d37d29ed70acda922a73cbeb04f746d869385348665816c8017bf5e706c8fb02a2143033
@@ -3,9 +3,13 @@ module Rake
3
3
  alias_method :invoke_without_appsignal, :invoke
4
4
 
5
5
  def invoke(*args)
6
- transaction = Appsignal::Transaction.create(SecureRandom.uuid, ENV)
7
- transaction.set_kind('background_job')
8
- transaction.set_action(name)
6
+ transaction = Appsignal::Transaction.create(
7
+ SecureRandom.uuid,
8
+ ENV,
9
+ :kind => 'background_job',
10
+ :action => name,
11
+ :params => args
12
+ )
9
13
 
10
14
  invoke_without_appsignal(*args)
11
15
  rescue => exception
@@ -11,10 +11,10 @@ module Appsignal
11
11
  HTTP_CACHE_CONTROL HTTP_CONNECTION HTTP_USER_AGENT HTTP_FROM HTTP_NEGOTIATE
12
12
  HTTP_PRAGMA HTTP_REFERER HTTP_X_FORWARDED_FOR HTTP_CLIENT_IP).freeze
13
13
 
14
- def self.create(request_id, env)
14
+ def self.create(request_id, env, defaults={})
15
15
  Appsignal.logger.debug("Creating transaction: #{request_id}")
16
16
  Thread.current[:appsignal_transaction_id] = request_id
17
- Appsignal::Transaction.new(request_id, env)
17
+ Appsignal::Transaction.new(request_id, env, defaults)
18
18
  end
19
19
 
20
20
  def self.current
@@ -31,17 +31,20 @@ module Appsignal
31
31
  end
32
32
 
33
33
  attr_reader :request_id, :events, :process_action_event, :action, :exception,
34
- :env, :fullpath, :time, :tags, :kind, :queue_start, :paused
34
+ :env, :fullpath, :time, :tags, :kind, :queue_start, :paused, :params
35
35
 
36
- def initialize(request_id, env)
36
+ def initialize(request_id, env, defaults={})
37
37
  Appsignal.transactions[request_id] = self
38
- @request_id = request_id
39
- @events = []
38
+ @request_id = request_id
39
+ @events = []
40
40
  @process_action_event = nil
41
- @exception = {}
42
- @env = env
43
- @tags = {}
44
- @paused = false
41
+ @exception = {}
42
+ @env = env
43
+ @params = defaults[:params] || {}
44
+ @tags = defaults[:tags] || {}
45
+ @kind = defaults[:kind] || 'web'
46
+ @action = defaults[:action]
47
+ @paused = false
45
48
  end
46
49
 
47
50
  def sanitized_environment
@@ -52,6 +55,10 @@ module Appsignal
52
55
  @sanitized_session_data ||= {}
53
56
  end
54
57
 
58
+ def sanitized_params
59
+ @sanitized_params ||= {}
60
+ end
61
+
55
62
  def request
56
63
  ::Rack::Request.new(@env)
57
64
  end
@@ -68,14 +75,6 @@ module Appsignal
68
75
  @paused = false
69
76
  end
70
77
 
71
- def set_kind(kind)
72
- @kind = kind
73
- end
74
-
75
- def set_action(action)
76
- @action = action
77
- end
78
-
79
78
  def set_process_action_event(event)
80
79
  return unless event && event.payload
81
80
  @process_action_event = event.dup
@@ -144,6 +143,7 @@ module Appsignal
144
143
  tags.clear
145
144
  sanitized_environment.clear
146
145
  sanitized_session_data.clear
146
+ sanitized_params.clear
147
147
  @env = nil
148
148
  @truncated = true
149
149
  end
@@ -221,6 +221,7 @@ module Appsignal
221
221
  sanitize_environment!
222
222
  sanitize_session_data! if kind == 'http_request'
223
223
  sanitize_tags!
224
+ sanitize_params!
224
225
  @env = nil
225
226
  end
226
227
 
@@ -236,7 +237,7 @@ module Appsignal
236
237
  end
237
238
 
238
239
  def sanitize_environment!
239
- return unless env
240
+ return unless env && env.keys.any?
240
241
  ENV_METHODS.each do |key|
241
242
  sanitized_environment[key] = env[key]
242
243
  end
@@ -248,5 +249,10 @@ module Appsignal
248
249
  ) if Appsignal.config[:skip_session_data] == false
249
250
  @fullpath = request.fullpath
250
251
  end
252
+
253
+ def sanitize_params!
254
+ return unless Appsignal.config[:send_params]
255
+ @sanitized_params = Appsignal::ParamsSanitizer.sanitize(@params)
256
+ end
251
257
  end
252
258
  end
@@ -23,16 +23,17 @@ module Appsignal
23
23
  def default_hash
24
24
  {
25
25
  :request_id => request_id,
26
- :log_entry => {
27
- :path => fullpath,
28
- :kind => kind,
29
- :action => action,
30
- :time => time,
31
- :environment => sanitized_environment,
26
+ :log_entry => {
27
+ :path => fullpath,
28
+ :kind => kind,
29
+ :action => action,
30
+ :time => time,
31
+ :environment => sanitized_environment,
32
32
  :session_data => sanitized_session_data,
33
- :revision => Appsignal.agent.revision
33
+ :params => sanitized_params,
34
+ :revision => Appsignal.agent.revision
34
35
  },
35
- :failed => exception?
36
+ :failed => exception?
36
37
  }
37
38
  end
38
39
 
@@ -1,3 +1,3 @@
1
1
  module Appsignal
2
- VERSION = '0.11.13.beta.2'
2
+ VERSION = '0.11.13.beta.3'
3
3
  end
@@ -24,16 +24,19 @@ describe "Rack integration" do
24
24
  let!(:transaction) { Appsignal::Transaction.new('123', {}) }
25
25
  let!(:agent) { double('Agent', :send_queue => true) }
26
26
  before do
27
+ SecureRandom.stub(:uuid => '123')
27
28
  Appsignal::Transaction.stub(:create => transaction)
28
29
  Appsignal.stub(:agent => agent, :active? => true)
29
30
  end
30
31
 
31
- it "should set the kind" do
32
- expect( transaction ).to receive(:set_kind).with('background_job')
33
- end
34
-
35
- it "should set the action" do
36
- expect( transaction ).to receive(:set_action).with('task:name')
32
+ it "should create a transaction" do
33
+ expect( Appsignal::Transaction ).to receive(:create).with(
34
+ '123',
35
+ ENV,
36
+ :kind => 'background_job',
37
+ :action => 'task:name',
38
+ :params => ['foo']
39
+ )
37
40
  end
38
41
 
39
42
  it "should call the original task" do
@@ -28,6 +28,7 @@ describe Appsignal::Transaction::Formatter do
28
28
  :path => "/foo",
29
29
  :session_data => {},
30
30
  :revision => nil,
31
+ :params => {},
31
32
  :time => 1389783600.0,
32
33
  } }
33
34
  its([:events]) { should be_nil }
@@ -58,12 +59,19 @@ describe Appsignal::Transaction::Formatter do
58
59
 
59
60
  context "with a background request without payload" do
60
61
  let(:transaction) do
61
- Appsignal::Transaction.new('123', {}).tap do |transaction|
62
- transaction.set_kind('web')
63
- transaction.set_action('foo#bar')
64
- end
62
+ Appsignal::Transaction.new(
63
+ '123',
64
+ {},
65
+ {
66
+ :kind => 'web',
67
+ :action => 'foo#bar',
68
+ :params => {'foo' => 'bar'}
69
+ }
70
+ )
65
71
  end
66
72
 
73
+ before { transaction.send(:add_sanitized_context!) }
74
+
67
75
  it "should get the kind and action from the transaction" do
68
76
  subject.to_hash.should == {
69
77
  :request_id => '123',
@@ -74,7 +82,9 @@ describe Appsignal::Transaction::Formatter do
74
82
  :time => nil,
75
83
  :environment => {},
76
84
  :session_data => {},
77
- :revision => nil},
85
+ :revision => nil,
86
+ :params => {'foo' => 'bar'}
87
+ },
78
88
  :failed => false
79
89
  }
80
90
  end
@@ -199,6 +209,7 @@ describe Appsignal::Transaction::Formatter do
199
209
  :kind => "background_job",
200
210
  :path => "/foo",
201
211
  :session_data => {},
212
+ :params => {},
202
213
  :revision => nil,
203
214
  :time => 1389783600.0,
204
215
  } }
@@ -189,22 +189,6 @@ describe Appsignal::Transaction do
189
189
  end
190
190
  end
191
191
 
192
- describe "#set_kind" do
193
- it "should set the kind" do
194
- expect{
195
- transaction.set_kind('web')
196
- }.to change(transaction, :kind).from(nil).to('web')
197
- end
198
- end
199
-
200
- describe "#set_action" do
201
- it "should set the action" do
202
- expect{
203
- transaction.set_action('foo#bar')
204
- }.to change(transaction, :action).from(nil).to('foo#bar')
205
- end
206
- end
207
-
208
192
  context "using exceptions" do
209
193
  let(:exception) do
210
194
  double(
@@ -341,7 +325,12 @@ describe Appsignal::Transaction do
341
325
 
342
326
  describe "#truncate!" do
343
327
  subject { slow_transaction }
344
- before { subject.set_tags('a' => 'b') }
328
+ before do
329
+ subject.set_tags('a' => 'b')
330
+ subject.sanitized_environment[:foo] = 'bar'
331
+ subject.sanitized_session_data[:foo] = 'bar'
332
+ subject.sanitized_params[:foo] = 'bar'
333
+ end
345
334
 
346
335
  it "should clear the process action payload and events" do
347
336
  subject.truncate!
@@ -349,6 +338,11 @@ describe Appsignal::Transaction do
349
338
  subject.process_action_event.payload.should be_empty
350
339
  subject.events.should be_empty
351
340
  subject.tags.should be_empty
341
+
342
+ subject.sanitized_environment.should be_empty
343
+ subject.sanitized_session_data.should be_empty
344
+ subject.sanitized_params.should be_empty
345
+
352
346
  subject.truncated?.should be_true
353
347
  end
354
348
 
@@ -619,6 +613,7 @@ describe Appsignal::Transaction do
619
613
  transaction.should_receive(:sanitize_environment!)
620
614
  transaction.should_receive(:sanitize_session_data!)
621
615
  transaction.should_receive(:sanitize_tags!)
616
+ transaction.should_receive(:sanitize_params!)
622
617
  subject
623
618
  end
624
619
  end
@@ -630,6 +625,7 @@ describe Appsignal::Transaction do
630
625
  transaction.should_receive(:sanitize_environment!)
631
626
  transaction.should_not_receive(:sanitize_session_data!)
632
627
  transaction.should_receive(:sanitize_tags!)
628
+ transaction.should_receive(:sanitize_params!)
633
629
  subject
634
630
  end
635
631
  end
@@ -743,5 +739,35 @@ describe Appsignal::Transaction do
743
739
  end
744
740
  end
745
741
  end
742
+
743
+ describe '#sanitize_params!' do
744
+ let(:params) { {:foo => 'bar'} }
745
+ let(:transaction) do
746
+ Appsignal::Transaction.create('1', {}, :params => params)
747
+ end
748
+ before { Appsignal.config = {:send_params => true} }
749
+ subject { transaction.sanitized_params }
750
+
751
+ it "should call the params sanitizer and set sanitized params" do
752
+ Appsignal::ParamsSanitizer.should_receive(:sanitize)
753
+ .with(params)
754
+ .and_return({'foo' => 'bar'})
755
+
756
+ transaction.send(:sanitize_params!)
757
+
758
+ should == {'foo' => 'bar'}
759
+ end
760
+
761
+ context "when skipping session data" do
762
+ before { Appsignal.config = {:send_params => false} }
763
+
764
+ it "should not pass data to the params sanitizer" do
765
+ Appsignal::ParamsSanitizer.should_not_receive(:sanitize)
766
+ transaction.send(:sanitize_params!)
767
+
768
+ should == {}
769
+ end
770
+ end
771
+ end
746
772
  end
747
773
  end
@@ -82,13 +82,15 @@ module TransactionHelpers
82
82
  notification_event(:name => 'query.mongoid')
83
83
  ]
84
84
  exception = args.delete(:exception)
85
+ defaults = args.delete(:defaults) || {}
85
86
  Appsignal::Transaction.create(
86
87
  '1',
87
88
  {
88
89
  'HTTP_USER_AGENT' => 'IE6',
89
90
  'SERVER_NAME' => 'localhost',
90
91
  'action_dispatch.routes' => 'not_available'
91
- }.merge(args)
92
+ }.merge(args),
93
+ defaults
92
94
  ).tap do |o|
93
95
  o.set_process_action_event(process_action_event)
94
96
  o.add_exception(exception)
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.11.13.beta.2
4
+ version: 0.11.13.beta.3
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: 2015-07-30 00:00:00.000000000 Z
15
+ date: 2015-08-04 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rack