I am dealing with integral
$I=\int_0^{\pi}dx\frac{\sin^2x}{a^2+\sin^2x}.$
I know the answer is
$I=\pi(1-\frac{a}{\sqrt{1+a^2}}).$
However I am having some uncertainty getting there. I know that before plugging in the integration limits the solution looks like
$I= \left[x-\frac{a \tan ^{-1}\left(\frac{\sqrt{1+a^2}}{a} \tan x\right)}{\sqrt{1+a^2}}\right]^{x=\pi}_{x=0}$
but at first sight this would yield merely $\pi$. I can see that the right step to recover the correct solution is to take
$\tan^{-1}\left(\frac{\sqrt{1+a^2}}{a} \tan x\right)\Big\rvert_{x=\pi}=\pi$
however how do I justify this (besides that it yields the correct answer)?
First notice that the integral exists for all $a\in\Bbb R$, and from symmetry $$I(a)=2\int_0^{\pi/2}\frac{\sin^2x}{a^2+\sin^2x}dx\\ =\pi-2a^2\int_0^{\pi/2}\frac{dx}{a^2+\sin^2x}$$ Then we have that $\sin^2x=\frac12(1-\cos2x)$ so $$I(a)=\pi-4a^2\int_0^{\pi/2}\frac{dx}{2a^2+1-\cos2x}\\ =\pi+2a^2\int_0^\pi\frac{dx}{\cos x-2a^2-1}$$ Then from the comments here, we have that $$\int_0^\pi\frac{dx}{b+a\cos x}=\frac\pi{\sqrt{b^2-a^2}}$$ (I can show you a proof if you'd like). So of course $$I(a)=\pi+\frac{2a^2\pi}{\sqrt{(2a^2+1)^2-1}}=\pi+\frac{a\pi}{\sqrt{a^2+1}}$$ And from the definition of $I(a)$, we have that $I(a)=I(-a)$ so your desired result: $$\frac1\pi I(a)=1-\frac{a}{\sqrt{a^2+1}}$$