Calculation of $ \int_0^{2\pi} \frac{\sqrt{a^2+2a\cos\theta+1}}{(a\cos\theta+1)^2} d\theta $ This integral formula came from the calculation in the spherical coordinate. Here, $a$ is a real number greater than 1.
$$ I = \int_0^{2\pi} \frac{\sqrt{a^2+2a\cos\theta+1}}{(a\cos\theta+1)^2}d\theta $$
Since $a^2+2a\cos\theta+1=\mathrm{Re}(a+e^{i\theta})(a+e^{-i\theta})$ and $a\cos\theta+1=\mathrm{Re}(ae^{i\theta}+1)$, the integration becomes
$$ I = \mathrm{Re}\int_0^{2\pi} \frac{\sqrt{(a+e^{i\theta})(a+e^{-i\theta})}}{(ae^{i\theta}+1)^2}d\theta. $$
Substitution $z=e^{i\theta}$ yields
$$ I = \mathrm{Re}\oint_C \frac{\sqrt{(a+z)(a+1/z)}}{iz(az+1)^2}dz, $$
where $C$ is an unit circle centered at the origin.
At this moment, I tried to decompose the integrand into partial fractions and to use Cauchy's integral formula, but the numerator of integrand, $\sqrt{(a+z)(a+1/z)}$, is not continuous on $C$ because of the multivaluedness of complex square root. How can I approach to the next step?
 A: As mentioned by Felix Marin in comments, the integral diverges for $a\ge1$. However we shall verify ComplexYetTrivial's claim that $I=\frac{4E(a^2)}{1-a^2}$ if $a\in[0,1)$. Elliptic integrals follow Mathematica/mpmath conventions in this answer.
Using Byrd and Friedman 289.09:
$$I=\int_0^{2\pi}\frac{\sqrt{a^2+2a\cos\theta+1}}{(a\cos\theta+1)^2}\,d\theta=2\int_0^\pi\frac{a^2+1+2a\cos\theta}{(a\cos\theta+1)^2}\frac1{\sqrt{a^2+1+2a\cos\theta}}\,d\theta\newcommand{sn}{\operatorname{sn}}$$
$$=\frac4{a+1}\int_0^{K(m=4a/(a+1)^2)}\frac{a^2+1+2a(1-2\sn^2u)}{(a(1-2\sn^2u)+1)^2}\,du$$
$$=\frac4{(a+1)^2}\int_0^{K(m)}\left(\frac{a-1}{(1-\frac{2a}{a+1}\sn^2u)^2}+\frac2{1-\frac{2a}{a+1}\sn^2u}\right)\,du$$
Now using B&F 336.01 and .02:
$$\int_0^\varphi\frac1{1-n\sn^2u}\,du=\Pi(n,\varphi,m)$$
$$\int_0^\varphi\frac1{(1-n\sn^2u)^2}\,du=\frac1{2(n-1)(m-n)}\left(nE(\varphi,m)+(m-n)F(\varphi,m)+(2mn+2n-n^2-3m)\Pi(n,\varphi,m)-\frac{n^2\sn u\operatorname{cn}u\operatorname{dn}u}{1-n\sn^2u}\right)$$
we get after much simplification (note that $\varphi=\pi/2$ here)
$$I=2\left(\frac{K(m)}{a+1}-\frac{E(m)}{a-1}\right)$$
which is in turn simplified by a Gauss transformation to
$$I=\frac{4E(a^2)}{1-a^2}$$
