erorr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b45b6f5b43832b233cb767226101f54da953033a12c06009c9a0132de238321e
4
+ data.tar.gz: 455e3ba9f73509ef19d8a7b5a83e3823fe3a235ed0e9277f37afb72c95be5bbe
5
+ SHA512:
6
+ metadata.gz: 2168fbc44040862030430a8e5123dfedb4442db8ed35e8a7d30b8b6775d82f9247cabbf3d83dd7bf3fd1d441d0d1a1875942b4e5e5b031b791b1dc28fad4a7f5
7
+ data.tar.gz: ee5fe808e8105269bdf48b56c1c6c3b5255eb167adbc7ac22ab58dba5cf8c06c21d22597e5d07c0556a873c8ddf6838022a4b1624a1471347b0a088ab98b71ee
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ erorr (0.1.0)
5
+ commander (~> 4.4)
6
+ concurrent-ruby (~> 1.0)
7
+ http
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.6.0)
13
+ public_suffix (>= 2.0.2, < 4.0)
14
+ commander (4.4.7)
15
+ highline (~> 2.0.0)
16
+ concurrent-ruby (1.1.4)
17
+ diff-lcs (1.3)
18
+ domain_name (0.5.20180417)
19
+ unf (>= 0.0.5, < 1.0.0)
20
+ highline (2.0.1)
21
+ http (4.0.5)
22
+ addressable (~> 2.3)
23
+ http-cookie (~> 1.0)
24
+ http-form_data (~> 2.0)
25
+ http_parser.rb (~> 0.6.0)
26
+ http-cookie (1.0.3)
27
+ domain_name (~> 0.5)
28
+ http-form_data (2.1.1)
29
+ http_parser.rb (0.6.0)
30
+ public_suffix (3.0.3)
31
+ rake (10.5.0)
32
+ rspec (3.8.0)
33
+ rspec-core (~> 3.8.0)
34
+ rspec-expectations (~> 3.8.0)
35
+ rspec-mocks (~> 3.8.0)
36
+ rspec-core (3.8.0)
37
+ rspec-support (~> 3.8.0)
38
+ rspec-expectations (3.8.2)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.8.0)
41
+ rspec-mocks (3.8.0)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.8.0)
44
+ rspec-support (3.8.0)
45
+ unf (0.1.4)
46
+ unf_ext
47
+ unf_ext (0.0.7.5)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ bundler (~> 1.17)
54
+ erorr!
55
+ rake (~> 10.0)
56
+ rspec (~> 3.0)
57
+
58
+ BUNDLED WITH
59
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Georgi Mitrev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Erorr Ruby client
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/erorr/rb`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'erorr-rb'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install erorr-rb
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gmitrev/erorr-rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Erorr::Rb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/gmitrev/erorr-rb/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ task :console do
9
+ require 'irb'
10
+ require 'irb/completion'
11
+ require 'erorr'
12
+ ARGV.clear
13
+ IRB.start
14
+ end
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require_relative '../lib/erorr'
5
+
6
+ require 'irb'
7
+ IRB.start(__FILE__)
data/bin/erorr ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/erorr/cli'
3
+
4
+ Erorr::CLI.new.run
data/erorr.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path 'lib', __dir__
2
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
3
+
4
+ require 'erorr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'erorr'
8
+ spec.version = Erorr::VERSION
9
+ spec.authors = ['Georgi Mitrev']
10
+ spec.email = ['gvmitrev@gmail.com']
11
+ spec.summary = %q{Ruby library for erorr.app}
12
+ spec.description = %q{A client library for erorr.app integration}
13
+ spec.homepage = 'https://github.com/gmitrev/erorr-rb'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+
20
+ spec.require_paths = ['lib']
21
+ spec.bindir = 'bin'
22
+ spec.executables << 'erorr'
23
+
24
+ spec.add_dependency 'http'
25
+ spec.add_dependency 'concurrent-ruby', '~> 1.0'
26
+ spec.add_dependency 'commander', '~> 4.4'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.17'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ end
data/lib/erorr/cli.rb ADDED
@@ -0,0 +1,89 @@
1
+ require 'commander'
2
+
3
+ module Erorr
4
+ class ErorrTestException < StandardError; end
5
+ class CLI
6
+ include Commander::Methods
7
+
8
+ def run
9
+ program :name, 'erorr'
10
+ program :version, Erorr::VERSION
11
+ program :description, 'Ruby/Rails client for erorr.app'
12
+
13
+ never_trace!
14
+
15
+ command 'setup' do |c|
16
+ c.syntax = 'erorr setup API-KEY'
17
+ c.description = 'Creates erorr.app\'s configuration file config/erorr.yml and populates it with the provided API-KEY.'
18
+ c.action do |args, _options|
19
+ api_key = args[0]
20
+
21
+ if File.exist? config_file_path
22
+ say_error 'Erorr config file already exists.'
23
+
24
+ exit(0)
25
+ end
26
+
27
+ unless api_key
28
+ say_error 'Please provide an API KEY.'
29
+
30
+ exit(0)
31
+ end
32
+
33
+ configuration_file = <<~YAML
34
+ ---
35
+ api_key: #{api_key}
36
+ YAML
37
+
38
+ File.open(config_file_path, 'w') { |file| file.write(configuration_file) }
39
+
40
+ say_success <<~MSG
41
+ erorr.app client configured successfully!
42
+
43
+ Test the integration by sending a test notification:
44
+
45
+ bundle exec erorr test-notify
46
+
47
+ If all is well, you'll see the test notification in https://erorr.app.
48
+ MSG
49
+ end
50
+ end
51
+
52
+ command 'test-notify' do |c|
53
+ c.syntax = 'erorr test-notify'
54
+ c.description = 'Send a test notification to erorr.app'
55
+ c.action do |args, _options|
56
+ require File.expand_path('config/environment')
57
+
58
+ Erorr.configure do |config|
59
+ config.enabled_for << 'development'
60
+ end
61
+
62
+ begin
63
+ raise ErorrTestException.new('Test message')
64
+ rescue ErorrTestException => e
65
+ if Erorr.notify e, location: 'erorr test-notify'
66
+ say_success 'Test notification sent successfully.'
67
+ else
68
+ say_error 'Test notification could not be delivered.'
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ run!
75
+ end
76
+
77
+ def config_file_path
78
+ File.expand_path 'config/erorr.yml'
79
+ end
80
+
81
+ def say_success(message)
82
+ say color(message, :green)
83
+ end
84
+
85
+ def say_error(message)
86
+ say color(message, :red)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,50 @@
1
+ require 'yaml'
2
+
3
+ module Erorr
4
+ class Config
5
+ attr_accessor :api_key,
6
+ :api_url,
7
+ :env,
8
+ :logger,
9
+ :root,
10
+ :enabled_for
11
+
12
+ def initialize
13
+ @env = ENV['ERORR_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV']
14
+ @api_key = ENV['ERORR_API_KEY']
15
+ @api_url = 'https://erorr.app/api'.freeze
16
+ @enabled_for = %w(production staging)
17
+
18
+ @logger = Logger.new(STDOUT)
19
+ end
20
+
21
+ def validate
22
+ unless @api_key
23
+ logger.warn '[erorr] API-KEY not set, skipping notifications.'
24
+
25
+ return false
26
+ end
27
+
28
+ unless @enabled_for.include? @env.to_s
29
+ logger.warn "[erorr] Reporting disabled for environment '#{@env}', skipping notification."
30
+
31
+ return false
32
+ end
33
+
34
+ true
35
+ end
36
+
37
+ def load_for(app)
38
+ @env ||= Rails.env
39
+ @root = app.root
40
+
41
+ config_file = @root.join 'config/erorr.yml'
42
+
43
+ file_config = YAML.safe_load File.read config_file
44
+
45
+ @api_key = file_config['api_key'] if file_config['api_key']
46
+ @api_url = file_config['api_url'] if file_config['api_url']
47
+ @enabled_for = file_config['enabled_for'] if file_config['enabled_for']
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,31 @@
1
+ module Erorr
2
+ module Middleware
3
+ class Rack
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ begin
10
+ response = @app.call(env)
11
+ rescue Exception => exception
12
+ request = ActionDispatch::Request.new env
13
+
14
+ location = request.parameters.values_at('controller', 'action').join('#')
15
+ request_params = {
16
+ params: request.parameters,
17
+ remote_ip: request.remote_ip,
18
+ }
19
+
20
+ Erorr.notify exception, location: location, request: request_params
21
+
22
+ raise
23
+ end
24
+
25
+ response
26
+ ensure
27
+ # Erorr.clear_request_data
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,54 @@
1
+ module Erorr
2
+ class Notification
3
+ def initialize(exception, params = {})
4
+ @exception = exception
5
+ @params = params
6
+ end
7
+
8
+ def to_params
9
+ {
10
+ class: @exception.class.name,
11
+ message: @exception.message,
12
+ location: location,
13
+ backtrace: backtrace.join("\n"),
14
+ environment: Erorr.config.env,
15
+ timestamp: Time.current,
16
+ fingerprint: fingerprint,
17
+ host: Socket.gethostname,
18
+ pid: Process.pid,
19
+ request_params: @params.dig(:request, :params),
20
+ request_remote_ip: @params.dig(:request, :remote_ip),
21
+ }
22
+ end
23
+
24
+ private
25
+
26
+ def location
27
+ @params[:location] || $PROGRAM_NAME
28
+ end
29
+
30
+ def backtrace
31
+ @_backtrace ||=
32
+ begin
33
+ cleaner = ActiveSupport::BacktraceCleaner.new
34
+ gem_paths.each { |gem_path| cleaner.add_filter { |line| line.sub(gem_path, '') } }
35
+ cleaner.add_filter { |line| line.sub(Erorr.config.root.to_s, '') }
36
+ cleaner.add_filter { |line| line.sub('/', '') }
37
+
38
+ cleaner.clean(@exception.backtrace)
39
+ end
40
+ end
41
+
42
+ def fingerprint
43
+ first_backtrace_line = backtrace.find { |trace| trace !~ /pry|irb/ }
44
+ checksum = [first_backtrace_line, @exception.class].join('|')
45
+
46
+ Digest::SHA1.hexdigest checksum
47
+ end
48
+
49
+ def gem_paths
50
+ @gem_paths ||= Gem.path | [Gem.default_dir]
51
+ end
52
+ end
53
+ end
54
+
@@ -0,0 +1,15 @@
1
+ module Erorr
2
+ class Railtie < Rails::Railtie
3
+ initializer 'erorr.use_rack_middleware' do |app|
4
+ if defined? ActionDispatch::DebugExceptions
5
+ app.middleware.insert_after ActionDispatch::DebugExceptions, Erorr::Middleware::Rack
6
+ else
7
+ app.middleware.use Erorr::Middleware::Rack
8
+ end
9
+ end
10
+
11
+ initializer 'erorr.configuration' do |app|
12
+ Erorr.config.load_for app
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require 'http'
2
+ require 'concurrent'
3
+
4
+ module Erorr
5
+ module Transport
6
+ class HTTPAsync
7
+ def initialize
8
+ @api_key = Erorr.config.api_key
9
+ @api_url = Erorr.config.api_url
10
+ end
11
+
12
+ def deliver(params)
13
+ # Concurrent::Promises.future do
14
+ HTTP.post "#{@api_url}/faults", json: {fault: params, api_key: @api_key}
15
+ # end.rescue { |error| log_error error}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Erorr
2
+ VERSION = '0.1.0'
3
+ end
data/lib/erorr.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'erorr/config'
2
+ require 'erorr/middleware/rack'
3
+ require 'erorr/notification'
4
+ require 'erorr/transport/http_async'
5
+ require 'erorr/version'
6
+
7
+ module Erorr
8
+ extend self
9
+
10
+ def config
11
+ @config ||= Config.new
12
+ end
13
+
14
+ def configure
15
+ yield config if block_given?
16
+ end
17
+
18
+ def logger
19
+ config.logger
20
+ end
21
+
22
+ def notify(exception, params = {})
23
+ return false unless config.validate
24
+
25
+ notification = Notification.new exception, params
26
+
27
+ transport.deliver notification.to_params
28
+
29
+ true
30
+ rescue => e
31
+ logger.error "[erorr] Internal error: #{e.inspect}"
32
+
33
+ false
34
+ end
35
+
36
+ private
37
+
38
+ def transport
39
+ @_transport ||= Erorr::Transport::HTTPAsync.new
40
+ end
41
+ end
42
+
43
+ require 'erorr/plugins/rails' if defined? Rails::Railtie
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erorr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Georgi Mitrev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: concurrent-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: commander
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.17'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.17'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: A client library for erorr.app integration
98
+ email:
99
+ - gvmitrev@gmail.com
100
+ executables:
101
+ - erorr
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/erorr
115
+ - erorr.gemspec
116
+ - lib/erorr.rb
117
+ - lib/erorr/cli.rb
118
+ - lib/erorr/config.rb
119
+ - lib/erorr/middleware/rack.rb
120
+ - lib/erorr/notification.rb
121
+ - lib/erorr/plugins/rails.rb
122
+ - lib/erorr/transport/http_async.rb
123
+ - lib/erorr/version.rb
124
+ homepage: https://github.com/gmitrev/erorr-rb
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.7.6
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Ruby library for erorr.app
148
+ test_files: []