In Order of the Phoenix, Harry saves Dudley's life by casting a patronus to drive back a dementor that was attacking him. Unfortunately, no good deed goes unpunished and he receives a letter that begins like this (emphasis mine):
Dear Mr Potter,
We have received intelligence that you performed the Patronus Charm at twenty-three minutes past nine this evening in a Muggle inhabited area and in the presence of a Muggle.
It is my understanding that the Trace only lets the ministry know when magic is used in the vicinity of an underage wizard, and not specifically who did it or the circumstances surrounding it (that's why Harry got in trouble when Dobby cast a hovering spell in the Dursleys' house).
So how did the Ministry know that Harry cast a patronus in front of a muggle, and why didn't they also know that dementors were around?