Azure API Management Trace Policy

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

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.

image

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

image

An example of the trace is shown below:

image

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:

imageimage

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

image

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.

image

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
developers.de is a .Net Community Blog powered by daenet GmbH.