rollbar_helper 1.1.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 +5 -5
- data/.github/CODEOWNERS +1 -0
- data/README.md +58 -7
- data/lib/rollbar_helper/version.rb +1 -1
- data/lib/rollbar_helper.rb +34 -0
- data/rollbar_helper.gemspec +2 -2
- metadata +8 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 84606736c578e537092e7c03d44fbab3aab6b4e48e3ca229b2425a7bce1dfb86
|
|
4
|
+
data.tar.gz: 07ffd55bf34642dc5564b2b8fe5a797c0f4e4c9e7d9bc34b4d2bb1aa7190f442
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 484787e2fa7d4285ae6961760195f9bddf694ccd000b8951c2b2488f08e69658cf92c66564e62f9c808815c62d7eae5d5968a525dc2441e5f4949bde3073882d
|
|
7
|
+
data.tar.gz: 46a10017ba729fde0e359924ad5a649ad6cc79631e486628f4991632fa6b2984df9f1b79fdd9fd72a7f27b6acd1dfa7267008cce905b72069cd362786c369861
|
data/.github/CODEOWNERS
ADDED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
data/lib/rollbar_helper.rb
CHANGED
|
@@ -10,6 +10,14 @@ module RollbarHelper
|
|
|
10
10
|
:critical,
|
|
11
11
|
].freeze
|
|
12
12
|
|
|
13
|
+
LEVELS_TO_LOGGER = {
|
|
14
|
+
debug: :debug,
|
|
15
|
+
info: :info,
|
|
16
|
+
warning: :warn,
|
|
17
|
+
error: :error,
|
|
18
|
+
critical: :fatal
|
|
19
|
+
}.freeze
|
|
20
|
+
|
|
13
21
|
class << self
|
|
14
22
|
LEVELS.each do |level|
|
|
15
23
|
define_method(level) do |*args|
|
|
@@ -17,6 +25,8 @@ module RollbarHelper
|
|
|
17
25
|
extra = { callee: caller }.merge(extra)
|
|
18
26
|
data, exception, callee, fingerprint = split_extra_arg(extra, exception)
|
|
19
27
|
|
|
28
|
+
call_custom_log(level, message, exception, callee, data) if custom_log?
|
|
29
|
+
|
|
20
30
|
if !message.nil? && exception.nil?
|
|
21
31
|
exception = StandardError.new(message).tap do |e|
|
|
22
32
|
e.set_backtrace(callee)
|
|
@@ -33,8 +43,32 @@ module RollbarHelper
|
|
|
33
43
|
send(level, { callee: caller }, *args)
|
|
34
44
|
end
|
|
35
45
|
|
|
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
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def custom_log?
|
|
53
|
+
!@custom_log.nil?
|
|
54
|
+
end
|
|
55
|
+
|
|
36
56
|
private
|
|
37
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}")
|
|
70
|
+
end
|
|
71
|
+
|
|
38
72
|
def extract_arguments(args)
|
|
39
73
|
message = exception = nil
|
|
40
74
|
extra = {}
|
data/rollbar_helper.gemspec
CHANGED
|
@@ -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", "
|
|
31
|
-
spec.add_development_dependency "rake", "~>
|
|
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.
|
|
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:
|
|
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: '
|
|
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: '
|
|
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,9 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
120
118
|
- !ruby/object:Gem::Version
|
|
121
119
|
version: '0'
|
|
122
120
|
requirements: []
|
|
123
|
-
|
|
124
|
-
rubygems_version: 2.5.2.3
|
|
125
|
-
signing_key:
|
|
121
|
+
rubygems_version: 3.6.9
|
|
126
122
|
specification_version: 4
|
|
127
123
|
summary: Displays a stacktrace in rollbar
|
|
128
124
|
test_files: []
|