Skip to content

Commit

Permalink
Better: Allow to pass before/after blocks for middleware with rails. (#…
Browse files Browse the repository at this point in the history
…15)

* Better: Allow to pass before/after blocks for middleware with rails.

* Add example config in the README
  • Loading branch information
ylecuyer authored and elhu committed May 23, 2019
1 parent 13836a1 commit 467fcf1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ config.peastash.enabled = true
# You can also configure Peastash from here, for example:
config.peastash.output = Peastash::Outputs::IO.new(File.join(Rails.root, 'log', "logstash_#{Rails.env}.log"))
config.peastash.source = Rails.application.class.parent_name
config.peastash.before_block = ->(env, response) { Peastash.with_instance.store[:path] = Rack::Request.new(env).path }
config.peastash.after_block = ->(env, response) { Peastash.with_instance.store[:puma_wait] = env['puma.request_body_wait'] }
```

By default, Peastash's Rails integration will log the same parameters as the Middleware version, plus the fields in the payload of the [``process_action.action_controller``](http://edgeguides.rubyonrails.org/active_support_instrumentation.html#process_action.action_controller) notification (except the params).
Expand Down
2 changes: 1 addition & 1 deletion lib/peastash/rails_ext/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Railtie < ::Rails::Railtie
Peastash.with_instance.store.merge!(payload) { |key, old_val, new_val| old_val }
end
before_middleware = app.config.peastash[:insert_before] || ActionDispatch::ShowExceptions
app.config.middleware.insert_before before_middleware, Peastash::Middleware
app.config.middleware.insert_before before_middleware, Peastash::Middleware, app.config.peastash[:before_block], app.config.peastash[:after_block]
end
end
end
Expand Down

0 comments on commit 467fcf1

Please sign in to comment.