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

Add before_process and transform hooks #375

Merged
merged 11 commits into from
Feb 15, 2016
Merged

Conversation

jondeandres
Copy link
Contributor

No description provided.

Jon de Andres added 5 commits February 2, 2016 10:50
Customers can define a list of handler that will be called before
processing the report:

handler = proc do |options|
  if some_calc(options)
    raise Rollbar::Ignore
  end
end

config.before_process << handler

or

config.before_process = handler

The received options is a Hash object with this data:

options = {
  :level => level,
  :scope => configuration.payload_options,
  :exception => exception,
  :message => message,
  :extra => extra
}
With this change users can define a series of method that will receive:

- scope
- level
- exception
- message
- payload

Users can mutate the payload and do everything they want to do
Instead, swallow exceptions and log with 'error' level
@jondeandres jondeandres force-pushed the jon/5752/filter-function branch 4 times, most recently from 103aba4 to 9e6ff51 Compare February 3, 2016 10:06
@brianr
Copy link
Member

brianr commented Feb 10, 2016

@jondeandres It seems that the :scope is empty/missing in both the before_process and transform hooks. Repro case:

handler1 = proc do |options|
  puts "+++ in handler1"
  puts options
  puts options[:scope][:custom][:some_key]
  puts "+++"
end

handler2 = proc do |options|
  puts "--- in handler2"
  puts options
  puts "---"
end

Rollbar.configure do |config|
  config.access_token = 'token'
  config.before_process << handler1
  config.transform << handler2
end

Rollbar.scope(:custom => {:some_key => "some value"}).debug("a debug message")

When I do the above, the output is:

+++ in handler1
{:level=>"debug", :scope=>{}, :exception=>nil, :message=>"a debug message", :extra=>nil}
E, [2016-02-10T13:45:17.817247 #20761] ERROR -- : [Rollbar] Error calling the `before_process` hook: undefined method `[]' for nil:NilClass
--- in handler2
{:level=>"debug", :scope=>{}, :exception=>nil, :message=>"a debug message", :extra=>nil, :payload=>{"access_token"=>"token", "data"=>{:timestamp=>1455140717, :environment=>"unspecified", :level=>"debug", :language=>"ruby", :framework=>"Plain", :server=>{:host=>"Brians-MacBook-Pro-2.local", :pid=>20761}, :notifier=>{:name=>"rollbar-gem", :version=>"2.7.1"}, :body=>{:message=>{:body=>"a debug message"}}, :uuid=>"f74b9e4f-a144-4b3d-9b6c-6270efd1b0f5", :custom=>{:some_key=>"some value"}}}}
---
I, [2016-02-10T13:45:17.817682 #20761]  INFO -- : [Rollbar] Scheduling payload
I, [2016-02-10T13:45:17.817715 #20761]  INFO -- : [Rollbar] Sending payload
I, [2016-02-10T13:45:18.580879 #20761]  INFO -- : [Rollbar] Success
I, [2016-02-10T13:45:18.580976 #20761]  INFO -- : [Rollbar] Details: https://rollbar.com/instance/uuid?uuid=f74b9e4f-a144-4b3d-9b6c-6270efd1b0f5 (only available if report was successful)

@jondeandres
Copy link
Contributor Author

@brianr the interface to access the scope is options[:scope].custom in that case. But using [] shouldn't give that behavior. I'll review this.

@jondeandres
Copy link
Contributor Author

Forget it, it's a bug yes. I'm passing there configuration.payload_options instead of the scope_object. I'll fix it.

@jondeandres
Copy link
Contributor Author

@brianr I've fixed and changed the interface in 3428eb1.

I think it'd be better if the users can access the scope as you wanted, scope[:request] instead of scope.request, since the scope is defined like Rollbar.scoped(request: some_data).

jondeandres added a commit that referenced this pull request Feb 15, 2016
Add before_process and transform hooks
@jondeandres jondeandres merged commit 1e58e49 into master Feb 15, 2016
@jondeandres jondeandres deleted the jon/5752/filter-function branch February 15, 2016 10:50
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.

2 participants