I used to take Ambien until I realized that after a week or less of them I couldn't sleep without one. It's called addiction, isn't it? Tolerance? BAD drug.
Ambien cannot compare with xanax for insomnia. I've tried everything over the decades and xanax is by far the best drug - as long as you leave it alone during the day. That's the ticket.
But I don't take it at bedtime unless I'm Really upset over something. What I take each night that somehow works great is GNC's Cherry Flavor sub-lingual Melatonin 1mg. After ten minutes your eyes start blurring over! LOL
It is really terrific.

I take a little xanax around 4 am if needed to return to sleep.