The circumstances for the writing of this psalm are unknown. It appears that David is sick and feels he is about to die. In this state he writes this penitential psalm (Psalms 6, 32, 38, 51, 102, 130, and 143). When seeking to confess sins, these are great psalms to read as part of confession when asking God to restore our fellowship with Him (1 John 1.9).
Verses 1-3-David feels as though his bones are melting away within him (Psalm 32) or are broken in pieces (Psalm 51). When we are not feeling well, both physically and spiritually, we feel like this. This call for healing his bones is actually a call for forgiveness. David sounds like he is depressed because of the attacks of his family, friends, and enemies. David is also depressed due to his sin. What does depression do to us?
Verses 4-5-David calls to God to heal him because of the praise that would be given Him and because of His goodness, His loving-kindness (Psalm 88.10-12 and Isaiah 38.18).
Verses 6-7-David weeps over his illness just as Job did (Job 17.7).
Verses 8-10-After the tears come praises.
Think about this Psalm. David is in grief. He presents his petition to God. He then turns to praising God. This is how it should be. Is it how it is with you?