Quite a few of the solos I record aren't actually improvised. Once I have recorded the rhythm guitars, bass and drum and whatnot, I play it back and improv over it quite a few times until I find some phrases that work well with it. It all subjective though. I will generally improvise if the music has a kind of bluesy feel to it, because of my style of playing. I guess my my improv leads sound more hendrixy than kirk hammet or whatever, and that doesn't always work too well if I'm playing metal. I also like to give them a very melodic feel, so this way I know I will be 100% happy with the end product.
This way the solo becomes like a tune within a tune. I find with a lot of the wankery that goes on these days, some of the solos aren't particularly memorable. I like to make solos that will stick in the listeners mind.
At the end of the day, to me its all about bringing the parts to together to make something that is the sum of the parts. The solo is just another part of the tune that adds to the overall feel of the tune. I'm no virtuoso so its all about sitting down and finding out what works well.
I'm not sure if that how people would normally do things, or if most solos are just improvised on the spot, but this way works for me...