A dump that restores fine but is missing a stored procedure is the kind of surprise you only find on the day you need the backup. The fix is two flags that I would add to every dump command by default.
mysqldump --routines --events mydb > mydb.sql
The options are --routines (-R) for stored procedures and functions, and --events (-E) for scheduled events. Triggers have their own option, --triggers, and that one is on by default (you turn it off with --skip-triggers).
As far as I know, routines and events are not part of a dump unless you ask for them, so a plain mysqldump mydb restores your tables and triggers but quietly leaves the procedures and events behind. Check the full mysqldump page for your version before you rely on the default.
It works with the other selection options too, for example --all-databases:
mysqldump --all-databases --routines --events > all.sql
One caveat: the account running the dump needs enough privileges to read those definitions, and the dump is only as complete as that account’s view. The manual lists SELECT for tables, SHOW VIEW for views and TRIGGER for triggers. After a restore on a new server, also check that the definer accounts of the routines exist, because routines keep their original definer. MariaDB’s mariadb-dump has the same two options.
Further reading: MySQL mysqldump