Example 5. Find the extremum of $y=\frac{\sqrt{3} x+1}{\sqrt{x^{2}+1}}+2$.

Translate the above text into English, please retain the original text's line breaks and format, and output the translation result directly.
Solve using trigonometric substitution. Let $x=\operatorname{tg} \theta$, $-\frac{\pi}{2}<\theta<\frac{\pi}{2}$,

we get $y=\frac{\sqrt{3} \operatorname{tg} \theta+1}{\sec \theta}+2=\sqrt{3} \sin \theta+\cos \theta+2=2 \sin \left(\theta+\frac{\pi}{6}\right)+2$, $-\frac{\pi}{2}+\frac{\pi}{6}<\theta<\frac{\pi}{2}+\frac{\pi}{6}$. When $\theta=\frac{\pi}{3}$, $y$ can achieve a maximum value of 4, since $\theta$ takes values in the open interval $\left(-\frac{\pi}{3}, \frac{2\pi}{3}\right)$, there are no other extremum values.

If the range of $\theta$ is not restricted, maintaining a one-to-one correspondence between $\operatorname{tg} \theta$ and $x$, it might lead to the incorrect conclusion that the minimum value of $y$ is 0 from $y=2 \sin \left(\theta+\frac{\pi}{6}\right)+2$.

In comprehensive trigonometric problems, these constraints often bring some inconvenience, which can increase the difficulty of solving problems. However, these constraints also confine the problem to a specific range, which can sometimes be beneficial to our problem-solving.