rollbar-mode 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b5ed5cbeafaea0c193d7554024199c8704e8bf1d9f6f8eec1eeabecae2f6badc
4
+ data.tar.gz: 66b9033b62d0c9d9423205c59127870d07e4a0519f0d23464861f042b53ecffe
5
+ SHA512:
6
+ metadata.gz: 77f00ff3d0d4ab88af5eef5e2a771b5adf76b7121431090b4daa3ae2004ee05a740b6a145787bd3d3d28812a088c6db158d9a2a2402d4ea0b1915c8d993321b5
7
+ data.tar.gz: 3d9d5ce5036bb4136297c35d67713af1f2ac31ebb1fa0a730f898fcf86509604d4fe211d13cb27fc2d1ffae79c7bc07d817f2b3391fd6090d22a81011ec38913
@@ -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
@@ -0,0 +1,49 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4.2
3
+
4
+ MethodLength:
5
+ Max: 20
6
+
7
+ BlockLength:
8
+ Max: 70
9
+
10
+ Exclude:
11
+ - 'Rakefile'
12
+ - 'rakelib/**/*.rake'
13
+ - 'spec/**/*.rb'
14
+
15
+ Metrics/LineLength:
16
+ Max: 80
17
+
18
+ Naming/RescuedExceptionsVariableName:
19
+ PreferredName: exception
20
+
21
+ Style/GuardClause:
22
+ Enabled: false
23
+
24
+ Style/Next:
25
+ Enabled: false
26
+
27
+ Style/SymbolArray:
28
+ Enabled: false
29
+
30
+ Style/SymbolProc:
31
+ Enabled: false
32
+
33
+ Style/WordArray:
34
+ Enabled: false
35
+
36
+ Style/YodaCondition:
37
+ EnforcedStyle: forbid_for_equality_operators_only
38
+
39
+ Layout/EmptyLinesAroundClassBody:
40
+ EnforcedStyle: empty_lines_except_namespace
41
+
42
+ Layout/EmptyLinesAroundModuleBody:
43
+ EnforcedStyle: empty_lines_except_namespace
44
+
45
+ Layout/MultilineMethodCallIndentation:
46
+ EnforcedStyle: aligned
47
+
48
+ Layout/SpaceInsidePercentLiteralDelimiters:
49
+ Enabled: false
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rollbar-mode.gemspec
6
+ gemspec
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rollbar-mode (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ method_source (0.9.2)
12
+ pry (0.12.2)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.9.0)
15
+ rake (10.5.0)
16
+ rollbar (2.22.1)
17
+ rspec (3.9.0)
18
+ rspec-core (~> 3.9.0)
19
+ rspec-expectations (~> 3.9.0)
20
+ rspec-mocks (~> 3.9.0)
21
+ rspec-core (3.9.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-expectations (3.9.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.9.0)
26
+ rspec-mocks (3.9.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.9.0)
29
+ rspec-support (3.9.0)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 1.17)
36
+ pry (~> 0.12)
37
+ rake (~> 10.0)
38
+ rollbar (~> 2.22)
39
+ rollbar-mode!
40
+ rspec (~> 3.0)
41
+
42
+ BUNDLED WITH
43
+ 1.17.3
@@ -0,0 +1,109 @@
1
+ # Rollbar::Mode
2
+
3
+ The idea behind `Rollbar::Mode` is inspired from the [Emacs major and minor][1]
4
+ modes, which alter the behaviour of the editor in certain cases. This is
5
+ the equivalent of a "minor mode", which alters the way Rollbar integrates
6
+ with your code:
7
+
8
+ * In development it automatically re-raises exceptions logged with Rollbar
9
+ * In production it alters some default values for better integration with Heroku
10
+
11
+ [1]: https://www.gnu.org/software/emacs/manual/html_node/emacs/Modes.html
12
+
13
+
14
+ ### Development mode
15
+
16
+ In development (i.e. when the Rollbar token is not set), the reporter will
17
+ not send errors to Rollbar but re-raise them, allowing the following code
18
+ pattern to work well both in development and in production:
19
+
20
+ ``` ruby
21
+ def find(id)
22
+ user = method_that_could_raise_exception(id)
23
+ rescue StandardError => exception
24
+ Rollbar.error(exception)
25
+
26
+ nil
27
+ end
28
+ ```
29
+
30
+ As of v2.22 of the gem, Rollbar has a setting called `raise_on_error` but will
31
+ only work if Rollbar believes it's enabled (the access token is enabled). See
32
+ the early `return` in the code snippet below, taken from
33
+ `Rollbar::Notifier#log`:
34
+
35
+
36
+ ``` ruby
37
+ def log(level, *args)
38
+ return 'disabled' unless enabled?
39
+
40
+ message, exception, extra, context = extract_arguments(args)
41
+ use_exception_level_filters = use_exception_level_filters?(extra)
42
+
43
+ return 'ignored' if ignored?(exception, use_exception_level_filters)
44
+
45
+ begin
46
+ status = call_before_process(:level => level,
47
+ :exception => exception,
48
+ :message => message,
49
+ :extra => extra)
50
+ return 'ignored' if status == 'ignored'
51
+ rescue Rollbar::Ignore
52
+ return 'ignored'
53
+ end
54
+
55
+ level = lookup_exception_level(level, exception,
56
+ use_exception_level_filters)
57
+
58
+ ret = report_with_rescue(level, message, exception, extra, context)
59
+
60
+ raise(exception) if configuration.raise_on_error && exception
61
+
62
+ ret
63
+ end
64
+ ```
65
+
66
+ If the Rollbar access token is not availble _and_ the `raise_on_errror` setting
67
+ is set to `true`, this gem will monkeypatch the `log` method described above
68
+ to side-steps the error delivery mechanism and automatically re-raise the
69
+ exception.
70
+
71
+ In order to make sure that the gem only affects your code in development, you
72
+ can enable it only in the Bundler `development` group:
73
+
74
+ ``` ruby
75
+ group :development do
76
+ gem 'rollbar-mode'
77
+ end
78
+ ```
79
+
80
+
81
+ ### Production mode
82
+
83
+ Rollbar has several configuration options that help with error reporting, like:
84
+
85
+ * `code_version` for linking stack traces to GitHub (SemVer, git SHA)
86
+ * `environment` which defaults to "unspecified"
87
+ * `populate_empty_backtraces` for manually initialized exceptions
88
+ * `use_async` for reporting errors using either `girl_friday` or threading
89
+
90
+ `Rollbar::Mode` will alter the default configuration for Rollbar to these
91
+ values:
92
+
93
+ * `code_version` will be set to the value of `HEROKU_SLUG_COMMIT` if available
94
+ * `environment` will be set to the value of `HEROKU_APP_NAME`, if available
95
+ * `populate_empty_backtraces` will be set to `true` (normal default is `false`)
96
+ * `use_async` will be set to `true` (normal default is `false`)
97
+
98
+ The `HEROKU_*` environment variables are provided by the [Dyno Metadata][2]
99
+ feature and has to be enabled manually.
100
+
101
+ [2]: https://devcenter.heroku.com/articles/dyno-metadata
102
+
103
+ If you do not want these changes, make sure the gem is in the development
104
+ group.
105
+
106
+
107
+ ## Contributing
108
+
109
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andreimaxim/rollbar-mode.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rollbar/mode"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rollbar'
4
+
5
+ require 'rollbar/mode/local_notifier'
6
+ require 'rollbar/mode/production'
7
+ require 'rollbar/mode/development'
8
+
9
+ require 'rollbar/mode/version'
10
+
11
+ module Rollbar
12
+ # Minor mode for Rollbar
13
+ module Mode
14
+
15
+ def self.apply
16
+ if Rollbar::Mode.production?
17
+ Rollbar::Mode::Production.apply
18
+ else
19
+ Rollbar::Mode::Development.apply
20
+ end
21
+ end
22
+
23
+ def self.production?
24
+ Rollbar::Mode::Production.access_token ||
25
+ Rollbar.configuration.enabled
26
+ end
27
+
28
+ # Determine if the current environment is a Heroku dyno based on the
29
+ # dyno metadata.
30
+ #
31
+ # See:
32
+ #
33
+ # https://devcenter.heroku.com/articles/dyno-metadata
34
+ def self.heroku?
35
+ ENV.key?('HEROKU_SLUG_COMMIT') &&
36
+ ENV.key?('HEROKU_APP_NAME')
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+ Rollbar::Mode.apply
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rollbar
4
+ module Mode
5
+ # Rollbar development minor mode
6
+ class Development
7
+
8
+ class << self
9
+
10
+ # :reek:TooManyStatements
11
+ def apply
12
+ Rollbar.reset_notifier!
13
+ Rollbar.notifier = Rollbar::Mode::LocalNotifier.new
14
+
15
+ Rollbar.configure do |config|
16
+ config.enabled = false
17
+ config.raise_on_error = true
18
+ end
19
+
20
+ warn 'Rollbar: disabled, errors re-raised automatically'
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rollbar
4
+ module Mode
5
+ # Local notifier that re-raises the exceptions
6
+ class LocalNotifier < ::Rollbar::Notifier
7
+
8
+ # Normally would send a report to Rollbar.
9
+ #
10
+ # Accepts any number of arguments. The last String argument will become
11
+ # the message or description of the report. The last Exception argument
12
+ # will become the associated exception for the report. The last hash
13
+ # argument will be used as the extra data for the report.
14
+ #
15
+ # This method is used by code lilke:
16
+ #
17
+ # @example
18
+ # begin
19
+ # foo = bar
20
+ # rescue => e
21
+ # Rollbar.error(e)
22
+ # end
23
+ #
24
+ # or:
25
+ #
26
+ # @example
27
+ # begin
28
+ # foo = bar
29
+ # rescue => e
30
+ # Rollbar.log(e, 'This is a description of the exception')
31
+ # end
32
+ #
33
+ def log(_level, *args)
34
+ _message, exception, _extra, _context = extract_arguments(args)
35
+ raise(exception) if configuration.raise_on_error && exception
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rollbar
4
+ module Mode
5
+ # Rollbar production minor-mode.
6
+ class Production
7
+
8
+ class << self
9
+
10
+ # :reek:TooManyStatements
11
+ def apply
12
+ Rollbar.configure do |config|
13
+ config.enabled = true
14
+ config.access_token = access_token
15
+
16
+ # Override the default values with better ones
17
+ config.populate_empty_backtraces = true
18
+ config.use_async = true
19
+
20
+ # Set up the code-related metrics.
21
+ config.code_version = code_version
22
+ config.environment = environment
23
+ end
24
+
25
+ warn 'Rollbar: using online service at https://rollbar.com'
26
+ end
27
+
28
+ def code_version
29
+ ENV['HEROKU_SLUG_COMMIT']
30
+ end
31
+
32
+ def environment
33
+ ENV['HEROKU_APP_NAME']
34
+ end
35
+
36
+ def access_token
37
+ ENV['ROLLBAR_ACCESS_TOKEN']
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rollbar
4
+ module Mode
5
+ VERSION = '0.0.1'
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rollbar/mode/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'rollbar-mode'
9
+ spec.version = Rollbar::Mode::VERSION
10
+ spec.authors = 'Andrei Maxim'
11
+ spec.email = 'andrei@andreimaxim.ro'
12
+
13
+ spec.summary = 'Add a Rollbar minor mode to your environment'
14
+ spec.homepage = 'https://github.com/andreimaxim/rollbar-mode'
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
18
+ # into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`
21
+ .split("\x0")
22
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.17'
30
+ spec.add_development_dependency 'pry', '~> 0.12'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rollbar', '~> 2.22'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rollbar-mode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrei Maxim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rollbar
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.22'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.22'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email: andrei@andreimaxim.ro
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - ".rubocop.yml"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/rollbar/mode.rb
100
+ - lib/rollbar/mode/development.rb
101
+ - lib/rollbar/mode/local_notifier.rb
102
+ - lib/rollbar/mode/production.rb
103
+ - lib/rollbar/mode/version.rb
104
+ - rollbar-mode.gemspec
105
+ homepage: https://github.com/andreimaxim/rollbar-mode
106
+ licenses: []
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Add a Rollbar minor mode to your environment
127
+ test_files: []