Trying to find the integral $$\int_0^\pi\frac{d\theta}{(2+\cos\theta)^2}$$ by complex analysis.
I let $z = \exp(i\theta)$, $dz = i \exp(i\theta)d\theta$, so $ d\theta=\dfrac{dz}{iz}$. I am trying therefore to find the integral $$\frac{1}{2iz} \oint_C \frac{dz}{\left(2 + \frac{z}{2} + \frac{1}{2z}\right)^2}$$ I am unsure of which contour I should use, and how to proceed besides that. Could anyone help?
First note that
$$\int_0^\pi \frac{d\theta}{(2+\cos \theta)^2} = \frac12 \int_{-\pi}^\pi \frac{d\theta}{(2+\cos \theta)^2}.$$
Then use the same substitution as the one you tried. You get your contour for free. (If $\theta$ varies from $-\pi$ to $\pi$, then $e^{i\theta}$ will cover the unit circle exactly once.)
Finally, clear the fractions, find the poles, and compute the residues for the poles that are inside the unit circle.