When any one solves an integral using the Cauchy integral formula, it depends on the contour of the function.
So my question is:
How to know the contour of any function?
For example:
$$f(z)=\frac {\ e^{itz}} {z^2+1}$$
Example 2:$$f(z)=\frac {\sinh(az)} {e^{bz}-1} $$
It depends on the integral you want to solve, there isn't a general method to choose. However there are some typical examples. Often you will have to integrate on rectangles, circles, half-circles (as in your first example), double circles (one circle oriented in positive direction, one in negative direction contained in the first one) and similar stuff. The important things to remember are:
Also note that sometimes you will have to change slightly the function you're integrating to get your result.