How to evaluate $\int _{0}^{\frac{\pi}{2}} \frac{\mathrm dx}{a+\cos x}$ using contour integration? 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?

I doubt you can use contour integration to handle this since you can't obtain a closed curve. Noting
$$ \cos x=\frac{1-\tan^2(\frac x2)}{1+\tan^2(\frac x2)}$$
one has, under $\tan(\frac x2)\to t$,
\begin{eqnarray}
&&\int _{0}^{\frac{\pi}{2}} \dfrac{\mathrm dx}{a+\cos x} \\
&=&\int _{0}^{\frac{\pi}{2}} \dfrac{\mathrm dx}{a+\frac{1-\tan^2(\frac x2)}{1+\tan^2(\frac x2)}} \\
&=&\int _{0}^{\frac{\pi}{2}} \dfrac{(1+\tan^2(\frac x2))\mathrm dx}{a(1+\tan^2(\frac x2))+1-\tan^2(\frac x2)} \\
&=&\int _{0}^{\frac{\pi}{2}} \dfrac{(1+\tan^2(\frac x2))\mathrm dx}{(a+1)+(a-1)\tan^2(\frac x2))} \\
&=&\int_0^1\frac{2}{(a+1)+(a-1)t^2}\mathrm dt\\
&=&\frac2{\sqrt{a^2-1}}\arctan\bigg(\sqrt{\frac{a-1}{a+1}}\bigg).
\end{eqnarray}
