Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to override config #519

Merged
merged 8 commits into from
Sep 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This is the Ruby library for Rollbar. It will instrument many kinds of Ruby appl
- [Before process hook](#before-process-hook)
- [Transform hook](#transform-hook)
- [The Scope](#the-scope)
- [Override configuration](#override-configuration)
- [Code and context](#code-and-context)
- [Silencing exceptions at runtime](#silencing-exceptions-at-runtime)
- [Sending backtrace without rescued exceptions](#sending-backtrace-without-rescued-exceptions)
Expand Down Expand Up @@ -608,6 +609,37 @@ your_handler = proc do |options|
end
```

## Override configuration

There are some cases where you would need to change the Rollbar configuration for a specific block of code so a new configuration is used on the reported errors in that block. You can use `Rollbar.with_config` to do this. It receives a `Hash` object with the configuration overrides you want to use for the given block. The configuration options to use can be read at [Configuration](https://rollbar.com/docs/notifier/rollbar-gem/configuration/). So the `Hash` passed to `with_config` can be like `{environment: 'specific-environment'}`. Example:

```ruby
Rollbar.with_config(use_async: false) do
begin
# do work that may crash
rescue => e
Rollbar.error(e)
end
end
```

This method looks similar to `Rollbar.scoped` and internally `Rollbar.with_config` uses it. Now `Rollbar.scoped` can receive a second argument with the config overrides for the given block of code. So if you need to set a new payload scope and new config for a code block, you can:

```ruby
scope = {context: 'foo'}
new_config = {framework: 'Sinatra'}

Rollbar.scoped(scope, new_config) do
begin
# do work that may crash
rescue => e
Rollbar.error(e)
end
end
```

In the example from above we are defining a new payload scope and overriding the `framework` configuration for the reported errors inside the given block.

## Code and context

By default we send the following values for each backtrace frame: `filename`, `lineno` and `method`. You can configure Rollbar to additionally send `code` (the actual line of code) and `context` (lines before and after) for each frame.
Expand Down
Loading