Azure Management API by default provides a testing tool with pretty good tracing option. Following picture shows how default trace looks like in action. First open the API Management in Azure Portal and navigate to your API (in my case Echo API). On the top right, you will find Test button.

After you click on send button, operation will be executed including or specified policies. As next click on “Trace” to see trace output.

An example of the trace is shown below:

This trace is very powerful, but sometimes, you might want to have more custom information. To do this you can use a trace-policy.
Select some operation or click all operations and open policy editor as code:


Here is what you will see, if no policies are defined in policy editor:

Then in the list of policies add new inbound policy:
<trace source="Anything"> @(context.Request.Body?.As<string>(true) ?? "No Body") </trace> |
As source, you can specify any string, which will appear in the trace output.

If you add trace policy to outbound policies, you can grab out response body as shown in following snippet:
<trace source="ResponseBody"> @(context.Response.Body?.As<string>(true) ?? "No body") </trace> |
Posted
Jan 12 2017, 05:43 AM
by
Damir Dobric