Draw a right triangle and label the sides and hypotenuse according to the expression in your integral. Since you have x^2 + 1, that corresponds to the hypotenuse. Label the side opposite your acute angle as x, label the base as 1, and label the hypotenuse as sqrt(x^2 + 1). So tan(theta) = x/1, and sec^2(theta)d(theta) = dx. Use these two equations to completely convert you integral from expressions in x and dx to ones in theta and d(theta).
If you're asking how did we know to make a trig substitution, they are good bets when you have factors involving the sum or difference of squares, such as sqrt(x^2 + a^2), sqrt(a^2 - x^2), or sqrt(x^2 - a^2).