Computing $\int\limits_{-\pi/2}^{\pi/2} \cos(\tan x)\,dx$ 
How to compute $\int\limits_{-\pi/2}^{\pi/2} \cos(\tan x)\,dx$?

I tried the usual Riemann integral method but could not figure out and thought of contour integral and seemed working. But whenever I tried to find the residue at the essential singularity of $f(z)=\cos (\tan z)$ at $\frac{\pm \pi}{2}$, I got stuck there.

HINT:
Let $I$ be the integral given by
$$\begin{align}
\int_{-\pi/2}^{\pi/2}\cos(\tan(x))\,dx&=\int_{-\infty}^\infty \frac{\cos(x)}{1+x^2}\,dx\\\\
&=\text{Re}\left(\int_{-\infty}^\infty \frac{e^{ix}}{x^2+1}\right)\,dx
\end{align}$$
Now, use contour integration by closing the contour in the upper half plane.
SPOILER ALERT:  Scroll over the highlighted area to reveal the solution

Let $J$ be the contour integral of $\frac{e^{iz}}{z^2+1}$ over the closed contour $C$, where $C$ is comprised of $(i)$ the real line from $-R$ to $R$, and $(ii)$ the semicircle in the upper-half plane with radius $R$ and centered at the origin.  Then, $J$ is given by $$\begin{align}J&=\oint_C \frac{e^{iz}}{z^2+1}\,dz\\\\&=\int_{-R}^R \frac{e^{ix}}{x^2+1}\,dx+\int_0^\pi \frac{e^{iRe^{i\phi}}}{R^2e^{i2\phi}+1}\,iRe^{i\phi}\,d\phi\\\\&=2\pi i \text{Res}\left(\frac{e^{iz}}{z^2+1}, z=i\right)\\\\&=2\pi i \frac{e^{-1}}{2i}\\\\&=\frac{\pi}{e}\end{align}$$Taking the limit as $R\to \infty$ and taking the real part shows that $$\int_{-\infty}^\infty \frac{\cos(x)}{x^2+1}\,=\frac{\pi}{e}$$

