Monitoring your applications or APIs is one of the most crucial elements of the DevOps world.

DevOps cycle

If you don’t do it you basically can’t solve errors properly or make new development decision based on your users behaviors, problems and needs. The easiest way to deploy APIs in Azure is to use API Management and the easiest way to monitor apps and APIs is Application Insights. One of the cool features of APIM is that you can have multiple Application Insights instances connected to it and assign them to specific APIs.

When you go to your APIM instance click on the Application Insights section in the menu in the Monitoring section. There you will find an option to add Application Insights instances to your APIM:

Master Application Insights in API Management

When you check the “User as default…“ this Application Insights instance will log requests and traffic for all of your APIs.

Now let’s add another Application Insights instance to our API Management

Second Application Insights instance added to API Management

As you can see there is no option to have all APIs use this instance. Now what we need to do is go the API of interest -> Click on it -> go to Settings tab -> Scroll down. In the Application Insights section click Enabled and from the drop down section select the Application Insights instance of interest:

Add Application Insights into specific API

IMPORTANT: As the documentation states - using 100% sampling on production scenarios is not recommended as there is a potential of performance decreases.

I would recommend a trial&test approach for this to find the sweet spot for your logging needs and the performance impact on your environment.

Scenarios You can think of many but one of the most common ones is having an Application Insights instance per environment like Dev/Test(UAT/Staging)/Prod. Thanks to this you can use all the great features of Application Insights like bulging maps, handling request start to finish and tracing down any issues while te request reaches your API and/or backend.