This post was originally going to be a rant about the inconsistencies and contradictions we're given in the books for how the Ministry of Magic detects underage magic. However, in the process of trying to describe all the problems, I actually managed to develop a possible theory for how the Trace works. So, here it goes....
The Ministry makes a distinction between magical and muggle areas of the British Isles. Magical locations include Diagon Alley, Hogwarts, the Forbidden Forest, Hogsmeade, etc.-- plus the private properties of wizards and witches. The Ministry only monitors the use of magic in designated muggle areas. Magical areas are probably surrounded by wards that prevent magical activity within them from being detected.
The Improper Use of Magic Office (IUMO) uses two separate instruments for monitoring muggle areas. The first instrument, which I'll call the "magic detector," alerts the ministry when there is a spike in magical activity and provides both the location and the name of the spell that's been cast. The second instrument is similar to the Marauder's Map, where every individual in the British Isles has a dot on the map. The dots are likely color coded, where, for example, muggles are red and wizards are green. Thus, when the magic detector registers the use of magic in a muggle area, the IUMO can quickly check their map to see if there are any muggles nearby who may have witnessed it.
Unlike the Marauder's Map, most of the dots on the IUMO map are unlabeled. Muggles simply appear as red dots and wizards as green dots. However, underage wizards and witches are identified by name on the map. Perhaps they also appear as a different color, such as blue. This is what is meant by the "Trace." When a wizard or witch turns 17, hir dot turns green and hir name disappears from the map. Magically, it is actually quite easy to identify adult wizards and witches by name on the map, but their dots are usually left unlabeled in order to protect their privacy.
Example 1: On the night that Dumbledore retrieved Harry from the Dursleys in HBP, there would have been 5 dots on the map at #4 Privet Drive: 3 red, 1 green, and a blue one labeled as 'Harry Potter'
Example 2: In CoS, there were no green dots on the map at #4 Privet Drive when Dobby cast his hovering charm, so Harry was blamed for doing underage magic when the magic detector registered the spell.
Example 3: In OoTP, Umbridge waited until there were no green dots in the area before sending in the dementors so that only Harry could be blamed for casting the Patronus charm.
This gives me some ideas about the activities of the four marauders. Perhaps they discovered how to create the Marauder's Map in the process of figuring out how to remove their dots from the IUMO map. Perhaps James removed Lily's dot from the map in his efforts to win her heart, and that's why she could get away with turning teacups into rats during her summer holidays. Maybe the Ministry had so much trouble tracking Sirius after his escape from Azkaban because he knew how to hide himself on the map. Maybe the reason neither the twins nor the trio ever spotted Pettrigrew's name on the Marauder's Map is because he knew how to keep his dot off of it. Perhaps, though, the spell is temporary, or you have to redo it if you've been outside the boundaries of the map, and so Lupin was finally able to spot the rat.
Yes, I'm fully aware that Rowling likely didn't work any of this out this carefully, but it's still fun theory. :D