appsignal 1.1.5 → 1.1.6.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/gemfiles/capistrano3.gemfile +1 -1
- data/lib/appsignal.rb +1 -0
- data/lib/appsignal/event_formatter/faraday/request_formatter.rb +18 -0
- data/lib/appsignal/rack/generic_instrumentation.rb +47 -0
- data/lib/appsignal/transaction.rb +11 -4
- data/lib/appsignal/version.rb +1 -1
- data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +23 -0
- data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +91 -0
- data/spec/lib/appsignal/transaction_spec.rb +14 -0
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ae9ee5ab79b406d2d3334b3f5b36af2b4a983a0
|
4
|
+
data.tar.gz: 3ffba4eac43c6f0f5d7fcdb5aaf9b7b14234041c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f044966b171092d94def63d5a0bfaf12941eac1ee7bece88968267050cdf0dd5c40e2cf57c21be33c2909a945cec2f80f564638619a74fc21ee828d908ef2de
|
7
|
+
data.tar.gz: c497ebe798b27c9dd78b379b4713cabf21891a00bd4dc5a8140b6ec3d7bf47e66b1e59d63b539a674a7cecdd72d15f7e3b31aadc18d06467e1b7e759573804ce
|
data/CHANGELOG.md
CHANGED
data/lib/appsignal.rb
CHANGED
@@ -266,6 +266,7 @@ require 'appsignal/integrations/resque'
|
|
266
266
|
require 'appsignal/subscriber'
|
267
267
|
require 'appsignal/transaction'
|
268
268
|
require 'appsignal/version'
|
269
|
+
require 'appsignal/rack/generic_instrumentation'
|
269
270
|
require 'appsignal/rack/js_exception_catcher'
|
270
271
|
require 'appsignal/js_exception_transaction'
|
271
272
|
require 'appsignal/transmitter'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Appsignal
|
2
|
+
class EventFormatter
|
3
|
+
module Faraday
|
4
|
+
class RequestFormatter < Appsignal::EventFormatter
|
5
|
+
register 'request.faraday'
|
6
|
+
|
7
|
+
def format(payload)
|
8
|
+
http_method = payload[:method].to_s.upcase
|
9
|
+
uri = payload[:url]
|
10
|
+
[
|
11
|
+
"#{http_method} #{uri.scheme}://#{uri.host}",
|
12
|
+
"#{http_method} #{uri.scheme}://#{uri.host}#{uri.path}"
|
13
|
+
]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Appsignal
|
4
|
+
module Rack
|
5
|
+
class GenericInstrumentation
|
6
|
+
def initialize(app, options = {})
|
7
|
+
Appsignal.logger.debug 'Initializing Appsignal::Rack::GenericInstrumentation'
|
8
|
+
@app, @options = app, options
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
if Appsignal.active?
|
13
|
+
call_with_appsignal_monitoring(env)
|
14
|
+
else
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def call_with_appsignal_monitoring(env)
|
20
|
+
request = ::Rack::Request.new(env)
|
21
|
+
transaction = Appsignal::Transaction.create(
|
22
|
+
SecureRandom.uuid,
|
23
|
+
Appsignal::Transaction::HTTP_REQUEST,
|
24
|
+
request
|
25
|
+
)
|
26
|
+
begin
|
27
|
+
ActiveSupport::Notifications.instrument('process_action.generic') do
|
28
|
+
@app.call(env)
|
29
|
+
end
|
30
|
+
rescue => error
|
31
|
+
transaction.set_error(error)
|
32
|
+
raise error
|
33
|
+
ensure
|
34
|
+
if env['appsignal.route']
|
35
|
+
transaction.set_action(env['appsignal.route'])
|
36
|
+
else
|
37
|
+
transaction.set_action('unknown')
|
38
|
+
end
|
39
|
+
transaction.set_metadata('path', request.path)
|
40
|
+
transaction.set_metadata('method', request.request_method)
|
41
|
+
transaction.set_http_or_background_queue_start
|
42
|
+
Appsignal::Transaction.complete_current!
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -19,15 +19,13 @@ module Appsignal
|
|
19
19
|
def create(id, namespace, request, options={})
|
20
20
|
# Check if we already have a running transaction
|
21
21
|
if Thread.current[:appsignal_transaction] != nil
|
22
|
-
|
23
22
|
# Log the issue and return the current transaction
|
24
23
|
Appsignal.logger.debug("Trying to start new transaction #{id} but #{current.transaction_id} is already running. Using #{current.transaction_id}")
|
25
24
|
|
26
25
|
# Return the current (running) transaction
|
27
26
|
current
|
28
|
-
|
29
|
-
# Otherwise, start a new transaction
|
30
27
|
else
|
28
|
+
# Otherwise, start a new transaction
|
31
29
|
Thread.current[:appsignal_transaction] = Appsignal::Transaction.new(id, namespace, request, options)
|
32
30
|
end
|
33
31
|
end
|
@@ -38,6 +36,9 @@ module Appsignal
|
|
38
36
|
|
39
37
|
def complete_current!
|
40
38
|
current.complete
|
39
|
+
rescue Exception => e
|
40
|
+
Appsignal.logger.error("Failed to complete transaction ##{current.transaction_id}. #{e.message}")
|
41
|
+
ensure
|
41
42
|
Thread.current[:appsignal_transaction] = nil
|
42
43
|
end
|
43
44
|
end
|
@@ -201,7 +202,13 @@ module Appsignal
|
|
201
202
|
def sanitized_params
|
202
203
|
return unless Appsignal.config[:send_params]
|
203
204
|
return unless request.respond_to?(options[:params_method])
|
204
|
-
|
205
|
+
begin
|
206
|
+
return unless params = request.send(options[:params_method])
|
207
|
+
rescue Exception => ex
|
208
|
+
# Getting params from the request has been know to fail.
|
209
|
+
Appsignal.logger.debug "Exception while getting params: #{ex}"
|
210
|
+
return
|
211
|
+
end
|
205
212
|
if params.is_a?(Hash)
|
206
213
|
Appsignal::ParamsSanitizer.sanitize(params)
|
207
214
|
elsif params.is_a?(Array)
|
data/lib/appsignal/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Appsignal::EventFormatter::Faraday::RequestFormatter do
|
4
|
+
let(:klass) { Appsignal::EventFormatter::Faraday::RequestFormatter }
|
5
|
+
let(:formatter) { klass.new }
|
6
|
+
|
7
|
+
it "should register request.faraday" do
|
8
|
+
Appsignal::EventFormatter.registered?('request.faraday', klass).should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#format" do
|
12
|
+
let(:payload) do
|
13
|
+
{
|
14
|
+
method: :get,
|
15
|
+
url: URI.parse("http://example.org/hello/world?some=param")
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { formatter.format(payload) }
|
20
|
+
|
21
|
+
it { should == ['GET http://example.org', 'GET http://example.org/hello/world'] }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Appsignal::Rack::GenericInstrumentation do
|
4
|
+
before :all do
|
5
|
+
start_agent
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:app) { double(:call => true) }
|
9
|
+
let(:env) { {:path => '/', :method => 'GET'} }
|
10
|
+
let(:options) { {} }
|
11
|
+
let(:middleware) { Appsignal::Rack::GenericInstrumentation.new(app, options) }
|
12
|
+
|
13
|
+
describe "#call" do
|
14
|
+
before do
|
15
|
+
middleware.stub(:raw_payload => {})
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when appsignal is active" do
|
19
|
+
before { Appsignal.stub(:active? => true) }
|
20
|
+
|
21
|
+
it "should call with monitoring" do
|
22
|
+
expect( middleware ).to receive(:call_with_appsignal_monitoring).with(env)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when appsignal is not active" do
|
27
|
+
before { Appsignal.stub(:active? => false) }
|
28
|
+
|
29
|
+
it "should not call with monitoring" do
|
30
|
+
expect( middleware ).to_not receive(:call_with_appsignal_monitoring)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should call the stack" do
|
34
|
+
expect( app ).to receive(:call).with(env)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
after { middleware.call(env) }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#call_with_appsignal_monitoring" do
|
42
|
+
it "should create a transaction" do
|
43
|
+
Appsignal::Transaction.should_receive(:create).with(
|
44
|
+
kind_of(String),
|
45
|
+
Appsignal::Transaction::HTTP_REQUEST,
|
46
|
+
kind_of(Rack::Request)
|
47
|
+
).and_return(double(:set_action => nil, :set_http_or_background_queue_start => nil, :set_metadata => nil))
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should call the app" do
|
51
|
+
app.should_receive(:call).with(env)
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with an error" do
|
55
|
+
let(:error) { VerySpecificError.new }
|
56
|
+
let(:app) do
|
57
|
+
double.tap do |d|
|
58
|
+
d.stub(:call).and_raise(error)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should set the error" do
|
63
|
+
Appsignal::Transaction.any_instance.should_receive(:set_error).with(error)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should set the action to unknown" do
|
68
|
+
Appsignal::Transaction.any_instance.should_receive(:set_action).with('unknown')
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with a route specified in the env" do
|
72
|
+
before do
|
73
|
+
env['appsignal.route'] = 'GET /'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should set the action" do
|
77
|
+
Appsignal::Transaction.any_instance.should_receive(:set_action).with('GET /')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should set metadata" do
|
82
|
+
Appsignal::Transaction.any_instance.should_receive(:set_metadata).twice
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should set the queue start" do
|
86
|
+
Appsignal::Transaction.any_instance.should_receive(:set_http_or_background_queue_start)
|
87
|
+
end
|
88
|
+
|
89
|
+
after { middleware.call(env) rescue VerySpecificError }
|
90
|
+
end
|
91
|
+
end
|
@@ -102,6 +102,14 @@ describe Appsignal::Transaction do
|
|
102
102
|
|
103
103
|
Thread.current[:appsignal_transaction].should be_nil
|
104
104
|
end
|
105
|
+
|
106
|
+
it "should still clear the transaction if there is an error" do
|
107
|
+
Appsignal::Extension.should_receive(:finish_transaction).with(kind_of(Integer)).and_raise 'Error'
|
108
|
+
|
109
|
+
Appsignal::Transaction.complete_current!
|
110
|
+
|
111
|
+
Thread.current[:appsignal_transaction].should be_nil
|
112
|
+
end
|
105
113
|
end
|
106
114
|
end
|
107
115
|
|
@@ -532,6 +540,12 @@ describe Appsignal::Transaction do
|
|
532
540
|
it { should be_nil }
|
533
541
|
end
|
534
542
|
|
543
|
+
context "when params crashes" do
|
544
|
+
before { transaction.request.stub(:params).and_raise(NoMethodError) }
|
545
|
+
|
546
|
+
it { should be_nil }
|
547
|
+
end
|
548
|
+
|
535
549
|
context "when not sending params" do
|
536
550
|
before { Appsignal.config.config_hash[:send_params] = false }
|
537
551
|
after { Appsignal.config.config_hash[:send_params] = true }
|
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: 1.1.
|
4
|
+
version: 1.1.6.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Beekman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-04
|
12
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/appsignal/event_formatter/active_record/instantiation_formatter.rb
|
160
160
|
- lib/appsignal/event_formatter/active_record/sql_formatter.rb
|
161
161
|
- lib/appsignal/event_formatter/elastic_search/search_formatter.rb
|
162
|
+
- lib/appsignal/event_formatter/faraday/request_formatter.rb
|
162
163
|
- lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb
|
163
164
|
- lib/appsignal/event_formatter/moped/query_formatter.rb
|
164
165
|
- lib/appsignal/event_formatter/net_http/request_formatter.rb
|
@@ -189,6 +190,7 @@ files:
|
|
189
190
|
- lib/appsignal/js_exception_transaction.rb
|
190
191
|
- lib/appsignal/marker.rb
|
191
192
|
- lib/appsignal/params_sanitizer.rb
|
193
|
+
- lib/appsignal/rack/generic_instrumentation.rb
|
192
194
|
- lib/appsignal/rack/js_exception_catcher.rb
|
193
195
|
- lib/appsignal/rack/rails_instrumentation.rb
|
194
196
|
- lib/appsignal/rack/sinatra_instrumentation.rb
|
@@ -219,6 +221,7 @@ files:
|
|
219
221
|
- spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb
|
220
222
|
- spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb
|
221
223
|
- spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb
|
224
|
+
- spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb
|
222
225
|
- spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb
|
223
226
|
- spec/lib/appsignal/event_formatter/moped/query_formatter_spec.rb
|
224
227
|
- spec/lib/appsignal/event_formatter/net_http/request_formatter_spec.rb
|
@@ -246,6 +249,7 @@ files:
|
|
246
249
|
- spec/lib/appsignal/js_exception_transaction_spec.rb
|
247
250
|
- spec/lib/appsignal/marker_spec.rb
|
248
251
|
- spec/lib/appsignal/params_sanitizer_spec.rb
|
252
|
+
- spec/lib/appsignal/rack/generic_instrumentation_spec.rb
|
249
253
|
- spec/lib/appsignal/rack/js_exception_catcher_spec.rb
|
250
254
|
- spec/lib/appsignal/rack/rails_instrumentation_spec.rb
|
251
255
|
- spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb
|
@@ -291,9 +295,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
291
295
|
version: '1.9'
|
292
296
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
293
297
|
requirements:
|
294
|
-
- - "
|
298
|
+
- - ">"
|
295
299
|
- !ruby/object:Gem::Version
|
296
|
-
version:
|
300
|
+
version: 1.3.1
|
297
301
|
requirements: []
|
298
302
|
rubyforge_project:
|
299
303
|
rubygems_version: 2.4.5
|
@@ -313,6 +317,7 @@ test_files:
|
|
313
317
|
- spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb
|
314
318
|
- spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb
|
315
319
|
- spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb
|
320
|
+
- spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb
|
316
321
|
- spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb
|
317
322
|
- spec/lib/appsignal/event_formatter/moped/query_formatter_spec.rb
|
318
323
|
- spec/lib/appsignal/event_formatter/net_http/request_formatter_spec.rb
|
@@ -340,6 +345,7 @@ test_files:
|
|
340
345
|
- spec/lib/appsignal/js_exception_transaction_spec.rb
|
341
346
|
- spec/lib/appsignal/marker_spec.rb
|
342
347
|
- spec/lib/appsignal/params_sanitizer_spec.rb
|
348
|
+
- spec/lib/appsignal/rack/generic_instrumentation_spec.rb
|
343
349
|
- spec/lib/appsignal/rack/js_exception_catcher_spec.rb
|
344
350
|
- spec/lib/appsignal/rack/rails_instrumentation_spec.rb
|
345
351
|
- spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb
|