   @debug_no_body "(no body)"
   @debug_stream "[Elixir.Stream]"
 
-  defp debug(request, {:ok, response}) do
+  defp debug(request, {:ok, response}, opts) do
     [
       "\n>>> REQUEST >>>\n",
       debug_query(request.query),
       ?\n,
-      debug_headers(request.headers),
+      debug_headers(request.headers, opts),
       ?\n,
       debug_body(request.body),
       ?\n,
       "\n<<< RESPONSE <<<\n",
-      debug_headers(response.headers),
+      debug_headers(response.headers, opts),
       ?\n,
       debug_body(response.body)
     ]
   end
 
-  defp debug(request, {:error, error}) do
+  defp debug(request, {:error, error}, opts) do
     [
       "\n>>> REQUEST >>>\n",
       debug_query(request.query),
       ?\n,
-      debug_headers(request.headers),
+      debug_headers(request.headers, opts),
       ?\n,
       debug_body(request.body),
       ?\n,


  defp debug_body(data) when is_binary(data) or is_list(data), do: data
  defp debug_body(term), do: inspect(term)

  defp filter_headers(env, []), do: env

  defp filter_headers(env, filter_headers) when is_list(filter_headers) do
    headers =
      env.headers
      |> Enum.map(fn {key, val} ->
        val = if key in filter_headers, do: "[FILTERED]", else: val
        {key, val}
      end)

    %Tesla.Env{env | headers: headers}
  end

  defp filter_headers(env, _), do: env
end

    Logger.log(level, fn -> Formatter.format(env, response, time, @format) end)

    if Keyword.get(@config, :debug, true) do
      Logger.debug(fn -> debug(env, response, opts) end)
    end

    response
