I am considering the integral $$I=\int_0^\infty \frac{a^x}{x^2+1}dx,\quad 0<a<1$$ which showed up in attempting to solve a different question on MSE. My attempt was by considering a keyhole contour
This function has simple poles at $z=i$ and $z=-i$. We drop the integral over the big circle; the lines $A$ and $B$ each contribute the value $I$, so $$2I=2\pi i \sum Res$$ which then leads to the solution $$2I=2\pi i (\frac{a^i}{2i} +\frac{a^{-i}}{-2i})$$ but the RHS is purely imaginary, when $I$ should be real. When I played with this on Mathematica, the RHS and LHS (in absolute value) are completely unrelated when I numerically compute each for various values of $a$. What am I doing wrong?
Edit: It appears I utterly failed with this integral. Does anyone have any idea of how to actually solve it? Hints are welcome. (Should I make a new post?)

In your contour,
I think what you are missing is the integral of the form $$\lim_{w \rightarrow \infty} \int_{\{w e^{i \theta}: -\pi \leq \theta \leq \pi\}} \frac{e^{\log(a)z}}{z^2+1} dx$$
It is not $0$ as it involves both positive and negative $x$-axis. In fact I think it diverges.