The rough rule is twelve years. Past that, the tank itself is usually the thing failing and no amount of element or thermostat work changes that. Under eight years, a repair is nearly always worth it.
Between eight and twelve it depends on the symptom. A failed element is cheap and worth doing. A leaking tank is not repairable at any age. Rusty water is the tank telling you it is going.
The exception is a unit that has been serviced properly and had its anode replaced. Those can run well past twelve years, and if yours has service records it is worth asking.