API endpoints logger

pull/4998/head
Viktor Baranov 3 years ago
parent 88f5ac6d73
commit 81df52787c
  1. 1
      CHANGELOG.md
  2. 5
      apps/block_scout_web/config/dev.exs
  3. 6
      apps/block_scout_web/config/prod.exs
  4. 19
      apps/block_scout_web/lib/block_scout_web/controllers/api/api_logger.ex
  5. 2
      apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/rpc_translator.ex
  6. 4
      apps/block_scout_web/lib/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller.ex
  7. 4
      apps/block_scout_web/lib/block_scout_web/controllers/api/v1/health_controller.ex
  8. 2
      apps/block_scout_web/lib/block_scout_web/controllers/api/v1/supply_controller.ex
  9. 4
      apps/block_scout_web/lib/block_scout_web/controllers/api/v1/verified_smart_contract_controller.ex
  10. 2
      apps/explorer/mix.exs
  11. 3
      config/config.exs
  12. 2
      mix.exs

@ -14,6 +14,7 @@
- [#4888](https://github.com/blockscout/blockscout/pull/4888) - Fix fetch_top_tokens method: add nulls last for token holders desc order - [#4888](https://github.com/blockscout/blockscout/pull/4888) - Fix fetch_top_tokens method: add nulls last for token holders desc order
### Chore ### Chore
- [#4998](https://github.com/blockscout/blockscout/pull/4998) - API endpoints logger
## 4.0.0-beta ## 4.0.0-beta

@ -78,6 +78,11 @@ config :logger, :block_scout_web,
level: :debug, level: :debug,
path: Path.absname("logs/dev/block_scout_web.log") path: Path.absname("logs/dev/block_scout_web.log")
config :logger, :api,
level: :debug,
path: Path.absname("logs/dev/api.log"),
metadata_filter: [fetcher: :api]
# Set a higher stacktrace during development. Avoid configuring such # Set a higher stacktrace during development. Avoid configuring such
# in production as building large stacktraces may be expensive. # in production as building large stacktraces may be expensive.
config :phoenix, :stacktrace_depth, 20 config :phoenix, :stacktrace_depth, 20

@ -33,3 +33,9 @@ config :logger, :block_scout_web,
level: :info, level: :info,
path: Path.absname("logs/prod/block_scout_web.log"), path: Path.absname("logs/prod/block_scout_web.log"),
rotate: %{max_bytes: 52_428_800, keep: 19} rotate: %{max_bytes: 52_428_800, keep: 19}
config :logger, :api,
level: :debug,
path: Path.absname("logs/prod/api.log"),
metadata_filter: [fetcher: :api],
rotate: %{max_bytes: 52_428_800, keep: 19}

@ -0,0 +1,19 @@
defmodule APILogger do
@moduledoc """
Logger of API ednpoins usage
"""
require Logger
def log(conn) do
endpoint =
if conn.query_string do
"#{conn.request_path}?#{conn.query_string}"
else
conn.request_path
end
Logger.debug(endpoint,
fetcher: :api
)
end
end

@ -14,6 +14,7 @@ defmodule BlockScoutWeb.API.RPC.RPCTranslator do
""" """
require Logger require Logger
require APILogger
import Plug.Conn import Plug.Conn
import Phoenix.Controller, only: [put_view: 2] import Phoenix.Controller, only: [put_view: 2]
@ -29,6 +30,7 @@ defmodule BlockScoutWeb.API.RPC.RPCTranslator do
{:ok, action} <- translate_action(action), {:ok, action} <- translate_action(action),
true <- action_accessed?(action, write_actions), true <- action_accessed?(action, write_actions),
{:ok, conn} <- call_controller(conn, controller, action) do {:ok, conn} <- call_controller(conn, controller, action) do
APILogger.log(conn)
conn conn
else else
{:error, :no_action} -> {:error, :no_action} ->

@ -1,10 +1,14 @@
defmodule BlockScoutWeb.API.V1.DecompiledSmartContractController do defmodule BlockScoutWeb.API.V1.DecompiledSmartContractController do
use BlockScoutWeb, :controller use BlockScoutWeb, :controller
require APILogger
alias Explorer.Chain alias Explorer.Chain
alias Explorer.Chain.Hash.Address alias Explorer.Chain.Hash.Address
def create(conn, params) do def create(conn, params) do
APILogger.log(conn)
if auth_token(conn) == actual_token() do if auth_token(conn) == actual_token() do
with {:ok, hash} <- validate_address_hash(params["address_hash"]), with {:ok, hash} <- validate_address_hash(params["address_hash"]),
:ok <- Chain.check_address_exists(hash), :ok <- Chain.check_address_exists(hash),

@ -1,9 +1,13 @@
defmodule BlockScoutWeb.API.V1.HealthController do defmodule BlockScoutWeb.API.V1.HealthController do
use BlockScoutWeb, :controller use BlockScoutWeb, :controller
require APILogger
alias Explorer.Chain alias Explorer.Chain
def health(conn, _) do def health(conn, _) do
APILogger.log(conn)
with {:ok, number, timestamp} <- Chain.last_db_block_status(), with {:ok, number, timestamp} <- Chain.last_db_block_status(),
{:ok, cache_number, cache_timestamp} <- Chain.last_cache_block_status() do {:ok, cache_number, cache_timestamp} <- Chain.last_cache_block_status() do
send_resp(conn, :ok, result(number, timestamp, cache_number, cache_timestamp)) send_resp(conn, :ok, result(number, timestamp, cache_number, cache_timestamp))

@ -1,9 +1,11 @@
defmodule BlockScoutWeb.API.V1.SupplyController do defmodule BlockScoutWeb.API.V1.SupplyController do
use BlockScoutWeb, :controller use BlockScoutWeb, :controller
require APILogger
alias Explorer.Chain alias Explorer.Chain
def supply(conn, _) do def supply(conn, _) do
APILogger.log(conn)
total_supply = Chain.total_supply() total_supply = Chain.total_supply()
circulating_supply = Chain.circulating_supply() circulating_supply = Chain.circulating_supply()

@ -1,11 +1,15 @@
defmodule BlockScoutWeb.API.V1.VerifiedSmartContractController do defmodule BlockScoutWeb.API.V1.VerifiedSmartContractController do
use BlockScoutWeb, :controller use BlockScoutWeb, :controller
require APILogger
alias Explorer.Chain alias Explorer.Chain
alias Explorer.Chain.Hash.Address alias Explorer.Chain.Hash.Address
alias Explorer.SmartContract.Solidity.Publisher alias Explorer.SmartContract.Solidity.Publisher
def create(conn, params) do def create(conn, params) do
APILogger.log(conn)
with {:ok, hash} <- validate_address_hash(params["address_hash"]), with {:ok, hash} <- validate_address_hash(params["address_hash"]),
:ok <- Chain.check_address_exists(hash), :ok <- Chain.check_address_exists(hash),
{:contract, :not_found} <- {:contract, Chain.check_verified_smart_contract_exists(hash)} do {:contract, :not_found} <- {:contract, Chain.check_verified_smart_contract_exists(hash)} do

@ -104,7 +104,7 @@ defmodule Explorer.Mixfile do
# `:spandex` tracing of `:ecto` # `:spandex` tracing of `:ecto`
{:spandex_ecto, "~> 0.6.2"}, {:spandex_ecto, "~> 0.6.2"},
# Attach `:prometheus_ecto` to `:ecto` # Attach `:prometheus_ecto` to `:ecto`
{:telemetry, "~> 0.4.1"}, {:telemetry, "~> 0.4.3"},
# `Timex.Duration` for `Explorer.Counters.AverageBlockTime.average_block_time/0` # `Timex.Duration` for `Explorer.Counters.AverageBlockTime.average_block_time/0`
{:timex, "~> 3.7.1"}, {:timex, "~> 3.7.1"},
{:con_cache, "~> 1.0"}, {:con_cache, "~> 1.0"},

@ -31,7 +31,8 @@ config :logger,
{LoggerFileBackend, :token_instances}, {LoggerFileBackend, :token_instances},
{LoggerFileBackend, :reading_token_functions}, {LoggerFileBackend, :reading_token_functions},
{LoggerFileBackend, :pending_transactions_to_refetch}, {LoggerFileBackend, :pending_transactions_to_refetch},
{LoggerFileBackend, :empty_blocks_to_refetch} {LoggerFileBackend, :empty_blocks_to_refetch},
{LoggerFileBackend, :api}
] ]
config :logger, :console, config :logger, :console,

@ -11,7 +11,7 @@ defmodule BlockScout.Mixfile do
apps_path: "apps", apps_path: "apps",
deps: deps(), deps: deps(),
dialyzer: dialyzer(), dialyzer: dialyzer(),
elixir: "~> 1.10", elixir: "~> 1.12",
preferred_cli_env: [ preferred_cli_env: [
credo: :test, credo: :test,
dialyzer: :test dialyzer: :test

Loading…
Cancel
Save