Skip to content

Commit

Permalink
Merge pull request #6 from podium/epinault/improve_codenaming
Browse files Browse the repository at this point in the history
chore: improve code naming
  • Loading branch information
dnsbty authored Aug 17, 2021
2 parents 6e9881e + 8c0093b commit 40e1a4a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/uinta/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,7 @@ if Code.ensure_loaded?(Plug) do
start = System.monotonic_time()

Conn.register_before_send(conn, fn conn ->
# Log successful request if path is not filtered based on the sampling pool
# or log all HTTP status >= 300 (usually errors)
if (conn.request_path not in opts.ignored_paths &&
should_log?(opts[:success_log_sampling_ratio])) ||
conn.status >= 300 do
if should_log_request?(conn, opts) do
Logger.log(opts.level, fn ->
stop = System.monotonic_time()
diff = System.convert_time_unit(stop - start, :native, :microsecond)
Expand Down Expand Up @@ -288,7 +284,15 @@ if Code.ensure_loaded?(Plug) do
defp query_type("{" <> _), do: "QUERY"
defp query_type(_), do: nil

defp should_log?(ratio) do
defp should_log_request?(conn, opts) do
# Log successful request if path is not filtered based on the sampling pool
# or log all HTTP status >= 300 (usually errors)
(conn.request_path not in opts.ignored_paths &&
should_include_in_sample?(opts[:success_log_sampling_ratio])) ||
conn.status >= 300
end

defp should_include_in_sample?(ratio) do
random_float() <= ratio
end

Expand Down

0 comments on commit 40e1a4a

Please sign in to comment.