Created
August 29, 2014 06:09
-
-
Save dnd/f250a6c0cde8e79f9b20 to your computer and use it in GitHub Desktop.
Grape ActiveSupport Instrumentation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Logger | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
payload = { | |
remote_addr: env['REMOTE_ADDR'], | |
request_method: env['REQUEST_METHOD'], | |
request_path: env['PATH_INFO'], | |
request_query: env['QUERY_STRING'] | |
} | |
ActiveSupport::Notifications.instrument "request.api", payload do | |
@app.call(env).tap do |response| | |
payload[:params] = env["api.endpoint"].params.to_hash | |
payload[:params].delete("route_info") | |
payload[:params].delete("format") | |
payload[:response_status] = response[0] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment