As is always the case, after you have completed a project is generally when you find out how something properly works. After working with Azure APIM for quite a while, I stumbled across the TRACE policy after having manually exported this data on my own.
Trace statements are a great way to ensure that information is bubbling up to the user where code executes solely in APIM.
In order to see any TRACE statements, you will need to navigate to the “Test” tab and click the TRACE button. Depending on your network setup, you might need to click “ByPass CORS proxy,” and depending on your setup, you might need to request explicit TRACE permissions on your subscription.

The Code
The code is relatively simple and requires no additional legwork or dependencies to be added.
<trace source="ContactApiId" severity="verbose">
<message>@((string)context.Variables["ContactId"])</message>
<metadata name="Operation Name" value="ById" />
</trace>
In the above scenario, I’m exporting the value of my ContactId, because I want to see if the value is coming through correctly. Instead of clicking “Send”, we are going to click “Trace” where we can then see the value of our Trace statement.

Note: You will still have to navigate to the “Trace” tab. As you can see the in the below, I get the execution of the trace statement along with a custom value being output.

Retrieving Multiple Items
Outputting a known item (i.e., a variable) is pretty simplistic. and not one of the problems I’m interested in trying to resolve. What the above would have helped me in my early days of APIM work was in understanding the unknown.
For example, the below statement takes all Request Headers in the incoming statements and traces them out to the console as I am working on issues. When debugging communications from other systems, this would have been a huge help.
<trace source="ContactHeaders" severity="information">
<message>@{
var headers = context.Request.Headers;
return string.Join("\n", headers.Select(h => $"{h.Key}: {h.Value}"));
}</message>
<metadata name="Operation Name" value="Headers" />
</trace>
If you’re looking to go deeper on Azure APIM, I highly recommend taking a read-through of this blog – https://dev.fyicenter.com/1000686_Microsoft_Azure_API_Management_Tutorials.html – it is incredibly helpeful and was a goto resource when I was getting started.