I want to evaluate:
$\displaystyle \int _{0}^{\frac{\pi}{2}} \dfrac{\mathrm dx}{a+\cos x} \tag*{}$
With my basic knowledge of Cauchy Residue theorem: \begin{align*} \int_0^{\frac{\pi}{2}} \frac{\mathrm dx}{a + \cos x} &= \int_0^{\frac{\pi}{2}}\frac{\mathrm dx}{a + \frac{e^{ix} + e^{-ix}}{2}} \\ &= 2\int_0^{\frac{\pi}{2}} \frac{e^{ix} \ \mathrm dx}{2ae^{ix} + e^{2ix} + 1} && \text{Let } z=e^{ix}, \text{ so } \mathrm dz = ie^{ix} \ \mathrm dx. \\ &= \frac{2}{i} \int_{|z|=1} \frac{\mathrm dz}{z^2 + 2az + 1} \\ &= \frac{2}{i} \int_{|z|=1} \frac{\mathrm dz}{(z-z_1)(z-z_2)} \end{align*} where the circle $|z|=1$
My problem is how to proceed further from here? How do I draw circle? Clockwise or Counterclockwise?
Your substitution gives$$\begin{align}\int_1^i\frac{-2idz}{(z+a)^2+1-a^2}&=\left[\frac{-2i}{\sqrt{1-a^2}}\arctan\frac{z+a}{\sqrt{1-a^2}}\right]_1^i\\&=\frac{2}{\sqrt{1-a^2}}\operatorname{artanh}\sqrt{\frac{1-a}{1+a}}.\end{align}$$It's technically a contour integral; it's just the contour isn't closed, so it's a "normal" integration evaluation technique, rather than one using the residue theorem. As for how the last $=$ works, I'll leave you to work through the trigonometric identities.