influx_reporter 1.0.0
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 +7 -0
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.rubocop.yml +51 -0
- data/.travis.yml +42 -0
- data/.yardopts +3 -0
- data/Dockerfile +9 -0
- data/Gemfile +7 -0
- data/HISTORY.md +1 -0
- data/LICENSE +14 -0
- data/README.md +189 -0
- data/Rakefile +27 -0
- data/gemfiles/Gemfile.base +29 -0
- data/gemfiles/Gemfile.rails-3.2.x +4 -0
- data/gemfiles/Gemfile.rails-4.0.x +4 -0
- data/gemfiles/Gemfile.rails-4.1.x +4 -0
- data/gemfiles/Gemfile.rails-4.2.x +5 -0
- data/gemfiles/Gemfile.rails-5.0.x +5 -0
- data/gemfiles/Gemfile.rails-HEAD +7 -0
- data/influx_reporter.gemspec +26 -0
- data/lib/influx_reporter.rb +142 -0
- data/lib/influx_reporter/client.rb +306 -0
- data/lib/influx_reporter/configuration.rb +88 -0
- data/lib/influx_reporter/data_builders.rb +18 -0
- data/lib/influx_reporter/data_builders/error.rb +52 -0
- data/lib/influx_reporter/data_builders/transactions.rb +120 -0
- data/lib/influx_reporter/error.rb +7 -0
- data/lib/influx_reporter/error_message.rb +85 -0
- data/lib/influx_reporter/error_message/exception.rb +14 -0
- data/lib/influx_reporter/error_message/http.rb +73 -0
- data/lib/influx_reporter/error_message/stacktrace.rb +76 -0
- data/lib/influx_reporter/error_message/user.rb +25 -0
- data/lib/influx_reporter/filter.rb +66 -0
- data/lib/influx_reporter/http_client.rb +140 -0
- data/lib/influx_reporter/influx_db_client.rb +74 -0
- data/lib/influx_reporter/injections.rb +89 -0
- data/lib/influx_reporter/injections/json.rb +21 -0
- data/lib/influx_reporter/injections/net_http.rb +50 -0
- data/lib/influx_reporter/injections/redis.rb +25 -0
- data/lib/influx_reporter/injections/sequel.rb +37 -0
- data/lib/influx_reporter/injections/sinatra.rb +59 -0
- data/lib/influx_reporter/integration/delayed_job.rb +30 -0
- data/lib/influx_reporter/integration/rails/inject_exceptions_catcher.rb +25 -0
- data/lib/influx_reporter/integration/railtie.rb +56 -0
- data/lib/influx_reporter/integration/resque.rb +18 -0
- data/lib/influx_reporter/integration/sidekiq.rb +130 -0
- data/lib/influx_reporter/line_cache.rb +21 -0
- data/lib/influx_reporter/logging.rb +39 -0
- data/lib/influx_reporter/middleware.rb +63 -0
- data/lib/influx_reporter/normalizers.rb +65 -0
- data/lib/influx_reporter/normalizers/action_controller.rb +34 -0
- data/lib/influx_reporter/normalizers/action_view.rb +72 -0
- data/lib/influx_reporter/normalizers/active_record.rb +45 -0
- data/lib/influx_reporter/sql_summarizer.rb +31 -0
- data/lib/influx_reporter/subscriber.rb +80 -0
- data/lib/influx_reporter/tasks.rb +28 -0
- data/lib/influx_reporter/trace.rb +48 -0
- data/lib/influx_reporter/trace_helpers.rb +31 -0
- data/lib/influx_reporter/transaction.rb +114 -0
- data/lib/influx_reporter/util.rb +18 -0
- data/lib/influx_reporter/util/constantize.rb +56 -0
- data/lib/influx_reporter/util/inspector.rb +72 -0
- data/lib/influx_reporter/util/timestamp.rb +11 -0
- data/lib/influx_reporter/version.rb +5 -0
- data/lib/influx_reporter/worker.rb +56 -0
- data/spec/influx_reporter/client_spec.rb +264 -0
- data/spec/influx_reporter/configuration_spec.rb +42 -0
- data/spec/influx_reporter/data_builders/error_spec.rb +40 -0
- data/spec/influx_reporter/data_builders/transactions_spec.rb +48 -0
- data/spec/influx_reporter/error_message/exception_spec.rb +22 -0
- data/spec/influx_reporter/error_message/http_spec.rb +55 -0
- data/spec/influx_reporter/error_message/stacktrace_spec.rb +56 -0
- data/spec/influx_reporter/error_message/user_spec.rb +26 -0
- data/spec/influx_reporter/error_message_spec.rb +102 -0
- data/spec/influx_reporter/filter_spec.rb +33 -0
- data/spec/influx_reporter/injections/net_http_spec.rb +35 -0
- data/spec/influx_reporter/injections/sequel_spec.rb +33 -0
- data/spec/influx_reporter/injections/sinatra_spec.rb +13 -0
- data/spec/influx_reporter/injections_spec.rb +50 -0
- data/spec/influx_reporter/integration/delayed_job_spec.rb +37 -0
- data/spec/influx_reporter/integration/json_spec.rb +41 -0
- data/spec/influx_reporter/integration/rails_spec.rb +92 -0
- data/spec/influx_reporter/integration/redis_spec.rb +20 -0
- data/spec/influx_reporter/integration/resque_spec.rb +42 -0
- data/spec/influx_reporter/integration/sidekiq_spec.rb +40 -0
- data/spec/influx_reporter/integration/sinatra_spec.rb +99 -0
- data/spec/influx_reporter/line_cache_spec.rb +38 -0
- data/spec/influx_reporter/logging_spec.rb +49 -0
- data/spec/influx_reporter/middleware_spec.rb +32 -0
- data/spec/influx_reporter/normalizers/action_controller_spec.rb +37 -0
- data/spec/influx_reporter/normalizers/action_view_spec.rb +78 -0
- data/spec/influx_reporter/normalizers/active_record_spec.rb +70 -0
- data/spec/influx_reporter/normalizers_spec.rb +16 -0
- data/spec/influx_reporter/sql_summarizer_spec.rb +35 -0
- data/spec/influx_reporter/subscriber_spec.rb +83 -0
- data/spec/influx_reporter/trace_spec.rb +43 -0
- data/spec/influx_reporter/transaction_spec.rb +98 -0
- data/spec/influx_reporter/util/inspector_spec.rb +41 -0
- data/spec/influx_reporter/util_spec.rb +20 -0
- data/spec/influx_reporter/worker_spec.rb +54 -0
- data/spec/influx_reporter_spec.rb +50 -0
- data/spec/spec_helper.rb +86 -0
- metadata +188 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module InfluxReporter
|
6
|
+
RSpec.describe ErrorMessage::Stacktrace do
|
7
|
+
def real_exception
|
8
|
+
1 / 0
|
9
|
+
rescue => e
|
10
|
+
e
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:config) { Configuration.new }
|
14
|
+
let(:exception) { real_exception }
|
15
|
+
|
16
|
+
describe '.from' do
|
17
|
+
it 'initializes from an exception' do
|
18
|
+
stacktrace = ErrorMessage::Stacktrace.from config, exception
|
19
|
+
expect(stacktrace.frames).to_not be_empty
|
20
|
+
|
21
|
+
# so meta
|
22
|
+
last_frame = stacktrace.frames.last
|
23
|
+
expect(last_frame.filename).to eq 'influx_reporter/error_message/stacktrace_spec.rb'
|
24
|
+
expect(last_frame.lineno).to be 8
|
25
|
+
expect(last_frame.abs_path).to_not be_nil
|
26
|
+
expect(last_frame.function).to eq '/'
|
27
|
+
expect(last_frame.vars).to be_nil
|
28
|
+
|
29
|
+
expect(last_frame.pre_context.last).to match(/def real_exception/)
|
30
|
+
expect(last_frame.context_line).to match(/1 \/ 0/)
|
31
|
+
expect(last_frame.post_context.first).to match(/rescue/)
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when context lines are off' do
|
35
|
+
let(:config) { Configuration.new context_lines: nil }
|
36
|
+
it 'initializes too' do
|
37
|
+
stacktrace = ErrorMessage::Stacktrace.from config, exception
|
38
|
+
expect(stacktrace.frames).to_not be_empty
|
39
|
+
|
40
|
+
last_frame = stacktrace.frames.last
|
41
|
+
expect(last_frame.pre_context).to be_nil
|
42
|
+
expect(last_frame.context_line).to be_nil
|
43
|
+
expect(last_frame.post_context).to be_nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#to_h' do
|
49
|
+
it 'is a hash' do
|
50
|
+
hsh = ErrorMessage::Stacktrace.from(config, exception).to_h
|
51
|
+
expect(hsh).to be_a Hash
|
52
|
+
expect(hsh.keys).to eq [:frames]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module InfluxReporter
|
6
|
+
RSpec.describe ErrorMessage::User do
|
7
|
+
let(:config) { Configuration.new }
|
8
|
+
|
9
|
+
class Controller
|
10
|
+
def current_user
|
11
|
+
Struct.new(:id, :email, :username).new(1, 'john@example.com', 'leroy')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.from_rack_env' do
|
16
|
+
it 'initializes from rack env' do
|
17
|
+
env = Rack::MockRequest.env_for '/', 'action_controller.instance' => Controller.new
|
18
|
+
user = ErrorMessage::User.from_rack_env config, env
|
19
|
+
|
20
|
+
expect(user.id).to be 1
|
21
|
+
expect(user.email).to eq 'john@example.com'
|
22
|
+
expect(user.username).to eq 'leroy'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module InfluxReporter
|
6
|
+
RSpec.describe ErrorMessage do
|
7
|
+
let(:config) { Configuration.new }
|
8
|
+
|
9
|
+
def real_exception
|
10
|
+
1 / 0
|
11
|
+
rescue => e
|
12
|
+
e
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#initialize' do
|
16
|
+
it 'sets attrs by hash' do
|
17
|
+
error = ErrorMessage.new config, 'Error', level: :warn
|
18
|
+
expect(error.level).to eq :warn
|
19
|
+
end
|
20
|
+
it 'yields itself' do
|
21
|
+
error = ErrorMessage.new(config, 'Error') { |m| m.level = :warn }
|
22
|
+
expect(error.level).to eq :warn
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.from_exception' do
|
27
|
+
it 'initializes from an exception' do
|
28
|
+
error = ErrorMessage.from_exception config, real_exception
|
29
|
+
expect(error.message).to eq 'ZeroDivisionError: divided by 0'
|
30
|
+
expect(error.level).to eq :error
|
31
|
+
|
32
|
+
expect(error.exception.type).to eq 'ZeroDivisionError'
|
33
|
+
expect(error.exception.value).to eq 'divided by 0'
|
34
|
+
expect(error.exception.module).to eq ''
|
35
|
+
|
36
|
+
expect(error.stacktrace.frames.length).to_not be 0
|
37
|
+
expect(error.stacktrace.frames.map(&:class).uniq)
|
38
|
+
.to eq [ErrorMessage::Stacktrace::Frame]
|
39
|
+
expect(error.culprit).to eq "influx_reporter/error_message_spec.rb:10:in `/'"
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'skips excluded exceptions' do
|
43
|
+
class ::SleepDeprivationError < StandardError; end
|
44
|
+
exception = SleepDeprivationError.new('so tired')
|
45
|
+
config.excluded_exceptions += %w[SleepDeprivationError]
|
46
|
+
|
47
|
+
error = ErrorMessage.from_exception config, exception
|
48
|
+
expect(error).to be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with a rack env' do
|
52
|
+
it 'adds rack env to message' do
|
53
|
+
env = Rack::MockRequest.env_for '/'
|
54
|
+
error = ErrorMessage.from_exception config, real_exception, rack_env: env
|
55
|
+
|
56
|
+
expect(error.http).to be_a(ErrorMessage::HTTP)
|
57
|
+
expect(error.http.url).to eq 'http://example.org/'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'uses proper filter options' do
|
61
|
+
env = Rack::MockRequest.env_for '/nested/path?foo=bar&password=SECRET'
|
62
|
+
error = ErrorMessage.from_exception config, real_exception, rack_env: env
|
63
|
+
expect(error.http.query_string).to eq 'foo=bar&password=[FILTERED]'
|
64
|
+
end
|
65
|
+
|
66
|
+
class DummyController
|
67
|
+
def current_user
|
68
|
+
Struct.new(:id, :email, :username).new(1, 'john@example.com', 'leroy')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'adds user from controller' do
|
73
|
+
env = Rack::MockRequest.env_for '/', 'action_controller.instance' => DummyController.new
|
74
|
+
error = ErrorMessage.from_exception config, real_exception, rack_env: env
|
75
|
+
|
76
|
+
expect(error.user).to be_a(ErrorMessage::User)
|
77
|
+
expect(error.user.id).to be 1
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'adds extra data to message' do
|
81
|
+
error = ErrorMessage.from_exception config, real_exception, extra: { 'test' => 1 }
|
82
|
+
|
83
|
+
expect(error.extra).to eq('test' => 1)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#add_extra' do
|
89
|
+
it 'adds extra info from hash' do
|
90
|
+
error_message = ErrorMessage.new config, 'Message'
|
91
|
+
error_message.add_extra(thing: 1)
|
92
|
+
expect(error_message.extra).to eq(thing: 1)
|
93
|
+
end
|
94
|
+
it 'merges with current' do
|
95
|
+
error_message = ErrorMessage.new config, 'Message'
|
96
|
+
error_message.extra = { other_thing: 2 }
|
97
|
+
error_message.add_extra(thing: 1)
|
98
|
+
expect(error_message.extra).to eq(thing: 1, other_thing: 2)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module InfluxReporter
|
6
|
+
RSpec.describe Filter do
|
7
|
+
let(:config) do
|
8
|
+
Configuration.new filter_parameters: [/password/, 'pwd', :_secret, :int_secret, 'non_existing']
|
9
|
+
end
|
10
|
+
|
11
|
+
subject do
|
12
|
+
Filter.new config
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#apply' do
|
16
|
+
it 'filters a string' do
|
17
|
+
data = 'password=SECRET&foo=bar&_secret=abc&pwd=de1&int_secret=123'
|
18
|
+
filtered_data = 'password=[FILTERED]&foo=bar&_secret=[FILTERED]&pwd=[FILTERED]&int_secret=[FILTERED]'
|
19
|
+
expect(subject.apply(data)).to eq filtered_data
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'filters a hash' do
|
23
|
+
data = { password: 'SECRET', foo: :bar, _secret: 'abc', pwd: 'de1', int_secret: 123 }
|
24
|
+
filtered_data = { password: '[FILTERED]',
|
25
|
+
foo: :bar,
|
26
|
+
_secret: '[FILTERED]',
|
27
|
+
pwd: '[FILTERED]',
|
28
|
+
int_secret: '[FILTERED]' }
|
29
|
+
expect(subject.apply(data)).to eq filtered_data
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
require 'open-uri'
|
6
|
+
|
7
|
+
module InfluxReporter
|
8
|
+
RSpec.describe 'net/http integration', start_without_worker: true do
|
9
|
+
it 'is installed' do
|
10
|
+
reg = InfluxReporter::Injections.installed['Net::HTTP']
|
11
|
+
expect(reg).to_not be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'traces http calls' do
|
15
|
+
InfluxReporter::Injections.installed['Net::HTTP'].install
|
16
|
+
|
17
|
+
WebMock.stub_request :get, 'http://example.com:80'
|
18
|
+
|
19
|
+
transaction = InfluxReporter.transaction 'Test'
|
20
|
+
|
21
|
+
Net::HTTP.start('example.com') do |http|
|
22
|
+
http.get '/'
|
23
|
+
end
|
24
|
+
|
25
|
+
expect(WebMock).to have_requested(:get, 'http://example.com')
|
26
|
+
expect(transaction.traces.length).to be 2
|
27
|
+
|
28
|
+
http_trace = transaction.traces.last
|
29
|
+
expect(http_trace.signature).to eq 'example.com'
|
30
|
+
expect(http_trace.extra).to eq(tags: { scheme: 'http', port: 80, method: 'GET' },
|
31
|
+
values: { path: '/' }
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'sequel'
|
5
|
+
|
6
|
+
module InfluxReporter
|
7
|
+
RSpec.describe Injections::Sequel do
|
8
|
+
it 'is installed' do
|
9
|
+
reg = InfluxReporter::Injections.installed['Sequel']
|
10
|
+
expect(reg).to_not be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
@db = Sequel.sqlite # in-memory db
|
15
|
+
|
16
|
+
@db.create_table :tests do
|
17
|
+
primary_key :id
|
18
|
+
String :title
|
19
|
+
end
|
20
|
+
|
21
|
+
@db[:tests].count # warm it up
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'traces db calls', start_without_worker: true do
|
25
|
+
t = InfluxReporter.transaction 'Test' do
|
26
|
+
@db[:tests].count
|
27
|
+
end.done(true)
|
28
|
+
|
29
|
+
expect(t.traces.length).to be 2
|
30
|
+
expect(t.traces.last.signature).to eq 'SELECT FROM `tests`'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'sinatra'
|
5
|
+
|
6
|
+
module InfluxReporter
|
7
|
+
RSpec.describe Injections::Sinatra do
|
8
|
+
it 'is installed' do
|
9
|
+
reg = InfluxReporter::Injections.installed['Sinatra::Base']
|
10
|
+
expect(reg).to_not be_nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module InfluxReporter
|
6
|
+
RSpec.describe Injections do
|
7
|
+
class TestProbe
|
8
|
+
def initialize
|
9
|
+
@installations = 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def install
|
13
|
+
@installations += 1
|
14
|
+
end
|
15
|
+
attr_reader :installations
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:probe) { TestProbe.new }
|
19
|
+
subject { InfluxReporter::Injections }
|
20
|
+
|
21
|
+
it 'installs right away if constant is defined' do
|
22
|
+
subject.register 'InfluxReporter', 'influx_reporter', probe
|
23
|
+
expect(probe.installations).to be 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'installs a require hook' do
|
27
|
+
subject.register 'SomeLib', 'influx_reporter', probe
|
28
|
+
|
29
|
+
expect(probe.installations).to be 0
|
30
|
+
|
31
|
+
class ::SomeLib; end
|
32
|
+
require 'influx_reporter'
|
33
|
+
expect(probe.installations).to be 1
|
34
|
+
|
35
|
+
require 'influx_reporter'
|
36
|
+
expect(probe.installations).to be 1
|
37
|
+
end
|
38
|
+
|
39
|
+
it "doesn't install something that never exists" do
|
40
|
+
subject.register 'SomethingElse', 'wut', probe
|
41
|
+
expect(probe.installations).to be 0
|
42
|
+
end
|
43
|
+
|
44
|
+
it "doesn't install when required but class is missing" do
|
45
|
+
subject.register 'SomethingElse', 'influx_reporter', probe
|
46
|
+
require 'influx_reporter'
|
47
|
+
expect(probe.installations).to be 0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# :nocov:
|
6
|
+
begin
|
7
|
+
require 'delayed_job'
|
8
|
+
rescue LoadError
|
9
|
+
puts 'Skipping delayed_job specs'
|
10
|
+
end
|
11
|
+
# :nocov:
|
12
|
+
|
13
|
+
if defined?(Delayed)
|
14
|
+
# so nasty
|
15
|
+
load File.join(
|
16
|
+
Gem::Specification.find_by_name('delayed_job').gem_dir,
|
17
|
+
'spec', 'delayed', 'backend', 'test.rb'
|
18
|
+
)
|
19
|
+
Delayed::Worker.backend = Delayed::Backend::Test::Job
|
20
|
+
|
21
|
+
describe Delayed::Plugins::InfluxReporter, start_without_worker: true do
|
22
|
+
class MyJob
|
23
|
+
def blow_up(e)
|
24
|
+
raise e
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'reports exceptions to InfluxReporter' do
|
29
|
+
exception = Exception.new('BOOM')
|
30
|
+
|
31
|
+
MyJob.new.delay.blow_up exception
|
32
|
+
|
33
|
+
expect(Delayed::Worker.new.work_off).to eq [0, 1]
|
34
|
+
expect(InfluxReporter::Client.inst.queue.length).to be 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
RSpec.describe 'JSON integration', start_without_worker: true do
|
7
|
+
if false # turned off for now
|
8
|
+
describe '#parse' do
|
9
|
+
it 'adds a trace to current transaction' do
|
10
|
+
transaction = InfluxReporter.transaction 'JSON' do
|
11
|
+
JSON.parse('[{"something":1}]')
|
12
|
+
end.done(true)
|
13
|
+
|
14
|
+
expect(transaction.traces.length).to be 2
|
15
|
+
expect(transaction.traces.last.signature).to eq 'JSON#parse'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#parse' do
|
20
|
+
it 'adds a trace to current transaction' do
|
21
|
+
transaction = InfluxReporter.transaction 'JSON' do
|
22
|
+
JSON.parse!('[{"something":1}]')
|
23
|
+
end.done(true)
|
24
|
+
|
25
|
+
expect(transaction.traces.length).to be 2
|
26
|
+
expect(transaction.traces.last.signature).to eq 'JSON#parse!'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#generate' do
|
31
|
+
it 'adds a trace to current transaction' do
|
32
|
+
transaction = InfluxReporter.transaction 'JSON' do
|
33
|
+
JSON.generate([{ something: 1 }])
|
34
|
+
end.done(true)
|
35
|
+
|
36
|
+
expect(transaction.traces.length).to be 2
|
37
|
+
expect(transaction.traces.last.signature).to eq 'JSON#generate'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
require 'rails'
|
6
|
+
require 'action_controller/railtie'
|
7
|
+
require 'influx_reporter/integration/railtie'
|
8
|
+
|
9
|
+
describe 'Rails integration' do
|
10
|
+
include Rack::Test::Methods
|
11
|
+
|
12
|
+
def boot
|
13
|
+
TinderButForHotDogs.initialize!
|
14
|
+
TinderButForHotDogs.routes.draw do
|
15
|
+
get 'error', to: 'users#error'
|
16
|
+
get 'json', to: 'users#other'
|
17
|
+
root to: 'users#index'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
before :all do
|
22
|
+
class TinderButForHotDogs < ::Rails::Application
|
23
|
+
config.secret_key_base = '__secret_key_base'
|
24
|
+
|
25
|
+
config.logger = Logger.new(DEBUG ? STDOUT : nil)
|
26
|
+
config.logger.level = Logger::DEBUG
|
27
|
+
|
28
|
+
config.eager_load = false
|
29
|
+
|
30
|
+
config.influx_reporter.database = 'APP_ID'
|
31
|
+
config.influx_reporter.disable_worker = true
|
32
|
+
end
|
33
|
+
|
34
|
+
class UsersController < ActionController::Base
|
35
|
+
def index
|
36
|
+
if Rails.version.to_i >= 5
|
37
|
+
render plain: 'HOT DOGS!'
|
38
|
+
else
|
39
|
+
render text: 'HOT DOGS!'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def other
|
44
|
+
json = InfluxReporter.trace('JSON.dump') { sleep 0.1; { result: :ok } }
|
45
|
+
render json: json
|
46
|
+
end
|
47
|
+
|
48
|
+
def error
|
49
|
+
raise Exception, 'NO KETCHUP!'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
boot
|
54
|
+
end
|
55
|
+
|
56
|
+
after :all do
|
57
|
+
Object.send(:remove_const, :TinderButForHotDogs)
|
58
|
+
Object.send(:remove_const, :UsersController)
|
59
|
+
Rails.application = nil
|
60
|
+
InfluxReporter.stop!
|
61
|
+
end
|
62
|
+
|
63
|
+
def app
|
64
|
+
@app ||= Rails.application
|
65
|
+
end
|
66
|
+
|
67
|
+
before :each do
|
68
|
+
InfluxReporter::Client.inst.queue.clear
|
69
|
+
InfluxReporter::Client.inst.instance_variable_set :@pending_transactions, []
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'adds an exception handler and handles exceptions' do
|
73
|
+
get '/error'
|
74
|
+
|
75
|
+
expect(InfluxReporter::Client.inst.queue.length).to be 1
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'traces actions and enqueues transaction' do
|
79
|
+
get '/'
|
80
|
+
|
81
|
+
expect(InfluxReporter::Client.inst.pending_transactions.length).to be 1
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'logs when failing to report error' do
|
85
|
+
allow(InfluxReporter::Client.inst).to receive(:report).and_raise
|
86
|
+
allow(Rails.logger).to receive(:error)
|
87
|
+
|
88
|
+
get '/404'
|
89
|
+
|
90
|
+
expect(Rails.logger).to have_received(:error).with(/\*\* \[InfluxReporter\] Error capturing/)
|
91
|
+
end
|
92
|
+
end
|