Three processes that decide what the kidney removes
How much of a drug the kidneys eliminate is the net result of three processes. Glomerular filtration pushes small, unbound molecules out of the blood into the forming urine, so highly protein-bound drugs are filtered poorly. Active tubular secretion uses transporter proteins to pump certain drugs from the blood into the tubule, sometimes clearing them faster than filtration alone would. Tubular reabsorption then moves some drug back into the blood, especially when it is lipid-soluble and un-ionised.
The balance of these three steps explains why two drugs of similar size can be cleared at very different rates.
Why kidney function and urine pH change drug levels
When kidney function declines, drugs that depend on renal clearance accumulate, so doses of many medicines are reduced in chronic kidney disease. Urine pH also matters because it shifts how ionised a weak acid or base is, which changes how much is reabsorbed; this principle underlies some overdose treatments that alkalinise the urine.
This is general educational information about renal pharmacology, not medical advice; dose adjustment for kidney function should be made by a qualified clinician.