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

Extend Exception Level Filter configuration to accept lambda applied to all exceptions #1125

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

malkovro
Copy link

@malkovro malkovro commented Apr 4, 2023

Description of the change

Exception level filters configuration allows to specify level (directly or through a lambda) for explicit class names but we reach a limit when using inheritance or more generally want the level to be determined by a lambda for distinct exception classes without having to go through declaring each single classes in the configuration.

class UnmonitoredError < StandardError; end
class SpecificUnmonitoredError < UnmonitoredError; end

Rollbar.configure do |config|
  config.exception_level_filters.merge!('UnmonitoredError' => 'ignored')
end

Rollbar.error(SpecificUnmonitoredError.new("Boom"), :use_exception_level_filters => true)
# => Actually reported error 😢

With this change we could get this to work

class UnmonitoredError < StandardError; end
class SpecificUnmonitoredError < UnmonitoredError; end

Rollbar.configure do |config|
  config.exception_level_filter = lambda { |exception|
    'ignored' if exception.is_a? UnmonitoredError
  }
end

Rollbar.error(SpecificUnmonitoredError.new("Boom"), :use_exception_level_filters => true)
# => 'ignored'

This change is basic and just add another configuration, it could be interesting to have the exception_level_filter chainable similarly to how the current implementation uses the .merge! to add behaviour without resetting the entire configuration but this is probably for another iteration...

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Maintenance
  • New release

Related issues

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers assigned
  • Issue from task tracker has a link to this pull request
  • Changes have been reviewed by at least one other engineer

@malkovro malkovro changed the title Feature/extend filter configuration Extend Exception Level Filter configuration to accept lambda applied to all exceptions Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant