Before you decide to replace the magnetron, here are the most common causes of sparking inside the microwave.
N1. Burnt leaky HV diode. This is the most likely cause. Also it is important to always test the diode prior replacing the magnetron. A leaky diode will damage the magnetron if left unnoticed.
The microwave should be disconnected and the HV capacitor discharged prior performing any test on microwave's internal parts. For more information on how to discharge HV capacitor and test the HV diode, please read following articles:
N2. Damaged wave guide cover. Sometime food particles may stick to waveguide causing it to spark and get damaged. Always make sure that the waveguide is clean and free from bugs and food particles.
N3. Damaged shelf rack support. Your microwave might be equipped with rack shelf. Check the supports and look for chipped/worn paint around the hooks. N4. Metal particle or utensil inside the microwave cabinet.
N5. Burnt magnetron Cavity. ( Best solution is to replace the microwave if the damage is beyond the quick repair).