The small imaginary part has nothing to do with the integration but when the antiderivative is evaluated. The reason is that the antiderivative that Mathematica finds is not optimal and contains many complex expression that should cancel out when you calculate the definite integral.
Let us check this:
fM[x_] = Integrate[ArcTan[x]/(x^2 + 2 x + 2), x]
fM[2.0] - fM[0.0]
(* 0.256663 + 1.66533*10^-16 I *)
This is what you observed. I mentioned that
fM[x] is not the best antiderivative that can be found. A better one (if not the optimal) can be calculated using Rubi, the rule-based integrator.
fR[x_] = Int[ArcTan[x]/(x^2 + 2 x + 2), x]
If you compare the size of the antiderivatives of
fR[x] you will find that the
fR is 118, while Mathematica's result has 249. But this is not the only advantage. Look what we can do analytically with Rubi's result
FullSimplify[fR - fR]
(* 1/8 (π - 4 ArcCot) ArcTan *)
Looks nice and short, does it? And finally
(* 0.256663 *)
The thing to be learned here is that when you have complex nested expression and you evaluate them numerically, there might be some imaginary left-overs that you can handle with
Finally, I want to mention that we are working heavily on making Rubi easily accessible on the RuleBasedIntegration GitHub page because if Rubi can solve an integral, you can look at all steps that were required. For the moment, you can use the first Rubi link if you want to try it.