Even another view on this technique could be provided via Euler substitutions. What there appeared, especially in final crucial step, was $x + u$ in the denominator, so why from the beggining assume the substitution :
$$\sqrt{a^2 + x^2} = u - x$$
Squaring both sides :
$$a^2 = u^2-2ux$$ and taking differential
$$u\mathrm{d}x=(u-x)\mathrm{d}u$$ hence
$$I = \int \frac{\mathrm{d}x}{\sqrt{a^2+x^2}} = \int \frac{(u-x)\mathrm{d}u}{(u-x)u} = \int \frac{\mathrm{d}u}{u} = \ln |u| +C = \ln\left(x+\sqrt{a^2+x^2}\right) +C $$
This approach is therefore equivallent, so what may appear "magical" is the taking multiple differentials, but this can be avoided : eliminating variable $x$ we get :
$$x = \frac{u^2-a^2}{2u}$$
Ergo $$ \sqrt{a^2+x^2} = \sqrt{a^2+\frac{(u^2-a^2)^2}{4u^2}}=\frac{u^2+a^2}{2u} $$ and for $\mathrm{d}x$ :
$$\mathrm{d}x = \mathrm{d}\left(\frac{u^2-a^2}{2u}\right)=\frac{u^2+a^2}{2u^2}\mathrm{d}u$$
Therefore
$$I = \int \frac{\mathrm{d}x}{\sqrt{a^2+x^2}} = \int \frac{\frac{u^2+a^2}{2u^2}\mathrm{d}u}{\frac{u^2+a^2}{2u}} =\int \frac{\mathrm{d}u}{u} = \ln |u| +C = \ln\left(x+\sqrt{a^2+x^2}\right) +C $$
And I was just curious what king of "magic" would arise from the third Euler substitution, clearly different than the first two, which are here somewhat equivalent, and yes here it is :
Let $$\sqrt{a^2 + x^2} = tx$$
Or $$a^2 + x^2 = t^2x^2$$
Taking differential$$2x\mathrm{d}x = 2tx^2\mathrm{d}t+2xt^2\mathrm{d}x$$
Rearanging : $$\frac{\mathrm{d}x}{tx} = \frac{\mathrm{d}t}{1-t^2}$$
Ergo
$$I=\int\frac{\mathrm{d}x}{\sqrt{a^2+x^2}}=\int\frac{\mathrm{d}x}{tx}=\int\frac{\mathrm{d}t}{1-t^2}=\frac{1}{2}\ln\left|\frac{1+t}{1-t}\right|+C=\frac{1}{2}\ln\left|\frac{x+\sqrt{a^2+x^2}}{x-\sqrt{a^2+x^2}}\right|+C$$
Indeed, after rationalisation the denominator in $\ln$ :
$$\frac{1}{2}\ln\left|\frac{x+\sqrt{a^2+x^2}}{x-\sqrt{a^2+x^2}}\right| + C = \frac{1}{2}\ln\left|\frac{\left(x+\sqrt{a^2+x^2}\right)^2}{x^2-(a^2+x^2)}\right| +C = \ln\left(x+\sqrt{a^2+x^2}\right) + C' $$
Note : Substitution $\sqrt{a^2+x^2}=a+tx$ is also possible ...