Evaluate the integral $\int_0^{\frac{\pi}{2}} \frac{1}{a + \sin^2 \theta}$ using the residue theorem Can someone show me how to compute this integral using the residue theorem: 
$$\int_0^{\frac{\pi}{2}} \frac{1}{a + \sin^2 \theta}d\theta$$

We can simplify the problem by (i) exploiting the even symmetry of the integrand, (ii) using the identity 
$$\sin^2 \theta =\frac{1-\cos 2\theta}{2}$$
and (iii) enforcing the substitution $2\theta \to \theta$.  We can write then write the integral of interest $I(a)$ as
$$I(a)=\frac12 \int_0^{2\pi}\frac{1}{(2a+1)-\cos \theta}d\theta \tag 1$$
Then, we move to the complex plane and letting $z=e^{i\theta}$ find that 
$$I(a) = i\oint_{|z|=1} \frac{1}{z^2-2(2a+1)z+1}dz$$
For $a>0$ ($a<-1$), the only pole enclosed in the unit circle is at
$$z=(2a+1)-2\sqrt{a(a+1)}\,\,\,\,\left(z=(2a+1)+2\sqrt{a(a+1)}\right)$$
Therefore the residue of $\frac{1}{z^2-2(2a+1)z+1}$ is for $a>1$
$$\begin{align}
\lim_{z\to (2a+1)-2\sqrt{a(a+1)}}\left(\frac{z-(2a+1)+2\sqrt{a(a+1)}}{z^2-2(2a+1)z+1}\right)=\frac{1}{-4\sqrt{a(a+1)}}
\end{align}$$
and for $a<-1$
$$\begin{align}
\lim_{z\to (2a+1)+2\sqrt{a(a+1)}}\left(\frac{z-(2a+1)-2\sqrt{a(a+1)}}{z^2-2(2a+1)z+1}\right)=\frac{1}{4\sqrt{a(a+1)}}
\end{align}$$
Putting it all together yields for $a>0$ or $a<-1$
$$\bbox[5px,border:2px solid #C0A000]{I(a)=(2\pi i) i\,\text{sgn(a)}\,\frac{1}{-4\sqrt{a(a+1)}}=\text{sgn}(a)\,\frac{\pi}{2\sqrt{a(a+1)}}}$$
NOTE:
For $-1\le a\le 0$, the integral of interest is divergent.
