You cast this spell. It requires either an action, or 10 minutes plus an action as a ritual. At the time you cast the spell, you can sense whether there is magic within 30 feet of you. If the source of magic is separated from you by 3 feet of wood, 1 foot of stone, 1 inch of common metal, or a thin sheet of lead, the spell will not detect the magic.
Detect and sense are ambiguous terms in 5E that are not defined. As such, we turn to a dictionary and get a definition of "a feeling that something is the case". As a result, this first initial blush of the spell is a binary toggle that turns on if there is any magic within 30 feet of you. You continue to sense magic in this way and would become aware if magic enters your 30 feet visible radius (or a barrier is removed) while you concentrate. However, if there is already magic in the area, your binary detection of magic does not change when a new magic source enters the area. Some people call this a "stupid spell" problem because most PCs walk around with some magic on them. The spell does not exist solely for PCs. Most low level clerics and wizards that can cast this magic may not have any magic items.
Note that per sage advice, constructs animated by magic do not detect as magic by themselves. They were given the spark of life by magic, but are no longer magical. It would seem the same is true of undead from an instantaneous source (like a zombie from a finger of death or a wight), but not of summoned or animated undead with a duration.
If you detect any magic, you may then use another action, so long as you are still concentrating on the spell, to look for magic auras. A 1.) visible 2.) creature or object will show you a faint aura that reveals the school of magic, if any.
Visible is not inherently defined either, but there are a few elements in the rules that clarify when something cannot be seen. Invisible and heavily obscured (including those shrouded in darkness) creatures or objects cannot be seen. If a creature is successful in their attempt to hide, they gain the benefits of being an unseen attacker/target. As such, a hidden creature concealed by stealth is presumably unseen, and thus would not detect as magical (assuming perception is not greater than stealth). Similarly, an object that has been concealed with sleight of hand should also be unseen as well (unless perception beats sleight of hand).
Absent a sleight of hand or stealth role to conceal the object or creature, non-skill based techniques can be used to obscure the creature or target so that no aura is detected. Any barrier that prevents direct line of sight to every part of the creature or object would prevent an aura from being generated. If, after the magic is applied, the entire object were painted, or covered in a thick layer of flour, or put into darkness it would not emit an aura when the second element of detect magic is used.
"But it glows! How can darkness hide something that glows?" you might ask.
It doesn't glow. It doesn't do anything unless it is visible. In this chicken and the egg scenario, you need to see the object or creature before it can emit that faint aura. If you do not see it, it does not glow.
Also, illusions and other spell effects are not creatures or objects, generally. Accordingly, a light spell cast on a stone would emit an aura because the stone is an enchanted object, but a dancing lights spell would not. They'd both trigger the initial "sense" that magic is present, but dancing lights would not emit a magical aura when that extra action is used to look for auras.