Skip to content

Commit

Permalink
chore: add logs message on deprecated routes (#1696)
Browse files Browse the repository at this point in the history
  • Loading branch information
sborrazas committed Mar 12, 2024
1 parent bc10039 commit 4f80b8b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
32 changes: 32 additions & 0 deletions lib/ae_mdw_web/plugs/deprecation_logger_plug.ex
@@ -0,0 +1,32 @@
defmodule AeMdwWeb.Plugs.DeprecationLoggerPlug do
@moduledoc """
Logs useful information to detect deprecated endpoint clients.
"""

alias Plug.Conn
alias AeMdw.Log

require Logger

@updated_prefixes ~w(status v2 v3)

@spec init([]) :: []
def init(opts), do: opts

@spec call(Conn.t(), []) :: Conn.t()
def call(%Conn{path_info: [path_prefix | _rest]} = conn, _opts)
when path_prefix in @updated_prefixes,
do: conn

def call(%Conn{request_path: request_path, remote_ip: remote_ip} = conn, _opts) do
referer =
case Conn.get_req_header(conn, "referer") do
[referer] -> referer
_no_match -> :inet.ntoa(remote_ip)
end

Log.info("[DEPRECATED] request: `#{request_path}`. referer: #{referer}")

conn
end
end
23 changes: 0 additions & 23 deletions lib/ae_mdw_web/plugs/versioning_plug.ex

This file was deleted.

4 changes: 2 additions & 2 deletions lib/ae_mdw_web/router.ex
Expand Up @@ -3,7 +3,7 @@ defmodule AeMdwWeb.Router do
use Plug.ErrorHandler

alias AeMdwWeb.Plugs.StatePlug
alias AeMdwWeb.Plugs.VersioningPlug
alias AeMdwWeb.Plugs.DeprecationLoggerPlug
alias AeMdwWeb.Plugs.JSONFormatterPlug
alias AeMdwWeb.Plugs.RequestSpan
alias AeMdwWeb.Util
Expand Down Expand Up @@ -35,7 +35,7 @@ defmodule AeMdwWeb.Router do
plug JSONFormatterPlug
plug Plug.RequestId
plug RequestSpan
plug VersioningPlug
plug DeprecationLoggerPlug
end

pipeline :browser do
Expand Down

0 comments on commit 4f80b8b

Please sign in to comment.