Demi Lovato's overdose was not a shock to some of her friends, who say there were big warning signs for weeks that she had lost her battle for sobriety.

Friends of Demi tell us ... even before she released her song, "Sober," confessing she had fallen off the wagon, it was apparent to them she had slipped back into her drug use. They say the signs became more alarming as the days passed, and one friend says he knew for weeks she was in the danger zone ... when he saw her this week it was apparent she was in trouble.  

Another warning sign ... she had a big falling out with her sober coach earlier in the month, accusing him of betraying her.

It seems Demi was able to compartmentalize her social life, because other friends say they didn't see this coming. One friend says he was at her home less than 2 weeks ago and she seemed great.

TMZ broke the story ... Demi OD'd at her home Tuesday and law enforcement sources say it was an apparent heroin overdose, but a source close to Demi says it was NOT heroin. When they arrived, she was unconscious and they used Narcan to bring her back. Narcan is used to counter overdoses of opioids.