Trigonometry substitution issue with sign

When you make the substitution $x=2\tan \theta$, you have to be careful to specify the domain of $\theta$: the substitution is only valid if $\theta$ has a small enough domain for $\tan \theta$ to be continuous. The simplest possible choice of domain is probably $-\frac{\pi}{2} < \theta < \frac{\pi}{2}$. Note that the range of $2\tan \theta$ on this domain is the entire real line, so taking $\theta$ in this domain doesn't lose any generality.

But when $-\frac{\pi}{2} < \theta < \frac{\pi}{2}$, we always have $\sec \theta > 0$. So in fact, if you make this choice of domain, it is always true that $2 \sec \theta=\sqrt{x^2+4}$, without any sign issues.

It's instructive to think about what happens if you choose a different domain for $\theta$. If $\sec \theta > 0$ on that domain, nothing will change. If $\sec \theta < 0$ on that domain, then

$$\int \frac{dx}{\sqrt{x^2+4}}=\int \frac{\sec^2 \theta \,d\theta}{-\sec \theta}=-\int \sec \theta \,d\theta $$

because $\sqrt{x^2+4}$ is still positive. So the integral in terms of $\theta$ evaluates to $-\ln|\sec \theta +\tan \theta|+C$. Then, when we rewrite in terms of $x$, we again have $\sec \theta=-\sqrt{x^2+4}$, so the integral in terms of $x$ is

$$-\ln\left|-\sqrt{x^2+4}+x\right|+C=-\ln\left(\sqrt{x^2+4}-x\right) +C\, ,$$

because $\sqrt{x^2+4} > x$ for all $x$.

But then

\begin{align*} -\ln\left(\sqrt{x^2+4}-x\right)&=\ln\left(\frac{1}{\sqrt{x^2+4}-x}\right)\\ &=\ln\left(\frac{\sqrt{x^2+4}+x}{(\sqrt{x^2+4})^2-x^2}\right)&\text{(multiplying by the conjugate)}\\ &=\ln\frac{\sqrt{x^2+4}+x}{4}\\ &=\ln(\sqrt{x^2+4}+x)-\ln 4 \, . \end{align*}

So we get the nearly same result whatever domain we choose, but the constant term may be different.