Example 9 Given a positive integer $n$. Find the smallest positive number $\lambda$, such that for any $\theta_{i} \in\left(0, \frac{\pi}{2}\right)(i=1,2, \cdots, n)$, as long as
$$
\tan \theta_{1} \cdot \tan \theta_{2} \cdots \cdot \tan \theta_{n}=2^{\frac{n}{2}},
$$

then
$$
\cos \theta_{1}+\cos \theta_{2}+\cdots+\cos \theta_{n} \leqslant \lambda .
$$
When $n=1$,
$$
\cos \theta_{1}=\left(1+\tan ^{2} \theta_{1}\right)^{-\frac{1}{2}}=\frac{\sqrt{3}}{3}, \lambda=\frac{\sqrt{3}}{3} \text {. }
$$

Assume $n \geqslant 2$. Let $x_{i}=\tan ^{2} \theta_{i}(1 \leqslant i \leqslant n)$, then the given condition becomes
$$
x_{1} x_{2} \cdots x_{n}=2^{n} \text {. }
$$

We need to find the smallest $\lambda$ such that
$$
\sum \frac{1}{\sqrt{1+x_{i}}} \leqslant \lambda \text {. }
$$

Without loss of generality, assume $x_{1}, x_{2}, \cdots, x_{n}$ with $x_{1}$ being the largest, then from equation (3) we have $x_{1} \geqslant 2$.

If $x_{2} \geqslant 2$, then it is exactly the same as the case $y \geqslant 2$ in Example 7 (where $x$ is $x_{1}$ and $y$ is $x_{2}$), we can conclude that $\sum \frac{1}{\sqrt{1+x_{i}}} = \varphi(x_{2})$ is decreasing. Thus, we can decrease $x_{2}$ until $x_{2}=2$, at which point $\varphi(x_{2})$ keeps increasing. Similarly, we can assume $x_{3} \leqslant 2$, $x_{4} \leqslant 2, \cdots, x_{n} \leqslant 2$. By the case $y \leqslant 2$ in Example 7, we can gradually adjust so that $x_{2}, x_{3}, \cdots, x_{n}$ are all adjusted to $\left(\frac{2^{n}}{x_{1}}\right)^{\frac{1}{n-1}}$. Therefore, we only need to find the smallest $\lambda$ such that
$$
g(y)=\frac{1}{\sqrt{1+x}}+\frac{n-1}{\sqrt{1+y}} \leqslant \lambda,
$$

where $x \geqslant 2 \geqslant y, x y^{n-1}=2^{n}$.
$$
\begin{array}{c}
g^{\prime}(y)=\frac{-(n-1)}{2(1+y)^{\frac{3}{2}}}+\frac{1}{2(1+x)^{\frac{3}{2}}} \cdot \frac{(n-1) 2^{n}}{y^{n}} \\
=\frac{n-1}{2 y}\left[\frac{x}{\sqrt{(1+x)^{3}}}-\frac{y}{\sqrt{(1+y)^{3}}}\right] .
\end{array}
$$
$g(y)$ is increasing $\Leftrightarrow g^{\prime}(y) \geqslant 0$
$$
\begin{array}{l}
\Leftrightarrow \frac{x^{2}}{(1+x)^{3}} \geqslant \frac{y^{2}}{(1+y)^{3}} \\
\Leftrightarrow x^{2}(1+y)^{3}-y^{2}(1+x)^{3} \geqslant 0 . \\
\text { When } n=2 \text {, } x y=2^{2}, \\
y^{2}\left[x^{2}(1+y)^{3}-y^{2}(1+x)^{3}\right] \\
=4^{2}(1+y)^{3}-y(y+4)^{3} \\
=(2+y)(2-y)^{3} \geqslant 0 .
\end{array}
$$

When $n=2$, $x y=2^{2}$,
$$
\begin{array}{l}
y^{2}\left[x^{2}(1+y)^{3}-y^{2}(1+x)^{3}\right] \\
=4^{2}(1+y)^{3}-y(y+4)^{3} \\
=(2+y)(2-y)^{3} \geqslant 0 .
\end{array}
$$

Therefore, $g(y)$ is increasing.
Thus, the maximum value is $g(2)=\frac{2}{\sqrt{3}}$, i.e., $\lambda=\frac{2}{\sqrt{3}}$.
When $n \geqslant 3$, $x y^{n-1}=2^{n}$,
$$
\begin{array}{l}
y^{3 n-5}\left[x^{2}(1+y)^{3}-y^{2}(1+x)^{3}\right] \\
=2^{2 n} y^{n-3}(1+y)^{3}-\left(y^{n-1}+2^{n}\right)^{3} \\
=\left(2^{n}-y^{n}\right)\left(y^{2 n-3}+2^{n} y^{n-3}+3 \times 2^{n} y^{n-2}-2^{2 n}\right) \\
\leqslant\left(2^{n}-y^{n}\right)\left(2^{2 n-3}+2^{2 n-3}+3 \times 2^{2 n-2}-2^{2 n}\right) \\
=0 .
\end{array}
$$

Therefore, $g(y)$ is decreasing.
When $y \rightarrow 0$, $g(y) \rightarrow n-1$, i.e., $\lambda=n-1$.