Dump all sip_headers to a text file

I’m familiar with turning debug on, watching the console etc. but I’d prefer to be able to extract all headers for a specific call and just dump them to a text file.

The problem is, how do I know what all available headers are? Different carriers send different header variables.

Is there any way I can query a list of all headers then loop through them and dump/append the values to a text file?
exmaples of the ones I access now:
${SIP_HEADER(History-Info)}, Call-ID, Contact, Remote-Party-ID etc.
Then I could run a system() command to send the variable names and values to a perl script for example?