kuende-opbeat 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/.travis.yml +36 -0
- data/Gemfile +2 -0
- data/LICENSE +205 -0
- data/Makefile +3 -0
- data/README.md +267 -0
- data/Rakefile +19 -0
- data/gemfiles/rails30.gemfile +9 -0
- data/gemfiles/rails31.gemfile +9 -0
- data/gemfiles/rails32.gemfile +9 -0
- data/gemfiles/rails40.gemfile +9 -0
- data/gemfiles/rails41.gemfile +9 -0
- data/gemfiles/rails42.gemfile +9 -0
- data/gemfiles/ruby192_rails31.gemfile +10 -0
- data/gemfiles/ruby192_rails32.gemfile +10 -0
- data/gemfiles/sidekiq31.gemfile +11 -0
- data/lib/opbeat.rb +132 -0
- data/lib/opbeat/better_attr_accessor.rb +44 -0
- data/lib/opbeat/capistrano.rb +9 -0
- data/lib/opbeat/capistrano/capistrano2.rb +47 -0
- data/lib/opbeat/capistrano/capistrano3.rb +26 -0
- data/lib/opbeat/client.rb +122 -0
- data/lib/opbeat/configuration.rb +90 -0
- data/lib/opbeat/error.rb +6 -0
- data/lib/opbeat/event.rb +223 -0
- data/lib/opbeat/filter.rb +63 -0
- data/lib/opbeat/integrations/delayed_job.rb +32 -0
- data/lib/opbeat/integrations/resque.rb +22 -0
- data/lib/opbeat/integrations/sidekiq.rb +32 -0
- data/lib/opbeat/interfaces.rb +35 -0
- data/lib/opbeat/interfaces/exception.rb +16 -0
- data/lib/opbeat/interfaces/http.rb +57 -0
- data/lib/opbeat/interfaces/message.rb +19 -0
- data/lib/opbeat/interfaces/stack_trace.rb +50 -0
- data/lib/opbeat/linecache.rb +25 -0
- data/lib/opbeat/logger.rb +21 -0
- data/lib/opbeat/rack.rb +44 -0
- data/lib/opbeat/rails/middleware/debug_exceptions_catcher.rb +22 -0
- data/lib/opbeat/railtie.rb +26 -0
- data/lib/opbeat/tasks.rb +24 -0
- data/lib/opbeat/version.rb +3 -0
- data/opbeat.gemspec +28 -0
- data/spec/opbeat/better_attr_accessor_spec.rb +99 -0
- data/spec/opbeat/client_spec.rb +35 -0
- data/spec/opbeat/configuration_spec.rb +50 -0
- data/spec/opbeat/event_spec.rb +138 -0
- data/spec/opbeat/filter_spec.rb +101 -0
- data/spec/opbeat/integrations/delayed_job_spec.rb +38 -0
- data/spec/opbeat/logger_spec.rb +55 -0
- data/spec/opbeat/opbeat_spec.rb +89 -0
- data/spec/opbeat/rack_spec.rb +116 -0
- data/spec/spec_helper.rb +22 -0
- metadata +218 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'opbeat/better_attr_accessor'
|
2
|
+
|
3
|
+
module Opbeat
|
4
|
+
|
5
|
+
INTERFACES = {}
|
6
|
+
|
7
|
+
class Interface
|
8
|
+
include BetterAttrAccessor
|
9
|
+
alias_method :to_hash, :attributes
|
10
|
+
|
11
|
+
def initialize(attributes = nil)
|
12
|
+
attributes.each do |attr, value|
|
13
|
+
send "#{attr}=", value
|
14
|
+
end if attributes
|
15
|
+
|
16
|
+
yield self if block_given?
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.name(value = nil)
|
20
|
+
@interface_name ||= value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.register_interface(mapping)
|
25
|
+
mapping.each_pair do |key, klass|
|
26
|
+
INTERFACES[key.to_s] = klass
|
27
|
+
INTERFACES[klass.name] = klass
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.find_interface(name)
|
32
|
+
INTERFACES[name.to_s]
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'opbeat/interfaces'
|
2
|
+
|
3
|
+
module Opbeat
|
4
|
+
|
5
|
+
class ExceptionInterface < Interface
|
6
|
+
|
7
|
+
name 'exception'
|
8
|
+
attr_accessor :type
|
9
|
+
attr_accessor :value
|
10
|
+
attr_accessor :module
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
register_interface :exception => ExceptionInterface
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'opbeat/interfaces'
|
2
|
+
|
3
|
+
module Opbeat
|
4
|
+
|
5
|
+
class HttpInterface < Interface
|
6
|
+
|
7
|
+
name 'http'
|
8
|
+
attr_accessor :url
|
9
|
+
attr_accessor :method
|
10
|
+
attr_accessor :data
|
11
|
+
attr_accessor :query_string
|
12
|
+
attr_accessor :cookies
|
13
|
+
attr_accessor :headers
|
14
|
+
attr_accessor :remote_host
|
15
|
+
attr_accessor :http_host
|
16
|
+
attr_accessor :env
|
17
|
+
|
18
|
+
def initialize(*arguments)
|
19
|
+
self.headers = {}
|
20
|
+
self.env = {}
|
21
|
+
super(*arguments)
|
22
|
+
end
|
23
|
+
|
24
|
+
def from_rack(env)
|
25
|
+
require 'rack'
|
26
|
+
req = ::Rack::Request.new(env)
|
27
|
+
self.url = req.url.split('?').first
|
28
|
+
self.method = req.request_method
|
29
|
+
self.query_string = req.query_string
|
30
|
+
self.cookies = req.cookies.collect {|k,v| "#{k}=#{v}"}.join(';')
|
31
|
+
self.remote_host = req.ip
|
32
|
+
self.http_host = req.host_with_port
|
33
|
+
env.each_pair do |key, value|
|
34
|
+
next unless key.upcase == key # Non-upper case stuff isn't either
|
35
|
+
if key.start_with?('HTTP_')
|
36
|
+
# Header
|
37
|
+
http_key = key[5..key.length-1].split('_').map{|s| s.capitalize}.join('-')
|
38
|
+
self.headers[http_key] = value.to_s
|
39
|
+
else
|
40
|
+
# Environment
|
41
|
+
self.env[key] = value.to_s
|
42
|
+
end
|
43
|
+
end
|
44
|
+
self.data = if req.form_data?
|
45
|
+
req.POST
|
46
|
+
elsif req.body
|
47
|
+
data = req.body.read
|
48
|
+
req.body.rewind
|
49
|
+
data
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
register_interface :http => HttpInterface
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'opbeat/interfaces'
|
2
|
+
|
3
|
+
module Opbeat
|
4
|
+
|
5
|
+
class MessageInterface < Interface
|
6
|
+
|
7
|
+
name 'param_message'
|
8
|
+
attr_accessor :message
|
9
|
+
attr_accessor :params
|
10
|
+
|
11
|
+
def initialize(*arguments)
|
12
|
+
self.params = []
|
13
|
+
super(*arguments)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
register_interface :message => MessageInterface
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'opbeat/interfaces'
|
2
|
+
|
3
|
+
module Opbeat
|
4
|
+
|
5
|
+
class StacktraceInterface < Interface
|
6
|
+
|
7
|
+
name 'stacktrace'
|
8
|
+
attr_accessor :frames, :default => []
|
9
|
+
|
10
|
+
def initialize(*arguments)
|
11
|
+
self.frames = []
|
12
|
+
super(*arguments)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_hash
|
16
|
+
data = super
|
17
|
+
data['frames'] = data['frames'].map{|frame| frame.to_hash}
|
18
|
+
data
|
19
|
+
end
|
20
|
+
|
21
|
+
def frame(attributes=nil, &block)
|
22
|
+
Frame.new(attributes, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Not actually an interface, but I want to use the same style
|
26
|
+
class Frame < Interface
|
27
|
+
attr_accessor :abs_path
|
28
|
+
attr_accessor :filename
|
29
|
+
attr_accessor :function
|
30
|
+
attr_accessor :vars, :default => {}
|
31
|
+
attr_accessor :pre_context, :default => []
|
32
|
+
attr_accessor :post_context, :default => []
|
33
|
+
attr_accessor :context_line
|
34
|
+
attr_accessor :lineno
|
35
|
+
|
36
|
+
def to_hash
|
37
|
+
data = super
|
38
|
+
data.delete('vars') unless self.vars && !self.vars.empty?
|
39
|
+
data.delete('pre_context') unless self.pre_context && !self.pre_context.empty?
|
40
|
+
data.delete('post_context') unless self.post_context && !self.post_context.empty?
|
41
|
+
data.delete('context_line') unless self.context_line && !self.context_line.empty?
|
42
|
+
data
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
register_interface :stack_trace => StacktraceInterface
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# A much simpler source line cacher because linecache sucks at platform compat
|
2
|
+
|
3
|
+
module Opbeat
|
4
|
+
|
5
|
+
class LineCache
|
6
|
+
class << self
|
7
|
+
CACHE = {}
|
8
|
+
|
9
|
+
def getlines(path)
|
10
|
+
CACHE[path] ||= begin
|
11
|
+
IO.readlines(path)
|
12
|
+
rescue
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def getline(path, n)
|
18
|
+
return nil if n < 1
|
19
|
+
getlines(path)[n-1]
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Opbeat
|
2
|
+
class Logger
|
3
|
+
LOG_PREFIX = "** [Opbeat] "
|
4
|
+
|
5
|
+
[
|
6
|
+
:fatal,
|
7
|
+
:error,
|
8
|
+
:warn,
|
9
|
+
:info,
|
10
|
+
:debug,
|
11
|
+
].each do |level|
|
12
|
+
define_method level do |*args, &block|
|
13
|
+
msg = args[0] # Block-level default args is a 1.9 feature
|
14
|
+
msg ||= block.call if block
|
15
|
+
logger = Opbeat.configuration[:logger]
|
16
|
+
logger.send(level, "#{LOG_PREFIX}#{msg}") if logger
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/opbeat/rack.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Opbeat
|
2
|
+
# Middleware for Rack applications. Any errors raised by the upstream
|
3
|
+
# application will be delivered to Opbeat and re-raised.
|
4
|
+
#
|
5
|
+
# Synopsis:
|
6
|
+
#
|
7
|
+
# require 'rack'
|
8
|
+
# require 'opbeat'
|
9
|
+
#
|
10
|
+
# Opbeat.configure do |config|
|
11
|
+
# config.server = 'http://my_dsn'
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# app = Rack::Builder.app do
|
15
|
+
# use Opbeat::Rack
|
16
|
+
# run lambda { |env| raise "Rack down" }
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# Use a standard Opbeat.configure call to configure your server credentials.
|
20
|
+
class Rack
|
21
|
+
def initialize(app)
|
22
|
+
@app = app
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
begin
|
27
|
+
response = @app.call(env)
|
28
|
+
rescue Error => e
|
29
|
+
raise # Don't capture Opbeat errors
|
30
|
+
rescue Exception => e
|
31
|
+
Opbeat.capture_rack_exception(e, env)
|
32
|
+
raise
|
33
|
+
end
|
34
|
+
|
35
|
+
error = env['rack.exception'] || env['sinatra.error']
|
36
|
+
|
37
|
+
if error
|
38
|
+
Opbeat.capture_rack_exception(error, env)
|
39
|
+
end
|
40
|
+
|
41
|
+
response
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Opbeat
|
2
|
+
module Rails
|
3
|
+
module Middleware
|
4
|
+
module DebugExceptionsCatcher
|
5
|
+
def self.included(base)
|
6
|
+
base.send(:alias_method_chain, :render_exception, :opbeat)
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_exception_with_opbeat(env, exception)
|
10
|
+
begin
|
11
|
+
evt = Opbeat::Event.from_rack_exception(exception, env)
|
12
|
+
Opbeat.send(evt) if evt
|
13
|
+
rescue
|
14
|
+
::Rails::logger.debug "Error capturing or sending exception #{$!}"
|
15
|
+
end
|
16
|
+
|
17
|
+
render_exception_without_opbeat(env, exception)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'opbeat'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module Opbeat
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
initializer "opbeat.use_rack_middleware" do |app|
|
7
|
+
app.config.middleware.insert 0, "Opbeat::Rack"
|
8
|
+
end
|
9
|
+
config.after_initialize do
|
10
|
+
Opbeat.configure(true) do |config|
|
11
|
+
config.logger ||= ::Rails.logger
|
12
|
+
end
|
13
|
+
|
14
|
+
if defined?(::ActionDispatch::DebugExceptions)
|
15
|
+
require 'opbeat/rails/middleware/debug_exceptions_catcher'
|
16
|
+
::ActionDispatch::DebugExceptions.send(:include, Opbeat::Rails::Middleware::DebugExceptionsCatcher)
|
17
|
+
elsif defined?(::ActionDispatch::ShowExceptions)
|
18
|
+
require 'opbeat/rails/middleware/debug_exceptions_catcher'
|
19
|
+
::ActionDispatch::ShowExceptions.send(:include, Opbeat::Rails::Middleware::DebugExceptionsCatcher)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
rake_tasks do
|
23
|
+
require 'opbeat/tasks'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/opbeat/tasks.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Capistrano tasks for notifying Opbeat of deploys
|
2
|
+
namespace :opbeat do
|
3
|
+
desc "Notify Opbeat of a new deploy."
|
4
|
+
task :deployment do
|
5
|
+
if defined?(::Rails.root)
|
6
|
+
initializer_file = ::Rails.root.join('config', 'initializers','opbeat.rb')
|
7
|
+
|
8
|
+
if initializer_file.exist?
|
9
|
+
load initializer_file
|
10
|
+
else
|
11
|
+
Rake::Task[:environment].invoke
|
12
|
+
end
|
13
|
+
end
|
14
|
+
rev = ENV['REV']
|
15
|
+
|
16
|
+
unless rev
|
17
|
+
puts "No revision given. Set environment variable REV."
|
18
|
+
else
|
19
|
+
data = {'rev' => ENV['REV'], 'branch' => ENV['BRANCH'], 'status' => 'completed'}
|
20
|
+
Opbeat::client.send_release(data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/opbeat.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'opbeat/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "kuende-opbeat"
|
8
|
+
gem.version = Opbeat::VERSION
|
9
|
+
gem.authors = ["Thomas Watson Steen", "Ron Cohen", "Noah Kantrowitz"]
|
10
|
+
gem.email = "support@opbeat.com"
|
11
|
+
gem.summary = "The official Opbeat Ruby client"
|
12
|
+
gem.homepage = "https://github.com/kuende/opbeat_ruby"
|
13
|
+
gem.license = "Apache-2.0"
|
14
|
+
|
15
|
+
gem.files = `git ls-files -z`.split("\x0")
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.extra_rdoc_files = ["README.md", "LICENSE"]
|
18
|
+
|
19
|
+
gem.add_dependency "faraday", [">= 0.7.6", "< 0.10"]
|
20
|
+
gem.add_dependency "multi_json", "~> 1.12.1"
|
21
|
+
|
22
|
+
gem.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
gem.add_development_dependency "rake", "~> 10.0"
|
24
|
+
gem.add_development_dependency "rspec", ">= 2.14"
|
25
|
+
gem.add_development_dependency "simplecov"
|
26
|
+
gem.add_development_dependency "delayed_job"
|
27
|
+
gem.add_development_dependency "sidekiq", "~> 2.17.0"
|
28
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require File::expand_path('../../spec_helper', __FILE__)
|
2
|
+
require 'opbeat'
|
3
|
+
|
4
|
+
describe Opbeat::BetterAttrAccessor do
|
5
|
+
|
6
|
+
let :klass do
|
7
|
+
Class.new do
|
8
|
+
include Opbeat::BetterAttrAccessor
|
9
|
+
|
10
|
+
attr_accessor :a
|
11
|
+
attr_accessor :b, :default => []
|
12
|
+
attr_accessor :c
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
let :child do
|
17
|
+
Class.new klass do
|
18
|
+
attr_accessor :d
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
subject{ klass.new }
|
23
|
+
|
24
|
+
describe 'the reader method' do
|
25
|
+
context 'when a value is not set' do
|
26
|
+
it 'should default to nil' do
|
27
|
+
expect(subject.a).to eq nil
|
28
|
+
end
|
29
|
+
it 'should use a default value if provided' do
|
30
|
+
expect(subject.b).to eq []
|
31
|
+
expect(subject.instance_variable_get '@b').to eq []
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when a value is set' do
|
36
|
+
before do
|
37
|
+
subject.a = 'foo'
|
38
|
+
subject.b = :bar
|
39
|
+
subject.c = false
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should save the value' do
|
43
|
+
expect(subject.a).to eq 'foo'
|
44
|
+
end
|
45
|
+
it 'should save a boolean `false` value' do
|
46
|
+
expect(subject.c).to eq false
|
47
|
+
end
|
48
|
+
it 'should no longer return the default' do
|
49
|
+
expect(subject.b).to eq :bar
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when a default value is directly modified' do
|
54
|
+
before { subject.b << 9 }
|
55
|
+
it 'should not affect a new instance' do
|
56
|
+
expect(klass.new.b).to eq []
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '.attributes' do
|
62
|
+
it 'should be a Set of all attributes set up' do
|
63
|
+
expect(klass.attributes).to be_a Set
|
64
|
+
expect(klass.attributes).to eq %w[a b c].to_set
|
65
|
+
end
|
66
|
+
it 'should work with inheritance' do
|
67
|
+
expect(child.attributes).to eq %w[d a b c].to_set
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#attributes' do
|
72
|
+
it 'should return a hash of all attributes' do
|
73
|
+
subject.a = {'foo' => :bar}
|
74
|
+
subject.b << 8
|
75
|
+
expect(subject.attributes).to eq \
|
76
|
+
'a' => {'foo' => :bar},
|
77
|
+
'b' => [8],
|
78
|
+
'c' => nil
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'inheritance' do
|
82
|
+
subject{ child.new }
|
83
|
+
|
84
|
+
before do
|
85
|
+
subject.a = 21
|
86
|
+
subject.d = true
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should work' do
|
90
|
+
expect(subject.attributes).to eq \
|
91
|
+
'a' => 21,
|
92
|
+
'b' => [],
|
93
|
+
'c' => nil,
|
94
|
+
'd' => true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|