opbeat 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -3
  3. data/.travis.yml +19 -28
  4. data/.yardopts +3 -0
  5. data/Gemfile +4 -2
  6. data/HISTORY.md +3 -0
  7. data/LICENSE +7 -196
  8. data/README.md +96 -177
  9. data/Rakefile +19 -13
  10. data/gemfiles/Gemfile.base +28 -0
  11. data/gemfiles/Gemfile.rails-3.2.x +3 -0
  12. data/gemfiles/Gemfile.rails-4.0.x +3 -0
  13. data/gemfiles/Gemfile.rails-4.1.x +3 -0
  14. data/gemfiles/Gemfile.rails-4.2.x +3 -0
  15. data/lib/opbeat.rb +113 -93
  16. data/lib/opbeat/capistrano.rb +3 -4
  17. data/lib/opbeat/client.rb +243 -82
  18. data/lib/opbeat/configuration.rb +51 -64
  19. data/lib/opbeat/data_builders.rb +16 -0
  20. data/lib/opbeat/data_builders/error.rb +27 -0
  21. data/lib/opbeat/data_builders/transactions.rb +85 -0
  22. data/lib/opbeat/error.rb +1 -2
  23. data/lib/opbeat/error_message.rb +71 -0
  24. data/lib/opbeat/error_message/exception.rb +12 -0
  25. data/lib/opbeat/error_message/http.rb +62 -0
  26. data/lib/opbeat/error_message/stacktrace.rb +75 -0
  27. data/lib/opbeat/error_message/user.rb +23 -0
  28. data/lib/opbeat/filter.rb +53 -43
  29. data/lib/opbeat/http_client.rb +141 -0
  30. data/lib/opbeat/injections.rb +83 -0
  31. data/lib/opbeat/injections/json.rb +19 -0
  32. data/lib/opbeat/injections/net_http.rb +43 -0
  33. data/lib/opbeat/injections/redis.rb +23 -0
  34. data/lib/opbeat/injections/sequel.rb +32 -0
  35. data/lib/opbeat/injections/sinatra.rb +56 -0
  36. data/lib/opbeat/{capistrano → integration}/capistrano2.rb +6 -6
  37. data/lib/opbeat/{capistrano → integration}/capistrano3.rb +3 -3
  38. data/lib/opbeat/{integrations → integration}/delayed_job.rb +6 -11
  39. data/lib/opbeat/integration/rails/inject_exceptions_catcher.rb +23 -0
  40. data/lib/opbeat/integration/railtie.rb +53 -0
  41. data/lib/opbeat/integration/resque.rb +16 -0
  42. data/lib/opbeat/integration/sidekiq.rb +38 -0
  43. data/lib/opbeat/line_cache.rb +21 -0
  44. data/lib/opbeat/logging.rb +37 -0
  45. data/lib/opbeat/middleware.rb +59 -0
  46. data/lib/opbeat/normalizers.rb +65 -0
  47. data/lib/opbeat/normalizers/action_controller.rb +21 -0
  48. data/lib/opbeat/normalizers/action_view.rb +71 -0
  49. data/lib/opbeat/normalizers/active_record.rb +41 -0
  50. data/lib/opbeat/sql_summarizer.rb +27 -0
  51. data/lib/opbeat/subscriber.rb +80 -0
  52. data/lib/opbeat/tasks.rb +20 -18
  53. data/lib/opbeat/trace.rb +47 -0
  54. data/lib/opbeat/trace_helpers.rb +29 -0
  55. data/lib/opbeat/transaction.rb +99 -0
  56. data/lib/opbeat/util.rb +26 -0
  57. data/lib/opbeat/util/constantize.rb +54 -0
  58. data/lib/opbeat/util/inspector.rb +75 -0
  59. data/lib/opbeat/version.rb +1 -1
  60. data/lib/opbeat/worker.rb +55 -0
  61. data/opbeat.gemspec +6 -14
  62. data/spec/opbeat/client_spec.rb +216 -29
  63. data/spec/opbeat/configuration_spec.rb +34 -38
  64. data/spec/opbeat/data_builders/error_spec.rb +43 -0
  65. data/spec/opbeat/data_builders/transactions_spec.rb +51 -0
  66. data/spec/opbeat/error_message/exception_spec.rb +22 -0
  67. data/spec/opbeat/error_message/http_spec.rb +65 -0
  68. data/spec/opbeat/error_message/stacktrace_spec.rb +56 -0
  69. data/spec/opbeat/error_message/user_spec.rb +28 -0
  70. data/spec/opbeat/error_message_spec.rb +78 -0
  71. data/spec/opbeat/filter_spec.rb +21 -99
  72. data/spec/opbeat/http_client_spec.rb +64 -0
  73. data/spec/opbeat/injections/net_http_spec.rb +37 -0
  74. data/spec/opbeat/injections/sequel_spec.rb +33 -0
  75. data/spec/opbeat/injections/sinatra_spec.rb +13 -0
  76. data/spec/opbeat/injections_spec.rb +49 -0
  77. data/spec/opbeat/integration/delayed_job_spec.rb +35 -0
  78. data/spec/opbeat/integration/json_spec.rb +41 -0
  79. data/spec/opbeat/integration/rails_spec.rb +88 -0
  80. data/spec/opbeat/integration/redis_spec.rb +20 -0
  81. data/spec/opbeat/integration/resque_spec.rb +42 -0
  82. data/spec/opbeat/integration/sidekiq_spec.rb +40 -0
  83. data/spec/opbeat/integration/sinatra_spec.rb +66 -0
  84. data/spec/opbeat/line_cache_spec.rb +38 -0
  85. data/spec/opbeat/logging_spec.rb +47 -0
  86. data/spec/opbeat/middleware_spec.rb +32 -0
  87. data/spec/opbeat/normalizers/action_controller_spec.rb +32 -0
  88. data/spec/opbeat/normalizers/action_view_spec.rb +77 -0
  89. data/spec/opbeat/normalizers/active_record_spec.rb +70 -0
  90. data/spec/opbeat/normalizers_spec.rb +16 -0
  91. data/spec/opbeat/sql_summarizer_spec.rb +6 -0
  92. data/spec/opbeat/subscriber_spec.rb +83 -0
  93. data/spec/opbeat/trace_spec.rb +43 -0
  94. data/spec/opbeat/transaction_spec.rb +98 -0
  95. data/spec/opbeat/util/inspector_spec.rb +40 -0
  96. data/spec/opbeat/util_spec.rb +20 -0
  97. data/spec/opbeat/worker_spec.rb +54 -0
  98. data/spec/opbeat_spec.rb +49 -0
  99. data/spec/spec_helper.rb +79 -6
  100. metadata +89 -149
  101. data/Makefile +0 -3
  102. data/gemfiles/rails30.gemfile +0 -9
  103. data/gemfiles/rails31.gemfile +0 -9
  104. data/gemfiles/rails32.gemfile +0 -9
  105. data/gemfiles/rails40.gemfile +0 -9
  106. data/gemfiles/rails41.gemfile +0 -9
  107. data/gemfiles/rails42.gemfile +0 -9
  108. data/gemfiles/ruby192_rails31.gemfile +0 -10
  109. data/gemfiles/ruby192_rails32.gemfile +0 -10
  110. data/gemfiles/sidekiq31.gemfile +0 -11
  111. data/lib/opbeat/better_attr_accessor.rb +0 -44
  112. data/lib/opbeat/event.rb +0 -223
  113. data/lib/opbeat/integrations/resque.rb +0 -22
  114. data/lib/opbeat/integrations/sidekiq.rb +0 -32
  115. data/lib/opbeat/interfaces.rb +0 -35
  116. data/lib/opbeat/interfaces/exception.rb +0 -16
  117. data/lib/opbeat/interfaces/http.rb +0 -57
  118. data/lib/opbeat/interfaces/message.rb +0 -19
  119. data/lib/opbeat/interfaces/stack_trace.rb +0 -50
  120. data/lib/opbeat/linecache.rb +0 -25
  121. data/lib/opbeat/logger.rb +0 -21
  122. data/lib/opbeat/rack.rb +0 -46
  123. data/lib/opbeat/rails/middleware/debug_exceptions_catcher.rb +0 -22
  124. data/lib/opbeat/railtie.rb +0 -26
  125. data/spec/opbeat/better_attr_accessor_spec.rb +0 -99
  126. data/spec/opbeat/event_spec.rb +0 -138
  127. data/spec/opbeat/integrations/delayed_job_spec.rb +0 -38
  128. data/spec/opbeat/logger_spec.rb +0 -55
  129. data/spec/opbeat/opbeat_spec.rb +0 -64
  130. data/spec/opbeat/rack_spec.rb +0 -117
@@ -1,38 +0,0 @@
1
- require File::expand_path('../../../spec_helper', __FILE__)
2
- require 'time'
3
- require 'delayed_job'
4
- require 'opbeat/integrations/delayed_job'
5
-
6
- # turtles, all the way down
7
- # trying too hard
8
- require 'active_support/core_ext/time/calculations.rb'
9
- load File.join(
10
- Gem::Specification.find_by_name("delayed_job").gem_dir,
11
- "spec", "delayed", "backend", "test.rb"
12
- )
13
-
14
-
15
- class Bomb
16
- def blow_up ex
17
- raise ex
18
- end
19
- end
20
-
21
-
22
- Delayed::Worker.backend = Delayed::Backend::Test::Job
23
-
24
- describe Delayed::Plugins::Opbeat do
25
- it 'should call Opbeat::capture_exception on erronous jobs' do
26
- test_exception = Exception.new("Test exception")
27
- expect(Opbeat).to receive(:capture_exception).with(test_exception)
28
-
29
- # Queue
30
- bomb = Bomb.new
31
- bomb.delay.blow_up test_exception
32
-
33
- expect {
34
- Delayed::Worker.new.work_off.should == [0, 1]
35
- }.to raise_error(Exception)
36
- end
37
- end
38
-
@@ -1,55 +0,0 @@
1
- require File::expand_path('../../spec_helper', __FILE__)
2
- require 'opbeat'
3
-
4
- describe Opbeat::Logger do
5
- context 'without a backend logger' do
6
- before do
7
- allow(Opbeat.configuration).to receive(:logger) { nil }
8
- end
9
-
10
- it 'should not error' do
11
- subject.fatal 'fatalmsg'
12
- subject.error 'errormsg'
13
- subject.warn 'warnmsg'
14
- subject.info 'infomsg'
15
- subject.debug 'debugmsg'
16
- end
17
- end
18
-
19
- context 'with a backend logger' do
20
- before do
21
- @logger = double('logger')
22
- allow(Opbeat.configuration).to receive(:logger) { @logger }
23
- end
24
-
25
- it 'should log fatal messages' do
26
- expect(@logger).to receive(:fatal).with('** [Opbeat] fatalmsg')
27
- subject.fatal 'fatalmsg'
28
- end
29
-
30
- it 'should log error messages' do
31
- expect(@logger).to receive(:error).with('** [Opbeat] errormsg')
32
- subject.error 'errormsg'
33
- end
34
-
35
- it 'should log warning messages' do
36
- expect(@logger).to receive(:warn).with('** [Opbeat] warnmsg')
37
- subject.warn 'warnmsg'
38
- end
39
-
40
- it 'should log info messages' do
41
- expect(@logger).to receive(:info).with('** [Opbeat] infomsg')
42
- subject.info 'infomsg'
43
- end
44
-
45
- it 'should log debug messages' do
46
- expect(@logger).to receive(:debug).with('** [Opbeat] debugmsg')
47
- subject.debug 'debugmsg'
48
- end
49
-
50
- it 'should log messages from blocks' do
51
- expect(@logger).to receive(:info).with('** [Opbeat] infoblock')
52
- subject.info { 'infoblock' }
53
- end
54
- end
55
- end
@@ -1,64 +0,0 @@
1
- require File::expand_path('../../spec_helper', __FILE__)
2
- require 'opbeat'
3
-
4
- describe Opbeat do
5
- before do
6
- @send = double("send")
7
- @event = double("event")
8
- allow(Opbeat).to receive(:send) { @send }
9
- allow(Opbeat::Event).to receive(:from_message) { @event }
10
- allow(Opbeat::Event).to receive(:from_exception) { @event }
11
- end
12
-
13
- it 'capture_message should send result of Event.from_message' do
14
- message = "Test message"
15
- expect(Opbeat::Event).to receive(:from_message).with(message, an_instance_of(Array), {})
16
- expect(Opbeat).to receive(:send).with(@event)
17
-
18
- Opbeat.capture_message(message)
19
- end
20
-
21
- it 'capture_message with options should send result of Event.from_message' do
22
- message = "Test message"
23
- options = {:extra => {:hello => "world"}}
24
- expect(Opbeat::Event).to receive(:from_message).with(message, an_instance_of(Array), options)
25
- expect(Opbeat).to receive(:send).with(@event)
26
-
27
- Opbeat.capture_message(message, options)
28
- end
29
-
30
- it 'capture_exception should send result of Event.from_exception' do
31
- exception = build_exception()
32
-
33
- expect(Opbeat::Event).to receive(:from_exception).with(exception, {})
34
- expect(Opbeat).to receive(:send).with(@event)
35
-
36
- Opbeat.capture_exception(exception)
37
- end
38
-
39
- context "async" do
40
- it 'capture_message should send result of Event.from_message' do
41
- async = lambda {}
42
- message = "Test message"
43
-
44
- expect(Opbeat::Event).to receive(:from_message).with(message, an_instance_of(Array), {})
45
- expect(Opbeat).to_not receive(:send)
46
- expect(async).to receive(:call).with(@event)
47
-
48
- Opbeat.configuration.async = async
49
- Opbeat.capture_message(message)
50
- end
51
-
52
- it 'capture_exception should send result of Event.from_exception' do
53
- async = lambda {}
54
- exception = build_exception()
55
-
56
- expect(Opbeat::Event).to receive(:from_exception).with(exception, {})
57
- expect(Opbeat).to_not receive(:send)
58
- expect(async).to receive(:call).with(@event)
59
-
60
- Opbeat.configuration.async = async
61
- Opbeat.capture_exception(exception)
62
- end
63
- end
64
- end
@@ -1,117 +0,0 @@
1
- require File::expand_path('../../spec_helper', __FILE__)
2
-
3
- require 'opbeat'
4
- require 'opbeat/interfaces'
5
-
6
- class User
7
- attr_accessor :id, :email, :username
8
- end
9
-
10
-
11
- class TestController
12
- def current_user
13
- test_user = User.new
14
- test_user.id = 99
15
- test_user.email = "ron@opbeat.com"
16
- test_user.username = "roncohen"
17
-
18
- return test_user
19
- end
20
-
21
- def custom_user
22
- test_user = User.new
23
- test_user.id = 999
24
- test_user.email = "custom@opbeat.com"
25
- test_user.username = "custom"
26
-
27
- return test_user
28
- end
29
- end
30
-
31
-
32
-
33
- describe Opbeat::Rack do
34
- before do
35
- @send = double("send")
36
- @event = double("event")
37
- allow(Opbeat).to receive(:send) { @send }
38
- allow(Opbeat::Event).to receive(:from_rack_exception) { @event }
39
- end
40
-
41
- it 'should capture exceptions' do
42
- exception = build_exception()
43
- env = {}
44
-
45
- expect(Opbeat::Event).to receive(:from_rack_exception).with(exception, env)
46
- expect(Opbeat).to receive(:send).with(@event)
47
-
48
- app = lambda do |e|
49
- raise exception
50
- end
51
-
52
- stack = Opbeat::Rack.new(app)
53
- expect(lambda {stack.call(env)}).to raise_error(exception)
54
- end
55
-
56
- it 'should capture rack.exception' do
57
- exception = build_exception()
58
- env = {}
59
-
60
- expect(Opbeat::Event).to receive(:from_rack_exception).with(exception, env)
61
- expect(Opbeat).to receive(:send).with(@event)
62
-
63
- app = lambda do |e|
64
- e['rack.exception'] = exception
65
- [200, {}, ['okay']]
66
- end
67
-
68
- stack = Opbeat::Rack.new(app)
69
-
70
- stack.call(env)
71
- end
72
- end
73
-
74
-
75
- describe Opbeat::Rack do
76
- before do
77
- @exception = build_exception()
78
- @env = {
79
- 'action_controller.instance' => TestController.new
80
- }
81
- allow(Opbeat::HttpInterface).to receive(:new) { Opbeat::Interface.new }
82
- end
83
-
84
- it 'should extract user info' do
85
- expected_user = TestController.new.current_user
86
-
87
- Opbeat::Event.from_rack_exception(@exception, @env) do |event|
88
- user = event.to_hash['user']
89
- expect(user[:id]).to eq(expected_user.id)
90
- expect(user[:email]).to eq(expected_user.email)
91
- expect(user[:username]).to eq(expected_user.username)
92
- expect(user[:is_authenticated]).to eq(true)
93
- end
94
- end
95
-
96
- it 'should handle custom user method' do
97
- Opbeat.configuration.user_controller_method = :custom_user
98
- expected_user = TestController.new.custom_user
99
-
100
- Opbeat::Event.from_rack_exception(@exception, @env) do |event|
101
- user = event.to_hash['user']
102
- expect(user[:id]).to eq(expected_user.id)
103
- expect(user[:email]).to eq(expected_user.email)
104
- expect(user[:username]).to eq(expected_user.username)
105
- expect(user[:is_authenticated]).to eq(true)
106
- end
107
- end
108
-
109
- it 'should handle missing user method' do
110
- Opbeat.configuration.user_controller_method = :missing_user_method
111
- expected_user = TestController.new.custom_user
112
-
113
- Opbeat::Event.from_rack_exception(@exception, @env) do |event|
114
- expect(event.user).to eq(nil)
115
- end
116
- end
117
- end