top of page
  • Writer's pictureShaw Innes

Azure API Management Feature: Application Insights

By Bill Chesnut

This is the third post in a multi part series on the features of Azure API Management.

As with the previous posts where I demonstrated publishing a SOAP Services with pass-through and SOAP to REST, this time I am going to demonstrate how you can connect Azure API Management to Azure Application Insights, to monitor the call to APIM and the dependent APIs. This post will not go into how or why to use Azure Application Insights, just how to configure APIM to use it.

By connecting APIM to Application Insights, information from APIM sent to Application Insights will include the request and response from APIM, the backend request and response and any Exception information. This will give end-to-end monitoring capabilities to the APIs that are being exposed in APIM if those APIs are also using Application Insights for monitoring.

As with any telemetry gathering system, there are some performance implications, APIM has recently added the ability to control this with a much finer grain as we will see later in the configuration screens.

To get started with Application Insights for APIM, you will need an Application Insights instance, I am not going to cover how to create that in this blog post, but you can find the instructions here:

Once the Application Insights instance has been created (you can also use an existing instance if you want), lets connect Application Insights to APIM, go to the ‘Application Insights’ tab in the Azure Portal for APIM.

Then Click ‘+ Add’

Select the instance of Application Insight that you want to configure, optionally add a description and Click ‘Create’

You can have multiple instances of Application Insights connected to APIM, now we need to configure how this instance of Application Insights is used, it can be the default for all APIs in APIM or just used for specific APIs, to use it as the default instance, Click ‘APIs’, Click ‘All APIs’, Click Settings and to enable Click the ‘Enable’ check box

Configure the destination (instance of Application Insights), Sampling (there are some performance implication with the sampling %, see the this link – ), Always log errors (recommended) and First bytes of body (if necessary). Click ‘Save’

The Advanced Options allow you to control which Request are logged and headers and body logging

If you do not want to use the same instance of Application Insights for all APIs, you can select the API and configure Application Insights just like above for the particular APIs

Now lets open Application Insights, Click ‘Search’, then in the Search, Click ‘Refresh’, the results are empty since we have not made any calls to the API yet. If this was an existing instance of Application Insight, there may already be some telemetry from the other services

Now lets go back to APIM and run some tests, Select and Operation, enter the required data (in this case, an invalid URL to see the exception processing) and Click ‘Send’

The result is a 500 Internal Server Error

Switch to Application Insights and Click ‘Refresh’, There is now data in Application Insights, 2 Request, 2 Trace, 1 Exception and 1 Dependency.

For this particular API, Application Insights is also setup on the API, so we can have end-to-end Application Insights information. Click on one of the entries to get the details

The details for the Request are contained in the view above and you can see the related Application Insights entries on the left and the particular details for the request on the right. If we want to get more details on the Exception, other than the 500 Response code we see in this entry, click on the Exception entry on the left

By configuring Application Insights for APIM, the full end-to-end flow of requests can be seen, the percentage of requests that are captured in Application Insights depends on your sampling, in a Development or Testing environment you can set this to 100% but in Production environments if the APIs are very active this may introduce too much overhead and require a lower sampling rate to prevent performance degradation.

Hopefully this has given you a quick demonstration on how to connect Application Insight to APIM.

If you are interested in more information on APIM, I would be glad to come out and present or chat directly with you, please use the Contact Us to reach out to me.





bottom of page