appsignal 0.6.3.beta.2 → 0.6.3.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 +8 -8
- data/CHANGELOG.md +1 -0
- data/lib/appsignal.rb +7 -4
- data/lib/appsignal/listener.rb +1 -3
- data/lib/appsignal/railtie.rb +0 -1
- data/lib/appsignal/transaction.rb +19 -1
- data/lib/appsignal/transaction/transaction_formatter.rb +11 -4
- data/lib/appsignal/version.rb +1 -1
- data/spec/appsignal/listener_spec.rb +0 -2
- data/spec/appsignal/transaction/transaction_formatter_spec.rb +11 -2
- data/spec/appsignal/transaction_spec.rb +41 -1
- data/spec/appsignal_spec.rb +22 -0
- data/spec/support/helpers/transaction_helpers.rb +6 -4
- metadata +2 -5
- data/lib/appsignal/exception_notification.rb +0 -28
- data/spec/appsignal/exception_notification_spec.rb +0 -38
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjhhMGUxYTk4NTgyYmUyZTlhNmU5OTQ5YTA5YjI1MjI1NmRiZjFkZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzdkMmI2NDJhNTU4NDliZWJjYmQwNTQ3NGZkYWRkZTFhZmIzYjdiMQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzRkMWNhMjFlNzEzNjZlZTFjYTU5YWI0NmZhM2ViMDllZjg2Y2NkOWMwZmFm
|
10
|
+
M2VlYTExYjJjY2E3ZTFkYjJjMjg5ZjMyMGQ4NGIwZWYwNjliNTE0MTNjZGI2
|
11
|
+
NDE2OTRmMDE2ZTBlOGQ4MWIyNjgyMWM0MzVlMjgzNzI5MGI4ZDg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDJkZWM1MTc5OTA3MjZhZjFjZjMzOTMxZWM2NTIyYWI1NDAyYzZlODZiMzJh
|
14
|
+
ZjY0ODg1MDEwZTllYzA2MzFjZTg1NGUwMTUyOGQxNTNiNDEyMmE5MTNkNzQw
|
15
|
+
MDk3MWEwN2Y1ZjNlMjZjMGM3MjQ1ZTg1YWMwNGNlOGE5MTEwNWE=
|
data/CHANGELOG.md
CHANGED
data/lib/appsignal.rb
CHANGED
@@ -32,14 +32,18 @@ module Appsignal
|
|
32
32
|
env = ENV.to_hash
|
33
33
|
|
34
34
|
transaction = Appsignal::Transaction.create(SecureRandom.uuid, env)
|
35
|
-
transaction.add_exception(
|
36
|
-
Appsignal::ExceptionNotification.new(env, exception, false)
|
37
|
-
)
|
35
|
+
transaction.add_exception(exception)
|
38
36
|
transaction.complete!
|
39
37
|
Appsignal.agent.send_queue
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
41
|
+
def tag_request(params={})
|
42
|
+
transaction = Appsignal::Transaction.current
|
43
|
+
return false unless transaction
|
44
|
+
transaction.set_tags(params)
|
45
|
+
end
|
46
|
+
|
43
47
|
def transactions
|
44
48
|
@transactions ||= {}
|
45
49
|
end
|
@@ -93,7 +97,6 @@ require 'appsignal/agent'
|
|
93
97
|
require 'appsignal/aggregator'
|
94
98
|
require 'appsignal/auth_check'
|
95
99
|
require 'appsignal/config'
|
96
|
-
require 'appsignal/exception_notification'
|
97
100
|
require 'appsignal/integrations/passenger'
|
98
101
|
require 'appsignal/listener'
|
99
102
|
require 'appsignal/marker'
|
data/lib/appsignal/listener.rb
CHANGED
@@ -11,9 +11,7 @@ module Appsignal
|
|
11
11
|
@app.call(env)
|
12
12
|
rescue Exception => exception
|
13
13
|
unless Appsignal.is_ignored_exception?(exception)
|
14
|
-
Appsignal::Transaction.current.add_exception(
|
15
|
-
Appsignal::ExceptionNotification.new(env, exception)
|
16
|
-
)
|
14
|
+
Appsignal::Transaction.current.add_exception(exception)
|
17
15
|
end
|
18
16
|
raise exception
|
19
17
|
ensure
|
data/lib/appsignal/railtie.rb
CHANGED
@@ -25,7 +25,7 @@ module Appsignal
|
|
25
25
|
end
|
26
26
|
|
27
27
|
attr_reader :request_id, :events, :process_action_event, :action, :exception,
|
28
|
-
:env, :fullpath, :time
|
28
|
+
:env, :fullpath, :time, :tags
|
29
29
|
|
30
30
|
def initialize(request_id, env)
|
31
31
|
@request_id = request_id
|
@@ -33,6 +33,7 @@ module Appsignal
|
|
33
33
|
@process_action_event = nil
|
34
34
|
@exception = nil
|
35
35
|
@env = env
|
36
|
+
@tags = {}
|
36
37
|
end
|
37
38
|
|
38
39
|
def sanitized_environment
|
@@ -47,6 +48,10 @@ module Appsignal
|
|
47
48
|
ActionDispatch::Request.new(@env)
|
48
49
|
end
|
49
50
|
|
51
|
+
def set_tags(given_tags={})
|
52
|
+
@tags.merge!(given_tags)
|
53
|
+
end
|
54
|
+
|
50
55
|
def set_process_action_event(event)
|
51
56
|
@process_action_event = event
|
52
57
|
if event && event.payload
|
@@ -80,6 +85,7 @@ module Appsignal
|
|
80
85
|
def truncate!
|
81
86
|
process_action_event.payload.clear
|
82
87
|
events.clear
|
88
|
+
tags.clear
|
83
89
|
sanitized_environment.clear
|
84
90
|
sanitized_session_data.clear
|
85
91
|
@env = nil
|
@@ -114,9 +120,21 @@ module Appsignal
|
|
114
120
|
def add_sanitized_context!
|
115
121
|
sanitize_environment!
|
116
122
|
sanitize_session_data!
|
123
|
+
sanitize_tags!
|
117
124
|
@env = nil
|
118
125
|
end
|
119
126
|
|
127
|
+
# Only keep tags if they meet the following criteria:
|
128
|
+
# * Key is a symbol or string with less then 100 chars
|
129
|
+
# * Value is a symbol or string with less then 100 chars
|
130
|
+
# * Value is an integer
|
131
|
+
def sanitize_tags!
|
132
|
+
@tags.keep_if do |k,v|
|
133
|
+
(k.is_a?(Symbol) || k.is_a?(String) && k.length <= 100) &&
|
134
|
+
(((v.is_a?(Symbol) || v.is_a?(String)) && v.length <= 100) || (v.is_a?(Integer)))
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
120
138
|
def sanitize_environment!
|
121
139
|
env.each do |key, value|
|
122
140
|
sanitized_environment[key] = value if ENV_METHODS.include?(key)
|
@@ -13,7 +13,10 @@ module Appsignal
|
|
13
13
|
|
14
14
|
def to_hash
|
15
15
|
merge_process_action_event_with_log_entry! if process_action_event
|
16
|
-
|
16
|
+
if exception?
|
17
|
+
add_exception_to_hash!
|
18
|
+
add_tags_to_hash!
|
19
|
+
end
|
17
20
|
add_events_to_hash! if slow_request?
|
18
21
|
hash
|
19
22
|
end
|
@@ -43,11 +46,15 @@ module Appsignal
|
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
49
|
+
def add_tags_to_hash!
|
50
|
+
hash[:log_entry][:tags] = tags
|
51
|
+
end
|
52
|
+
|
46
53
|
def add_exception_to_hash!
|
47
54
|
hash[:exception] = {
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
55
|
+
:exception => exception.class.name,
|
56
|
+
:message => exception.message,
|
57
|
+
:backtrace => Rails.backtrace_cleaner.clean(exception.backtrace, nil)
|
51
58
|
}
|
52
59
|
end
|
53
60
|
|
data/lib/appsignal/version.rb
CHANGED
@@ -40,7 +40,6 @@ describe Appsignal::Listener do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should catch the exception and notify the transaction of it' do
|
43
|
-
Appsignal::ExceptionNotification.should_receive(:new)
|
44
43
|
current.should_receive(:add_exception)
|
45
44
|
middleware.call(env) rescue nil
|
46
45
|
end
|
@@ -55,7 +54,6 @@ describe Appsignal::Listener do
|
|
55
54
|
end
|
56
55
|
|
57
56
|
it 'should ignore the error' do
|
58
|
-
Appsignal::ExceptionNotification.should_not_receive(:new)
|
59
57
|
current.should_not_receive(:add_exception)
|
60
58
|
middleware.call(env) rescue nil
|
61
59
|
end
|
@@ -40,13 +40,22 @@ describe Appsignal::TransactionFormatter do
|
|
40
40
|
its([:request_id]) { should == '1' }
|
41
41
|
its([:failed]) { should be_true }
|
42
42
|
|
43
|
+
context "log_entry content" do
|
44
|
+
subject { formatter.hash[:log_entry] }
|
45
|
+
|
46
|
+
its([:tags]) { should == {'user_id' => 123} }
|
47
|
+
end
|
48
|
+
|
43
49
|
context "exception content" do
|
44
50
|
subject { formatter.hash[:exception] }
|
45
51
|
|
46
|
-
its(:keys) { should =~ [:
|
47
|
-
its([:backtrace]) { should be_instance_of Array }
|
52
|
+
its(:keys) { should =~ [:exception, :message, :backtrace] }
|
48
53
|
its([:exception]) { should == 'ArgumentError' }
|
49
54
|
its([:message]) { should == 'oh no' }
|
55
|
+
its([:backtrace]) { should == [
|
56
|
+
'app/controllers/somethings_controller.rb:10',
|
57
|
+
'/user/local/ruby/path.rb:8'
|
58
|
+
] }
|
50
59
|
end
|
51
60
|
end
|
52
61
|
|
@@ -48,6 +48,14 @@ describe Appsignal::Transaction do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
describe "#set_tags" do
|
52
|
+
it "should add tags to transaction" do
|
53
|
+
expect {
|
54
|
+
transaction.set_tags({'a' => 'b'})
|
55
|
+
}.to change(transaction, :tags).to({'a' => 'b'})
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
51
59
|
describe '#add_event' do
|
52
60
|
let(:event) { double(:event, :name => 'test') }
|
53
61
|
|
@@ -141,12 +149,14 @@ describe Appsignal::Transaction do
|
|
141
149
|
|
142
150
|
describe "#truncate!" do
|
143
151
|
subject { slow_transaction }
|
152
|
+
before { subject.set_tags('a' => 'b') }
|
144
153
|
|
145
154
|
it "should clear the process action payload and events" do
|
146
155
|
subject.truncate!
|
147
156
|
|
148
157
|
subject.process_action_event.payload.should be_empty
|
149
158
|
subject.events.should be_empty
|
159
|
+
subject.tags.should be_empty
|
150
160
|
end
|
151
161
|
end
|
152
162
|
|
@@ -280,6 +290,7 @@ describe Appsignal::Transaction do
|
|
280
290
|
it "delegates to sanitize_environment! and sanitize_session_data!" do
|
281
291
|
transaction.should_receive(:sanitize_environment!)
|
282
292
|
transaction.should_receive(:sanitize_session_data!)
|
293
|
+
transaction.should_receive(:sanitize_tags!)
|
283
294
|
subject
|
284
295
|
end
|
285
296
|
|
@@ -301,6 +312,36 @@ describe Appsignal::Transaction do
|
|
301
312
|
its(:keys) { should =~ whitelisted_keys }
|
302
313
|
end
|
303
314
|
|
315
|
+
describe '#sanitize_tags!' do
|
316
|
+
let(:transaction) { Appsignal::Transaction.create('1', {}) }
|
317
|
+
before do
|
318
|
+
transaction.set_tags(
|
319
|
+
{
|
320
|
+
:valid_key => 'valid_value',
|
321
|
+
'valid_string_key' => 'valid_value',
|
322
|
+
:both_symbols => :valid_value,
|
323
|
+
:integer_value => 1,
|
324
|
+
:hash_value => {'invalid' => 'hash'},
|
325
|
+
:array_value => ['invalid', 'array'],
|
326
|
+
:to_long_value => SecureRandom.urlsafe_base64(101),
|
327
|
+
:object => Object.new,
|
328
|
+
SecureRandom.urlsafe_base64(101) => 'to_long_key'
|
329
|
+
}
|
330
|
+
)
|
331
|
+
transaction.send(:sanitize_tags!)
|
332
|
+
end
|
333
|
+
subject { transaction.tags.keys }
|
334
|
+
|
335
|
+
it "should only return whitelisted data" do
|
336
|
+
should =~ [
|
337
|
+
:valid_key,
|
338
|
+
'valid_string_key',
|
339
|
+
:both_symbols,
|
340
|
+
:integer_value
|
341
|
+
]
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
304
345
|
describe '#sanitize_session_data!' do
|
305
346
|
subject { transaction.send(:sanitize_session_data!) }
|
306
347
|
before do
|
@@ -334,7 +375,6 @@ describe Appsignal::Transaction do
|
|
334
375
|
subject
|
335
376
|
end
|
336
377
|
|
337
|
-
|
338
378
|
def action_dispatch_session
|
339
379
|
store = Class.new {
|
340
380
|
def load_session(env); [1, {:foo => :bar}]; end
|
data/spec/appsignal_spec.rb
CHANGED
@@ -14,6 +14,28 @@ describe Appsignal do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
describe ".tag_request" do
|
18
|
+
before { Appsignal::Transaction.stub(:current => transaction) }
|
19
|
+
|
20
|
+
context "with transaction" do
|
21
|
+
let(:transaction) { double }
|
22
|
+
|
23
|
+
it "should call set_tags on transaction" do
|
24
|
+
transaction.should_receive(:set_tags).with({'a' => 'b'})
|
25
|
+
end
|
26
|
+
|
27
|
+
after { Appsignal.tag_request({'a' => 'b'}) }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "without transaction" do
|
31
|
+
let(:transaction) { nil }
|
32
|
+
|
33
|
+
it "should call set_tags on transaction" do
|
34
|
+
Appsignal.tag_request.should be_false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
17
39
|
describe ".transactions" do
|
18
40
|
subject { Appsignal.transactions }
|
19
41
|
|
@@ -6,13 +6,15 @@ module TransactionHelpers
|
|
6
6
|
|
7
7
|
def transaction_with_exception
|
8
8
|
appsignal_transaction.tap do |o|
|
9
|
+
o.set_tags('user_id' => 123)
|
9
10
|
begin
|
10
11
|
raise ArgumentError, 'oh no'
|
11
12
|
rescue ArgumentError => exception
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
)
|
13
|
+
exception.stub(:backtrace => [
|
14
|
+
Rails.root.join('app/controllers/somethings_controller.rb:10').to_s,
|
15
|
+
'/user/local/ruby/path.rb:8'
|
16
|
+
])
|
17
|
+
o.add_exception(exception)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
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.6.3.beta.
|
4
|
+
version: 0.6.3.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: 2013-09-
|
15
|
+
date: 2013-09-23 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rails
|
@@ -144,7 +144,6 @@ files:
|
|
144
144
|
- lib/appsignal/careful_logger.rb
|
145
145
|
- lib/appsignal/cli.rb
|
146
146
|
- lib/appsignal/config.rb
|
147
|
-
- lib/appsignal/exception_notification.rb
|
148
147
|
- lib/appsignal/integrations/passenger.rb
|
149
148
|
- lib/appsignal/listener.rb
|
150
149
|
- lib/appsignal/marker.rb
|
@@ -172,7 +171,6 @@ files:
|
|
172
171
|
- spec/appsignal/capistrano_spec.rb
|
173
172
|
- spec/appsignal/cli_spec.rb
|
174
173
|
- spec/appsignal/config_spec.rb
|
175
|
-
- spec/appsignal/exception_notification_spec.rb
|
176
174
|
- spec/appsignal/inactive_railtie_spec.rb
|
177
175
|
- spec/appsignal/integrations/passenger_spec.rb
|
178
176
|
- spec/appsignal/listener_spec.rb
|
@@ -224,7 +222,6 @@ test_files:
|
|
224
222
|
- spec/appsignal/capistrano_spec.rb
|
225
223
|
- spec/appsignal/cli_spec.rb
|
226
224
|
- spec/appsignal/config_spec.rb
|
227
|
-
- spec/appsignal/exception_notification_spec.rb
|
228
225
|
- spec/appsignal/inactive_railtie_spec.rb
|
229
226
|
- spec/appsignal/integrations/passenger_spec.rb
|
230
227
|
- spec/appsignal/listener_spec.rb
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Appsignal
|
2
|
-
class MissingController
|
3
|
-
def method_missing(*args, &block)
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
class ExceptionNotification
|
8
|
-
attr_reader :env, :exception, :backtrace
|
9
|
-
|
10
|
-
def initialize(env, exception, run_rails_cleaner=true)
|
11
|
-
@env = env
|
12
|
-
@exception = exception
|
13
|
-
if run_rails_cleaner && Rails.respond_to?(:backtrace_cleaner)
|
14
|
-
@backtrace = Rails.backtrace_cleaner.clean(@exception.backtrace, nil)
|
15
|
-
else
|
16
|
-
@backtrace = @exception.backtrace
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def name
|
21
|
-
@exception.class.name
|
22
|
-
end
|
23
|
-
|
24
|
-
def message
|
25
|
-
@exception.message
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Appsignal::ExceptionNotification do
|
4
|
-
let(:error) { StandardError.new('moo') }
|
5
|
-
let(:notification) { Appsignal::ExceptionNotification.new({}, error, false) }
|
6
|
-
subject { notification }
|
7
|
-
before do
|
8
|
-
Rails.stub(:root => '/home/app/current')
|
9
|
-
end
|
10
|
-
|
11
|
-
its(:env) { should == {} }
|
12
|
-
its(:exception) { should == error }
|
13
|
-
its(:name) { should == 'StandardError' }
|
14
|
-
its(:message) { should == 'moo' }
|
15
|
-
|
16
|
-
context "backtrace" do
|
17
|
-
let(:backtrace) do
|
18
|
-
[
|
19
|
-
'/home/app/current/app/controllers/somethings_controller.rb:10',
|
20
|
-
'/user/local/ruby/path.rb:8'
|
21
|
-
]
|
22
|
-
end
|
23
|
-
before { error.stub(:backtrace => backtrace) }
|
24
|
-
|
25
|
-
subject { notification.backtrace }
|
26
|
-
|
27
|
-
it { should == backtrace }
|
28
|
-
|
29
|
-
context "when running the backtrace cleaner" do
|
30
|
-
let(:notification) { Appsignal::ExceptionNotification.new({}, error) }
|
31
|
-
|
32
|
-
it { should == [
|
33
|
-
'app/controllers/somethings_controller.rb:10',
|
34
|
-
'/user/local/ruby/path.rb:8'
|
35
|
-
] }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|