Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/givelively/gl_exception_notifier
Exception Notification wrapper
https://github.com/givelively/gl_exception_notifier
Last synced: 9 days ago
JSON representation
Exception Notification wrapper
- Host: GitHub
- URL: https://github.com/givelively/gl_exception_notifier
- Owner: givelively
- License: apache-2.0
- Created: 2024-05-28T23:42:30.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-01-06T16:33:06.000Z (19 days ago)
- Last Synced: 2025-01-06T17:40:19.630Z (19 days ago)
- Language: Ruby
- Size: 81.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Give Lively 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/).
`GLExceptionNotifier` 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)
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'gl_exception_notifier'
```And then execute:
$ bundle install
Or install it yourself as:
$ gem install gl_exception_notifier
## Usage
`GLExceptionNotifier` supports the following:
### Record an Exception
Capture exceptions with the call method.
```ruby
begin
raise StandardError
rescue StandardError => error
GLExceptionNotifier.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
GLExceptionNotifier.add_context(:tags_context, my_tag: my_tag_value)# add user info to the context
GLExceptionNotifier.add_context(:user_context, user_id: user_id)# add extra info to the context
GLExceptionNotifier.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
GLExceptionNotifier.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) { GLExceptionNotifier.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
```