diff --git a/lib/aww.ex b/lib/aww.ex index 805a8cf..34a3c86 100644 --- a/lib/aww.ex +++ b/lib/aww.ex @@ -218,7 +218,37 @@ defmodule Aww do end end - defp dns_resp(host, opts, timeout) do + defp dns_resp(req_host, opts, timeout) do + start = System.monotonic_time() + + resp = resolve(req_host, opts, timeout) + + finish = System.monotonic_time() + + case resp do + {:ok, ttl, {resp_host, port}} -> + :telemetry.execute( + [:aww, :dns, :resolve, :success], + %{duration: finish - start, ttl: ttl}, + %{ + req_host: req_host, + resp_host: resp_host, + resp_port: port + } + ) + + :error -> + :telemetry.execute( + [:aww, :dns, :resolve, :failed], + %{duration: finish - start}, + %{req_host: req_host} + ) + end + + resp + end + + defp resolve(host, opts, timeout) do with {:ok, msg} <- :inet_res.resolve( to_charlist(host), diff --git a/mix.exs b/mix.exs index b291719..ac2a141 100644 --- a/mix.exs +++ b/mix.exs @@ -56,6 +56,7 @@ defmodule Aww.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ + {:telemetry, "~> 1.0"}, {:ex_doc, ">= 0.0.0", only: [:dev, :test]}, {:stream_data, "~> 1.1", only: [:test]} ] diff --git a/mix.lock b/mix.lock index 8b56acc..9772138 100644 --- a/mix.lock +++ b/mix.lock @@ -6,4 +6,5 @@ "makeup_erlang": {:hex, :makeup_erlang, "1.0.3", "4252d5d4098da7415c390e847c814bad3764c94a814a0b4245176215615e1035", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "953297c02582a33411ac6208f2c6e55f0e870df7f80da724ed613f10e6706afd"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"}, "stream_data": {:hex, :stream_data, "1.2.0", "58dd3f9e88afe27dc38bef26fce0c84a9e7a96772b2925c7b32cd2435697a52b", [:mix], [], "hexpm", "eb5c546ee3466920314643edf68943a5b14b32d1da9fe01698dc92b73f89a9ed"}, + "telemetry": {:hex, :telemetry, "1.4.1", "ab6de178e2b29b58e8256b92b382ea3f590a47152ca3651ea857a6cae05ac423", [:rebar3], [], "hexpm", "2172e05a27531d3d31dd9782841065c50dd5c3c7699d95266b2edd54c2dafa1c"}, }