evaluate $\int_0^{2\pi} \frac{1}{\cos x + \sin x +2}\, dx $ This is supposed to be a very easy integral, however I cannot get around.
Evaluate:
$$\int_0^{2\pi} \frac{1}{\cos x  + \sin x +2}\, dx$$
What I did is:
$$\int_{0}^{2\pi}\frac{dx}{\cos x + \sin x +2}  = \int_{0}^{2\pi} \frac{dx}{\left ( \frac{e^{ix}-e^{-ix}}{2i}+ \frac{e^{ix}+e^{-ix}}{2} +2\right )}= \oint_{|z|=1} \frac{dz}{iz \left ( \frac{z-z^{-1}}{2i} + \frac{z+z^{-1}}{2}+2 \right )}$$
Although the transformation is correct I cannot go on from the last equation. After calculations in the denominator there still appears $i$ and other equations of that. How can I proceed? 
 A: Note that: $$\frac{1}{iz \left ( \frac{z-z^{-1}}{2i} + \frac{z+z^{-1}}{2}+2 \right )}$$
is a rational function. Write it as a quotient of polynomials, then factor the denominator and apply partial fractions.
If you change the integral to:
$$\int_{-\pi}^{\pi} \frac{1}{\cos x  + \sin x +2}\, dx$$ you can apply the Weierstrass substitution and get:
$$\int_{-\infty}^{\infty} \frac{\frac{2}{1+t^2}}{\frac{1-t^2}{1+t^2}+\frac{2t}{1+t^2}+2}\,dt=\int_{-\infty}^{\infty}\frac{2\,dt}{2+(t+1)^2}\\=\int_{-\infty}^{\infty}\frac{dt}{1+\left(\frac{1+t}{\sqrt 2}\right)^2}$$
Substituting $u=\frac{1+t}{\sqrt{2}}$ gives:
$$=\sqrt{2}\int_{-\infty}^{\infty} \frac{du}{1+u^2}=\sqrt{2}\pi$$
A: Via corindo's rearrangement: we have
$$
I = \int_0^{2 \pi} \frac{1}{\sqrt{2}\cos(x - \pi/4) + 2}\,dx =\\
\frac 1{\sqrt{2}} \int_0^{2 \pi} \frac{1}{\cos(x - \pi/4) + \sqrt{2}}\,dx = \\
\frac 1{\sqrt{2}} \int_0^{2 \pi} \frac{1}{\cos(x) + \sqrt{2}}\,dx =\\
\frac 1{\sqrt{2}} \oint_{|z| = 1} \frac{1}{iz((z + z^{-1})/2 + \sqrt{2})}\,dx = \\
\frac {\sqrt{2}}{i} \oint_{|z| = 1} \frac{1}{(z^2 + 2\sqrt{2}z + 1)}\,dz
$$
Note the integrand has one pole inside the unit circle, namely
$$
z_{0} = 1-\sqrt{2}
$$
