diff --git a/README.md b/README.md index 381eb01..322b6d2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_1147 TILs and counting..._ +_1148 TILs and counting..._ --- @@ -910,6 +910,7 @@ _1147 TILs and counting..._ - [Identify Outdated Gems](ruby/identify-outdated-gems.md) - [If You Detect None](ruby/if-you-detect-none.md) - [Iterate With An Offset Index](ruby/iterate-with-an-offset-index.md) +- [Include Extra Context In A Honeybadger Notify](ruby/include-extra-context-in-a-honeybadger-notify.md) - [Ins And Outs Of Pry](ruby/ins-and-outs-of-pry.md) - [Invoking Rake Tasks Multiple Times](ruby/invoking-rake-tasks-multiple-times.md) - [IRB Has Built-In Benchmarking With Ruby 3](ruby/irb-has-built-in-benchmarking-with-ruby-3.md) diff --git a/ruby/include-extra-context-in-a-honeybadger-notify.md b/ruby/include-extra-context-in-a-honeybadger-notify.md new file mode 100644 index 0000000..a79c75c --- /dev/null +++ b/ruby/include-extra-context-in-a-honeybadger-notify.md @@ -0,0 +1,33 @@ +# Include Extra Context In A Honeybadger Notify + +The simplest way to `notify` [Honeybadger](https://www.honeybadger.io/) of an +error is to either pass it the exception directly: + +```ruby +rescue SpecializedError => e + Honeybadger.notify(e) +end +``` + +Or to give it a custom message: + +```ruby +Honeybadger.notify("The user #{user.id} was unable to access their account.") +``` + +Honeybadger collects a lot of additional context about the report based on +where it is called. More context is usually better though. You can pass +additional, specific context with the `context` keyword argument. + +```ruby +message = "The user was unable to access their account." +Honeybadger.notify( + message, + context: { user_id: user.id, query: params[:query] } +) +``` + +Include whatever else you might want to know and those values will show up in +the Honeybadger web interface. + +[source](https://docs.honeybadger.io/lib/ruby/getting-started/reporting-errors/)