It is probably a little off topic but, given that you already had an explanation on how to calculate that integral by Residue theorem, I think that it's worth mentioning the following path using Fourier series in order to calculate that integral, which I report just in case you're interested in.
Assuming first that $a\in(0,1)$. It is obvious that: $$\frac{1}{1-2a\cos(\vartheta)+a^2}=\left|\frac{1}{1-ae^{i\vartheta}}\right|^2,$$
and, by geometric series, we know that: $$\frac{1}{1-ae^{i\vartheta}}=\sum_{n=0}^\infty a^ne^{in\vartheta},$$
so the Fourier coefficients of $$f:\mathbb{T}\rightarrow\mathbb{C}, \vartheta\mapsto\frac{1}{1-ae^{i\vartheta}}$$
are given by: $$\forall n\in\mathbb{Z}, \hat{f}(n)=\begin{cases}
a^n\ \ if \ \ n\ge0\\
0\ \ otherwise
\end{cases}$$
Then, by Plancherel, we get: $$\int_0^{2\pi}\frac{1}{1-2a\cos(\vartheta)+a^2}\operatorname{d}\vartheta=\int_0^{2\pi}|f(\vartheta)|^2\operatorname{d}\vartheta=\\=2\pi\sum_{n=-\infty}^{+\infty}|\hat{f}(n)|^2=2\pi\sum_{n=0}^{+\infty}|a|^{2n}=\frac{2\pi}{1-|a|^2}=\frac{2\pi}{1-a^2}.$$
Then, denoting the unit disk by $D$ and noticing that the functions $$D\rightarrow\mathbb{C}, a\mapsto\frac{2\pi}{1-a^2}$$
and
$$D\rightarrow\mathbb{C}, a\mapsto\int_0^{2\pi}\frac{1}{1-2a\cos(\vartheta)+a^2}\operatorname{d}\vartheta$$
are both analytic and coincide by what we have shown on $(0,1)$, by the identity principle for analytic functions, we get that: $$\forall a\in D, \int_0^{2\pi}\frac{1}{1-2a\cos(\vartheta)+a^2}\operatorname{d}\vartheta=\frac{2\pi}{1-a^2}.$$
With a similar argument you can also address the case $|a|>1$.