How to use complex analysis to find the integral $\int^\pi_{−\pi} \frac 1 {1+\sin^2(\theta)} d\theta$? How can I use complex analysis to solve the following:
$$\int^\pi_{−\pi} \frac 1 {1+\sin^2(\theta)} d\theta$$

Start with
$$
z=e^{i\theta} \\
\log z=i\theta \\
\theta=-i\log z \\
d\theta=-\frac izdz
$$
Now we substitute $z$ into our integral.
$$
\oint\frac{-i}{z(1+\sin^2(-i\log z))}dz \\
$$
Analyzing just the $\sin$ part for a moment:
$$
\begin{align}
\sin(-i\log z)&=-\frac i2\left(e^{i(-i\log z)}-e^{-i(-i\log z)}\right)\\
&=-\frac i2\left(e^{\log z}-e^{-\log z}\right) \\
&=-\frac i2\left(z-\frac 1z\right) \\
&=\frac{i(1-z^2)}{2z}
\end{align}
$$
Now we go back to the integral:
$$
\oint\frac{-i}{z\left(1+\left(\frac{i(1-z^2)}{2z}\right)^2\right)}dz \\
=\oint\frac{-i}{z\left(1-\frac{(1-z^2)^2}{4z^2}\right)}dz \\
=i\oint\frac{1}{\frac{1-6z^2+z^4}{4z}}dz \\
=i\oint\frac{4z}{1-6z^2+z^4}dz
$$
Now we can do partial fraction decomposition on the integrand to expose its poles:
$$
=\frac{i}{2\sqrt{2}}\oint\frac{1}{z-(-1-\sqrt{2})}-\frac{1}{z-(-1+\sqrt{2})}-\frac{1}{z-(1-\sqrt{2})}+\frac{1}{z-(1+\sqrt{2})}dz \\
$$
Two of these poles (the negative ones) are inside the unit circle, our integration contour.  By Cauchy's integral formula, we get the value of the integral:
$$
2\pi i\left(\frac{i}{2\sqrt{2}}(-1-1)\right)=2\pi\frac{-2}{-2\sqrt{2}}=\sqrt{2}\pi
$$
