Most guitar players love their time to shine, the moment when the singer shuts up and you get to put your own stamp on a piece of music, but what can you do to make sure you don't suck the vibe or generally don't suck?
I don't ever like the thought of rules in music, so think of this as guidance, nothing strict, these are just a few thoughts I have had in the past. I have asked a lot of questions, because I believe in asking the right questions it makes you think and understand rather than read and forget, but I've added a few answers to these questions, you may think differently. This is just the tip of the iceberg in ways to train your brain:
Are you soloing over the verse chords after a chorus before a middle section? Are you soloing over a completely different chord progression to the rest of the song? What is the song doing before you solo and where is it going to be when you finish?
If you are soloing over a verse or chorus then you have the advantage that the singer has already laid down a melody for you, try playing what the singer has done, this will reestablish the listener with the hook, this is generally a good thing. You don't have to play it note for note, in fact I prefer to start loosely following the vocal melody, but add in touches that make it more guitar unique (harmonics, wide vibrato), vary as you progress, then perhaps go wild.
What if you have just played a low down stripped breakdown, then the solo comes in before a big loud double chorus, you may like to start slow and moody to bring the song out of the breakdown or perhaps come in all guns blazing to lift the song straight up, but where do you go next, how do you lift it again before the bind blowing chorus? Can you turn up to 11? The song may act in reverse to above, you may wish to finish in a slow melodic solo to bring the song to a dreamy close?
You need to know what key you're playing in of course, but that doesn't mean if the song is in A minor that you can only play the notes of A minor (A B C D E F G A) over the top, this of course depends on the style of song and the chords or bass line that is the canvas behind you. Most of all trust your ears, you may find that the A blues scale (A C D D# E G) works great over the song, the only note not in A minor is the D# (a flat 5 or augmented 4), this can add great tension.
You may be brave enough to 'play over the changes', by this I mean don't play any particular scale, but play the notes of the chords that are behind you, sticking with A minor, the chords may be A minor, D minor and G, you could start with C note as this is the minor third of A minor, then perhaps a play an A (the root) then down to a G (the minor 7), then back to an A, the next chord D minor is made up of D, F and A, so the A from the previous chords will work really well over the D minor too, perhaps try hanging on this note, you don't move, the backing does, it will make you sound great as a result.
This may entirely depend on what type of player you are. For me I have several approaches.
A fully written solo. This is what it sounds like, spend some time with backing, looper pedals are great for this, or perhaps you have a recording you can put on a loop. Spend your time seeing what sticks, what sounds great, when, then learn your solo, knowing when to stop tinkering will be your biggest obstacle here. I normally have a journey type feel in mind when writing a solo.
A fully improvised (just wing it) solo. This is when you just go for it! I mean you have to know what key you're in. Knowing when to stop helps too! This can be a fixed measure or a nod to your band mates. You have to hear in your head, what you'll play before you play, get to know your instrument, sing a note (or hum it), then try and play that note on your guitar, sing two notes, play them both (keep building), train your ears to hear intervals, what does it sound like to shift up one fret (the Jaws theme), this will all become natural the more you do it. Learn to play simple melodies from memory, christmas songs, advert jingles, phone ring tones, anything. One day you will be able to play what you hear in your head.
An improvised solo with check points. This is what I like to think of as a combination of the two, think again of the solo like a journey, where do you start, where does it goes and where do you finish. I have a solo like this that I like to play, which plays over a four bar pattern twice, I know I start with some two handed tapping for two bars, then I tend to get a bit more soulful and bendy for the second half a round, before building up some ascending arpeggios until I reach a C# on the high E string before going down and playing some whammy bar harmonics around the second fret. Sometimes I swap the tapping for the arpeggios as both have a triplet feel, sometimes I may drop a section and do something completely off the cuff. The solo is never the same twice. Like a journey, perhaps you make a regular journey, is it ever the same twice?