I have an idea for postgres plpgsql: create a new pl function with the same name, but an additional param, a switch to do something else. You can write a new body to do whatever you want. Then you can use the old and new version anywhere.
If you use something like ttrace, you modify every call of the function.