errplane 0.0.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.
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +11 -0
- data/README.md +6 -0
- data/Rakefile +1 -0
- data/config.ru +7 -0
- data/errplane.gemspec +23 -0
- data/lib/errplane.rb +57 -0
- data/lib/errplane/black_box.rb +17 -0
- data/lib/errplane/configuration.rb +11 -0
- data/lib/errplane/rack.rb +18 -0
- data/lib/errplane/rails/middleware/hijack_render_exception.rb +17 -0
- data/lib/errplane/railtie.rb +30 -0
- data/lib/errplane/transmitter.rb +33 -0
- data/lib/errplane/version.rb +3 -0
- data/lib/rails/generators/errplane/errplane_generator.rb +23 -0
- data/lib/rails/generators/errplane/templates/initializer.rb +4 -0
- data/spec/controllers/widgets_controller_spec.rb +15 -0
- data/spec/integration/exceptions_spec.rb +21 -0
- data/spec/integration/integration_helper.rb +1 -0
- data/spec/internal/app/controllers/application_controller.rb +2 -0
- data/spec/internal/app/controllers/widgets_controller.rb +9 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/initializers/errplane.rb +4 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +3 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/unit/black_box_spec.rb +34 -0
- metadata +90 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3-p125@errplane_rails --create
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/config.ru
ADDED
data/errplane.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "errplane/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "errplane"
|
7
|
+
s.version = Errplane::VERSION
|
8
|
+
s.authors = ["Todd Persen"]
|
9
|
+
s.email = ["todd@errplane.com"]
|
10
|
+
s.homepage = "http://errplane.com"
|
11
|
+
s.summary = %q{Rails exception reporting for Errplane.}
|
12
|
+
s.description = %q{This gem provides exception reporting with Errplane for Rails 3.x applications.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "errplane"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# s.add_development_dependency "combustion"
|
22
|
+
# s.add_runtime_dependency "rest-client"
|
23
|
+
end
|
data/lib/errplane.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'active_support'
|
7
|
+
require 'active_support/core_ext'
|
8
|
+
rescue LoadError
|
9
|
+
require 'activesupport'
|
10
|
+
require 'activesupport/core_ext'
|
11
|
+
end
|
12
|
+
|
13
|
+
require "errplane/version"
|
14
|
+
require "errplane/black_box"
|
15
|
+
require "errplane/configuration"
|
16
|
+
require "errplane/transmitter"
|
17
|
+
require "errplane/rack"
|
18
|
+
|
19
|
+
require "errplane/railtie" #if defined?(Rails)
|
20
|
+
|
21
|
+
module Errplane
|
22
|
+
API_HOST = "api.errplane.com"
|
23
|
+
|
24
|
+
class << self
|
25
|
+
attr_writer :configuration
|
26
|
+
attr_accessor :transmitter
|
27
|
+
|
28
|
+
def configure(silent = false)
|
29
|
+
yield(configuration)
|
30
|
+
self.transmitter = Transmitter.new(configuration)
|
31
|
+
end
|
32
|
+
|
33
|
+
def configuration
|
34
|
+
@configuration ||= Configuration.new
|
35
|
+
end
|
36
|
+
|
37
|
+
def transmit_to_api(exception)
|
38
|
+
transmitter.relay(assemble_black_box_for(exception))
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def assemble_black_box_for(exception, options = {})
|
43
|
+
exception = unwrap_exception(exception)
|
44
|
+
black_box = BlackBox.new(exception: exception)
|
45
|
+
end
|
46
|
+
|
47
|
+
def unwrap_exception(exception)
|
48
|
+
if exception.respond_to?(:original_exception)
|
49
|
+
exception.original_exception
|
50
|
+
elsif exception.respond_to?(:continued_exception)
|
51
|
+
exception.continued_exception
|
52
|
+
else
|
53
|
+
exception
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Errplane
|
2
|
+
class BlackBox
|
3
|
+
attr_reader :exception
|
4
|
+
|
5
|
+
def initialize(params = {})
|
6
|
+
@exception = params[:exception]
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_json
|
10
|
+
{
|
11
|
+
:time => Time.now.to_i,
|
12
|
+
:message => @exception.message,
|
13
|
+
:backtrace => @exception.backtrace
|
14
|
+
}.to_json
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Errplane
|
2
|
+
module Rails
|
3
|
+
module Middleware
|
4
|
+
module HijackRenderException
|
5
|
+
def self.included(base)
|
6
|
+
base.send(:alias_method_chain,:render_exception,:errplane)
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_exception_with_errplane(env,exception)
|
10
|
+
Errplane.transmit_to_api(exception)
|
11
|
+
render_exception_without_errplane(env,exception)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'errplane'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module Errplane
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
rake_tasks do
|
7
|
+
end
|
8
|
+
|
9
|
+
initializer "errplane.insert_rack_middleware" do |app|
|
10
|
+
app.config.middleware.insert 0, Errplane::Rack
|
11
|
+
end
|
12
|
+
|
13
|
+
config.after_initialize do
|
14
|
+
Errplane.configure(true) do |config|
|
15
|
+
config.logger ||= ::Rails.logger
|
16
|
+
config.environment_name ||= ::Rails.env
|
17
|
+
config.project_root ||= ::Rails.root
|
18
|
+
config.framework = "Rails: #{::Rails::VERSION::STRING}"
|
19
|
+
end
|
20
|
+
|
21
|
+
if defined?(::ActionDispatch::DebugExceptions)
|
22
|
+
require 'errplane/rails/middleware/hijack_render_exception'
|
23
|
+
::ActionDispatch::DebugExceptions.send(:include,Errplane::Rails::Middleware::HijackRenderException)
|
24
|
+
elsif defined?(::ActionDispatch::ShowExceptions)
|
25
|
+
require 'errplane/rails/middleware/hijack_render_exception'
|
26
|
+
::ActionDispatch::ShowExceptions.send(:include,Errplane::Rails::Middleware::HijackRenderException)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Errplane
|
2
|
+
class Transmitter
|
3
|
+
def initialize(params = {})
|
4
|
+
end
|
5
|
+
|
6
|
+
def relay(black_box)
|
7
|
+
http = initialize_http_connection
|
8
|
+
data = black_box.to_json
|
9
|
+
response = begin
|
10
|
+
url = "/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/#{Errplane.configuration.environment_name}?api_key=#{Errplane.configuration.api_key}"
|
11
|
+
::Rails.logger.info(url)
|
12
|
+
http.post("/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/#{Errplane.configuration.environment_name}?api_key=#{Errplane.configuration.api_key}", data)
|
13
|
+
rescue Exception => e
|
14
|
+
e
|
15
|
+
end
|
16
|
+
::Rails.logger.info("Exception Data: #{data}")
|
17
|
+
::Rails.logger.info("Exception Body: #{response.body}")
|
18
|
+
::Rails.logger.info("Exception Response: #{response.inspect}")
|
19
|
+
|
20
|
+
case response
|
21
|
+
when Net::HTTPSuccess
|
22
|
+
# Success
|
23
|
+
else
|
24
|
+
# Failure
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def initialize_http_connection
|
30
|
+
connection = Net::HTTP.new(API_HOST, "80")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
class ErrplaneGenerator < Rails::Generators::Base
|
4
|
+
desc "Description:\n This creates a Rails initializer for Errplane."
|
5
|
+
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
argument :api_key,
|
8
|
+
required: false,
|
9
|
+
type: :string,
|
10
|
+
description: "API Key for your Errplane Organization"
|
11
|
+
argument :application_id,
|
12
|
+
required: false,
|
13
|
+
default: lambda { Time.now.to_s },
|
14
|
+
type: :string,
|
15
|
+
description: "API Key for your Errplane Organization"
|
16
|
+
|
17
|
+
def copy_initializer_file
|
18
|
+
template "initializer.rb", "config/initializers/errplane.rb"
|
19
|
+
end
|
20
|
+
|
21
|
+
def install
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WidgetsController do
|
4
|
+
describe "#new" do
|
5
|
+
it "should raise an exception" do
|
6
|
+
expect { get :new }.to raise_error(ZeroDivisionError)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#index" do
|
11
|
+
it "should not raise an exception" do
|
12
|
+
expect { get :index }.to_not raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/integration_helper"
|
2
|
+
|
3
|
+
feature "exception handling" do
|
4
|
+
describe "in an action that raises an exception" do
|
5
|
+
scenario "should make an HTTP call to the API" do
|
6
|
+
stub_request(:post, "#{Errplane::API_HOST}/exceptions").to_return(status: 200)
|
7
|
+
|
8
|
+
lambda { visit new_widget_path }.should raise_error
|
9
|
+
|
10
|
+
assert_requested :post, "#{Errplane::API_HOST}/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/test?api_key=f123-e456-d789c012"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "in an action that does not raise an exception" do
|
15
|
+
scenario "should not make an HTTP call to the API" do
|
16
|
+
lambda { visit widgets_path }.should_not raise_error
|
17
|
+
|
18
|
+
assert_not_requested :post, "#{Errplane::API_HOST}/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/test?api_key=f123-e456-d789c012"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
*.log
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
Bundler.require :default, :development
|
5
|
+
|
6
|
+
require 'capybara/rspec'
|
7
|
+
require 'webmock/rspec'
|
8
|
+
|
9
|
+
Combustion.initialize!
|
10
|
+
|
11
|
+
require 'rspec/rails'
|
12
|
+
require 'capybara/rails'
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.use_transactional_fixtures = true
|
16
|
+
end
|
17
|
+
|
18
|
+
class Combustion::Application < Rails::Application
|
19
|
+
config.action_dispatch.show_exceptions = false
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Errplane::BlackBox do
|
4
|
+
before do
|
5
|
+
begin
|
6
|
+
1/0
|
7
|
+
rescue Exception => e
|
8
|
+
@exception = e
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".new" do
|
13
|
+
it "should create a new BlackBox" do
|
14
|
+
black_box = Errplane::BlackBox.new
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should accept an exception as a parameter" do
|
18
|
+
|
19
|
+
black_box = Errplane::BlackBox.new(exception: @exception)
|
20
|
+
black_box.should_not be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#to_json" do
|
25
|
+
it "should return a JSON string" do
|
26
|
+
black_box = Errplane::BlackBox.new(exception: @exception)
|
27
|
+
json = JSON.parse(black_box.to_json)
|
28
|
+
|
29
|
+
json["message"].should == "divided by 0"
|
30
|
+
json["time"].should_not be_nil
|
31
|
+
json["backtrace"].should_not be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: errplane
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Todd Persen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-08 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: This gem provides exception reporting with Errplane for Rails 3.x applications.
|
15
|
+
email:
|
16
|
+
- todd@errplane.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rvmrc
|
23
|
+
- Gemfile
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- config.ru
|
27
|
+
- errplane.gemspec
|
28
|
+
- lib/errplane.rb
|
29
|
+
- lib/errplane/black_box.rb
|
30
|
+
- lib/errplane/configuration.rb
|
31
|
+
- lib/errplane/rack.rb
|
32
|
+
- lib/errplane/rails/middleware/hijack_render_exception.rb
|
33
|
+
- lib/errplane/railtie.rb
|
34
|
+
- lib/errplane/transmitter.rb
|
35
|
+
- lib/errplane/version.rb
|
36
|
+
- lib/rails/generators/errplane/errplane_generator.rb
|
37
|
+
- lib/rails/generators/errplane/templates/initializer.rb
|
38
|
+
- spec/controllers/widgets_controller_spec.rb
|
39
|
+
- spec/integration/exceptions_spec.rb
|
40
|
+
- spec/integration/integration_helper.rb
|
41
|
+
- spec/internal/app/controllers/application_controller.rb
|
42
|
+
- spec/internal/app/controllers/widgets_controller.rb
|
43
|
+
- spec/internal/config/database.yml
|
44
|
+
- spec/internal/config/initializers/errplane.rb
|
45
|
+
- spec/internal/config/routes.rb
|
46
|
+
- spec/internal/db/combustion_test.sqlite
|
47
|
+
- spec/internal/db/schema.rb
|
48
|
+
- spec/internal/log/.gitignore
|
49
|
+
- spec/internal/public/favicon.ico
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
- spec/unit/black_box_spec.rb
|
52
|
+
homepage: http://errplane.com
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project: errplane
|
72
|
+
rubygems_version: 1.8.24
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Rails exception reporting for Errplane.
|
76
|
+
test_files:
|
77
|
+
- spec/controllers/widgets_controller_spec.rb
|
78
|
+
- spec/integration/exceptions_spec.rb
|
79
|
+
- spec/integration/integration_helper.rb
|
80
|
+
- spec/internal/app/controllers/application_controller.rb
|
81
|
+
- spec/internal/app/controllers/widgets_controller.rb
|
82
|
+
- spec/internal/config/database.yml
|
83
|
+
- spec/internal/config/initializers/errplane.rb
|
84
|
+
- spec/internal/config/routes.rb
|
85
|
+
- spec/internal/db/combustion_test.sqlite
|
86
|
+
- spec/internal/db/schema.rb
|
87
|
+
- spec/internal/log/.gitignore
|
88
|
+
- spec/internal/public/favicon.ico
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- spec/unit/black_box_spec.rb
|