You want to use a dialplan hook for internal calls:
Here’s a recent example of setting CDR values:
We’d be happy to work with on you this if you have budget. Click the support link above.