Hi Melody!
IMHO, the answer lies in the Lord's Prayer. "Our Father, Who art in Heaven HALLOWED be Thy name." Calling on the Lord can be pleasing to Him if we do it with righteous intent.
The term "in vain" is described in the dictionary as
"in an irreverent or disrespectful manner".
We should always use the Lord's name with awe. To this day, Jews don't even write God's name out in full, you will see Orthodox Jewish writings as
G_d because His name is hallowed.
Many people will "swear to God" with barely a thought. Biblically speaking, swearing to God is a very grave thing, indeed.
At least the way I've seen most people use the Lord's name when they say "Oh my God," it seems to me they are taking His name in vain. In your second example, it seems to me the intent is to call upon Jesus for aid, which is really a prayer. I guess it's what's in your heart and mind when you speak the Lord's name that makes it either a prayer

, or a sin against Him

.