Skip to content

Commit

Permalink
Add duration to request logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nid90 committed Dec 15, 2023
1 parent b9fa358 commit 49db8de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require "hanami/middleware/body_parser"
require "sentry-ruby"
require "rack/jwt/auth"
require "rack/jwt"
require "rack/runtime"
require "./initializers/config"
require "./initializers/sentry_config"
require "./initializers/jwt"
Expand Down Expand Up @@ -127,6 +128,7 @@ class App < Hanami::API

use Rack::Ougai::Logger
use Rack::Ougai::RequestLogger
use Rack::Runtime
use Sentry::Rack::CaptureExceptions
use Hanami::Middleware::BodyParser, :json

Expand Down
5 changes: 3 additions & 2 deletions rack/rack_ougai_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ def call(env)

private

def create_log(env, status, header)
def create_log(env, status, headers)
{
time: Time.now,
remote_addr: env["HTTP_X_FORWARDED_FOR"] || env["REMOTE_ADDR"],
method: env[REQUEST_METHOD],
path: env[PATH_INFO],
query: env[QUERY_STRING],
status: status.to_i
status: status.to_i,
duration: headers["X-Runtime"]
}
end
end
Expand Down

0 comments on commit 49db8de

Please sign in to comment.