rollbar_helper 1.0.0 → 1.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45016049bfc7fea331fe1718c7a39c632c7aca38f3df4aa70ac97ca8c6e2b820
4
- data.tar.gz: 2f940d6a1d6a39ca65af8e3e25c9ce9a422fb093b2da65219fd79516f96d3651
3
+ metadata.gz: 84606736c578e537092e7c03d44fbab3aab6b4e48e3ca229b2425a7bce1dfb86
4
+ data.tar.gz: 07ffd55bf34642dc5564b2b8fe5a797c0f4e4c9e7d9bc34b4d2bb1aa7190f442
5
5
  SHA512:
6
- metadata.gz: 799e7561dd05166a40d527b0d6e7c1c191fb1c3b5e40dd292261aeffc6c8daf2ba6603acc8e9610995050ee51ddfd70669ded4fa74492b8d59aa2e01b40b794a
7
- data.tar.gz: 989d22b2883cb81a1e3645ed15ffa49b29b34e7136737ea6dcd4a27f530da23b9461226166a25c61db0f6c9a5eb6afb06a16690d6e60662d35950e63c5b8b12c
6
+ metadata.gz: 484787e2fa7d4285ae6961760195f9bddf694ccd000b8951c2b2488f08e69658cf92c66564e62f9c808815c62d7eae5d5968a525dc2441e5f4949bde3073882d
7
+ data.tar.gz: 46a10017ba729fde0e359924ad5a649ad6cc79631e486628f4991632fa6b2984df9f1b79fdd9fd72a7f27b6acd1dfa7267008cce905b72069cd362786c369861
@@ -0,0 +1 @@
1
+ * @bodyshopbidsdotcom/backend-committee
data/README.md CHANGED
@@ -22,24 +22,75 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- Keep your `gem 'rollbar'` dependency and your rollbar configuration.
26
-
27
25
  Instead of calling `Rollbar.error(...)`, call
28
26
  ```ruby
29
- RollbarHelper.error(...)
27
+ RollbarHelper.error(*args)
30
28
  ```
31
29
 
32
- `...` could be a string or an Exception
30
+
31
+ `args` will be an array that can include a mix of:
32
+ - a String for the message to show
33
+ - an Exception
34
+ - a hash for extra params to be sent to Rollbar, including:
35
+ - `:fingerprint` for grouping
36
+ - `:e` for providing an Exception (to not break legacy code)
37
+
38
+ Example:
39
+ ```ruby
40
+ RollbarHelper.error(
41
+ 'Something went wrong',
42
+ exception,
43
+ { foo: 'bar' }
44
+ )
45
+ ```
46
+
47
+ ℹ️ Rollbar allows receiving the args in any given order and it will ignore when an arg not a String, Hash or Exception.
48
+
49
+ ### Logging
50
+
51
+ To also log every report locally, register a `custom_log` hook. It is called before the report is sent to Rollbar:
52
+ ```ruby
53
+ RollbarHelper.custom_log do |loglevel:, message:, exception:, backtrace:, extra:|
54
+ puts "#{loglevel}: #{message}"
55
+ end
56
+ ```
57
+
58
+ - `loglevel` is the Rollbar level (`:debug`, `:info`, `:warning`, `:error`, `:critical`). `RollbarHelper::LEVELS_TO_LOGGER` maps these to `Logger` methods.
59
+ - `backtrace` is the exception's backtrace, or the caller's backtrace when no exception was given.
60
+ - `extra` is the extra hash, without `:fingerprint`.
61
+
62
+ Accept `**` in the block if you don't need every keyword. An exception raised by the hook is printed to stderr and the Rollbar report still goes out. Call `RollbarHelper.custom_log` without a block to remove the hook.
63
+
64
+ To write to a `Logger`, such as `Rails.logger`:
65
+ ```ruby
66
+ RollbarHelper.custom_log do |loglevel:, message:, exception:, **|
67
+ Rails.logger.public_send(
68
+ RollbarHelper::LEVELS_TO_LOGGER[loglevel],
69
+ [message, exception&.full_message].compact.join("\n")
70
+ )
71
+ end
72
+ ```
33
73
 
34
74
  ## Development
35
75
 
36
- 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.
76
+ ### Setup
77
+ After checking out the repo, run `bin/setup` to install dependencies.
78
+
79
+ ### Specs
80
+ Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
81
+
82
+ ### Install
83
+ To install this gem onto your local machine, run `bundle exec rake install`.
37
84
 
38
- 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).
85
+ ### Release
86
+ To release a new version:
87
+ - update the version number in `version.rb`,
88
+ - 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).
39
89
 
40
90
  ## Contributing
41
91
 
42
- Bug reports and pull requests are welcome on GitHub at https://github.com/bodyshopbidsdotcom/rollbar_helper. 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.
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bodyshopbidsdotcom/rollbar_helper.
93
+ 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.
43
94
 
44
95
 
45
96
  ## License
@@ -1,3 +1,3 @@
1
1
  module RollbarHelper
2
- VERSION = '1.0.0'
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -3,55 +3,99 @@ require 'rollbar_helper/version'
3
3
 
4
4
  module RollbarHelper
5
5
  LEVELS = [
6
- :critical,
7
6
  :debug,
8
- :error,
9
7
  :info,
10
8
  :warning,
11
- ]
9
+ :error,
10
+ :critical,
11
+ ].freeze
12
+
13
+ LEVELS_TO_LOGGER = {
14
+ debug: :debug,
15
+ info: :info,
16
+ warning: :warn,
17
+ error: :error,
18
+ critical: :fatal
19
+ }.freeze
12
20
 
13
21
  class << self
14
- def critical(obj, fingerprint: nil, **data)
15
- log(:critical, obj, :callee => caller, fingerprint: fingerprint, **data)
16
- end
22
+ LEVELS.each do |level|
23
+ define_method(level) do |*args|
24
+ message, exception, extra = extract_arguments(args)
25
+ extra = { callee: caller }.merge(extra)
26
+ data, exception, callee, fingerprint = split_extra_arg(extra, exception)
27
+
28
+ call_custom_log(level, message, exception, callee, data) if custom_log?
29
+
30
+ if !message.nil? && exception.nil?
31
+ exception = StandardError.new(message).tap do |e|
32
+ e.set_backtrace(callee)
33
+ end
34
+ message = nil
35
+ end
17
36
 
18
- def debug(obj, fingerprint: nil, **data)
19
- log(:debug, obj, :callee => caller, fingerprint: fingerprint, **data)
37
+ get_notifier(fingerprint).public_send(level, message, exception, data)
38
+ end
20
39
  end
21
40
 
22
- def error(obj, fingerprint: nil, **data)
23
- log(:error, obj, :callee => caller, fingerprint: fingerprint, **data)
41
+ def log(level, *args)
42
+ raise ArgumentError, 'Log level is not supported' unless LEVELS.include?(level.to_sym)
43
+ send(level, { callee: caller }, *args)
24
44
  end
25
45
 
26
- def info(obj, fingerprint: nil, **data)
27
- log(:info, obj, :callee => caller, fingerprint: fingerprint, **data)
46
+ # Registers a block called on every report, before it is sent to Rollbar.
47
+ # Calling it without a block removes the hook.
48
+ def custom_log(&block)
49
+ @custom_log = block
28
50
  end
29
51
 
30
- def warn(obj, fingerprint: nil, **data)
31
- log(:warning, obj, :callee => caller, fingerprint: fingerprint, **data)
52
+ def custom_log?
53
+ !@custom_log.nil?
32
54
  end
33
55
 
34
- def warning(obj, fingerprint: nil, **data)
35
- log(:warning, obj, :callee => caller, fingerprint: fingerprint, **data)
56
+ private
57
+
58
+ def call_custom_log(level, message, exception, callee, extra)
59
+ @custom_log.call(
60
+ loglevel: level,
61
+ message: message,
62
+ exception: exception,
63
+ backtrace: exception&.backtrace || callee,
64
+ extra: extra.dup
65
+ )
66
+ rescue StandardError => e
67
+ # Logging failures must never prevent the underlying Rollbar report.
68
+ # $stderr directly, since Kernel#warn is silent when $VERBOSE is nil.
69
+ $stderr.puts("RollbarHelper custom_log failed to log: #{e.class}: #{e.message}")
36
70
  end
37
71
 
38
- def log(level, obj, callee: caller, fingerprint: nil, **data)
39
- level = level.to_sym
40
- raise ArgumentError, 'Log level is not supported' unless LEVELS.include?(level)
41
- e = nil
72
+ def extract_arguments(args)
73
+ message = exception = nil
74
+ extra = {}
42
75
 
43
- if obj.is_a?(Exception)
44
- e = obj
45
- else
46
- e = StandardError.new(obj.to_s)
47
- e.set_backtrace(callee)
76
+ args.each do |arg|
77
+ if arg.is_a?(String)
78
+ message = arg
79
+ elsif arg.is_a?(Exception)
80
+ exception = arg
81
+ elsif arg.is_a?(Hash)
82
+ extra = extra.merge(arg)
83
+ end
48
84
  end
49
85
 
50
- unless fingerprint.nil?
51
- ::Rollbar.scope(:fingerprint => fingerprint).send(level, e, data)
52
- else
53
- ::Rollbar.send(level, e, data)
54
- end
86
+ [message, exception, extra]
87
+ end
88
+
89
+ def split_extra_arg(extra, exception)
90
+ exception ||= extra.delete(:e) # Core legacy support
91
+ callee = extra.delete(:callee)
92
+ fingerprint = extra.delete(:fingerprint)
93
+ [extra, exception, callee, fingerprint]
94
+ end
95
+
96
+ def get_notifier(fingerprint)
97
+ return Rollbar if fingerprint.nil?
98
+ Rollbar.scope(fingerprint: fingerprint)
55
99
  end
56
100
  end
57
101
  end
@@ -27,8 +27,8 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_development_dependency "bundler", "~> 1.14"
31
- spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "bundler", ">= 1.14"
31
+ spec.add_development_dependency "rake", "~> 13.0"
32
32
  spec.add_development_dependency "rspec", "~> 3.0"
33
33
  spec.add_development_dependency "pry", "~> 0.11"
34
34
  spec.add_dependency "rollbar", "~> 3.2"
metadata CHANGED
@@ -1,27 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Santiago Herrera
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2021-10-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: '1.14'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - "~>"
23
+ - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '1.14'
27
26
  - !ruby/object:Gem::Dependency
@@ -30,14 +29,14 @@ dependencies:
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '10.0'
32
+ version: '13.0'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '10.0'
39
+ version: '13.0'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: rspec
43
42
  requirement: !ruby/object:Gem::Requirement
@@ -80,13 +79,13 @@ dependencies:
80
79
  - - "~>"
81
80
  - !ruby/object:Gem::Version
82
81
  version: '3.2'
83
- description:
84
82
  email:
85
83
  - santi.4096@gmail.com
86
84
  executables: []
87
85
  extensions: []
88
86
  extra_rdoc_files: []
89
87
  files:
88
+ - ".github/CODEOWNERS"
90
89
  - ".gitignore"
91
90
  - ".rspec"
92
91
  - ".travis.yml"
@@ -105,7 +104,6 @@ licenses:
105
104
  - MIT
106
105
  metadata:
107
106
  allowed_push_host: https://rubygems.org
108
- post_install_message:
109
107
  rdoc_options: []
110
108
  require_paths:
111
109
  - lib
@@ -120,8 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
118
  - !ruby/object:Gem::Version
121
119
  version: '0'
122
120
  requirements: []
123
- rubygems_version: 3.2.3
124
- signing_key:
121
+ rubygems_version: 3.6.9
125
122
  specification_version: 4
126
123
  summary: Displays a stacktrace in rollbar
127
124
  test_files: []