Example 2. Compute the integral

$$
\int_{|z|=2} \tan z \, dz
$$
Solution. In the region $D:|z|<2$, the function $f(z)=\operatorname{tg} z$ is analytic everywhere except at the points $z=\frac{\pi}{2}$ and $z=-\frac{\pi}{2}$, which are simple poles. All other singular points $z_{k}=\frac{\pi}{2}+k \pi$ of the function $f(z)=\operatorname{tg} z$ lie outside the region $D$ and are therefore not considered.

We have

res $f\left(\frac{\pi}{2}\right)=\left.\frac{\sin z}{(\cos z)^{\prime}}\right|_{z=\pi / 2}=-1, \quad$ res $f\left(-\frac{\pi}{2}\right)=\left.\frac{\sin z}{(\cos z)^{\prime}}\right|_{z=-\pi / 2}=-1$.

Therefore,

$$
\int_{|z|=2} \operatorname{tg} z d z=-4 \pi i
$$