Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/givelively/exception_notifier
This is GiveLively's exception notification wrapper
https://github.com/givelively/exception_notifier
Last synced: about 2 months ago
JSON representation
This is GiveLively's exception notification wrapper
- Host: GitHub
- URL: https://github.com/givelively/exception_notifier
- Owner: givelively
- Created: 2020-03-02T19:59:48.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-26T19:05:54.000Z (6 months ago)
- Last Synced: 2024-07-27T20:49:21.428Z (6 months ago)
- Language: Ruby
- Size: 89.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Use [gl_exception_notifier](https://github.com/givelively/gl_exception_notifier) (this gem's replacement)
**This gem is deprecated and replaced**
The repository has been left because some code references the github URL, but everything should be updated to use the GLExceptionNotifier gem.
---
# Exception Notifier
This is GiveLively's exception notification wrapper. The goal of this gem is to provide the charity api with a clean set of exception and logging apis regardless of what exception client is used under the hood.
Currently we use [sentry-ruby](https://docs.sentry.io/platforms/ruby/).
`ExceptionNotifier` isolates the main charity api app from the exception notifier in use.[![codecov](https://codecov.io/gh/givelively/exception_notifier/branch/master/graph/badge.svg?token=4P64ZW129N)](https://codecov.io/gh/givelively/exception_notifier)
## Usage
`ExceptionNotifier` supports the following:
**Record an Exception**
Capture exceptions with the call method.
```ruby
begin
raise StandardError
rescue StandardError => error
ExceptionNotifier.call(error)
end
```**Adding Context**
The `add_context` method takes two arguments, first a `type` which must be symbol: `:tags_context`, `:user_context`, or `:extra_context`. Second, a `Hash` of parameters to add to the given context type.
```ruby
# add tags to the context
ExceptionNotifier.add_context(:tags_context, my_tag: my_tag_value)# add user info to the context
ExceptionNotifier.add_context(:user_context, user_id: user_id)# add extra info to the context
ExceptionNotifier.add_context(:extra_context, more_info: { interesting_data: 1234, more_data: 'hello world' })
```**Add Breadcrumbs to Context**
The `breadcrumbs` method takes two arguments, first a `message` which must be a `String`, and second a `Hash` of data to add to the context's breadcrumb trail.
```ruby
ExceptionNotifier.breadcrumbs(message: 'foo', data: { bar: 'baz' })
```**Breadcrumb Inspection**
For testing purposes, we may wish to inspect the last `breadcrumb`. To do so, we provide a `last_breadcrumb` method.
```ruby
# spec/...
describe '#method' do
let(:breadcrumb) { ExceptionNotifier.last_breadcrumb }it 'adds correct message' do
expect(breadcrumb.message).to eq expected_message
endit 'adds correct data' do
expect(breadcrumb.data).to eq expected_data
end
end
```To build a new version, update the `exception_notifier.gempec` with the new version number and run `gem build exception_notifier.gempec`. This will give you a new file in the root folder