API Management - Hands-on Lab Script - part 6
- Lab Prerrequisites
- Part 1 - Create an API Management instance
- Part 2 - Developer Portal and Product Management
- Part 3 - Adding API’s
- Part 4 - Policy Expressions
- Part 5 - Versioning and Revisions
- Part 6 - Analytics and Monitoring (You are here)
- Part 7 - Security
- Part 8 - DevOps
Basic Monitoring with Azure Monitor
Analytics is available in the Azure management portal from the Analytics blade.
- Look at the dashboard and detailed : Timeline , Geography , APIs , Operations , Products , Subscriptions , Users , Requests
How to integrate Azure API Management with Azure Application Insights
Azure API Management allows for easy integration with Azure Application Insights - an extensible service for web developers building and managing apps on multiple platforms. This guide walks through every step of such integration and describes strategies for reducing performance impact on your API Management service instance.
Create an Azure Application Insights instance
Before you can use Azure Application Insights, you first need to create an instance of the service.
- Open the Azure portal and navigate to Application Insights.
- Click + Add.
- Fill the form. Select General as the Application Type.
- Click Create.
Create a connection between Azure Application Insights and Azure API Management service instance
- Navigate to your Azure API Management service instance in the Azure portal.
- Select Application Insights from the menu on the left.
- Click + Add.
- Select the previously created Application Insights instance and provide a short description.
- Click Create.
- You have just created an Azure Application Insights logger with an instrumentation key. It should now appear in the list.
Behind the scene, a Logger entity is created in your API Management instance, containing the Instrumentation Key of the Application Insights instance.
Enable Application Insights logging for your API
- Navigate to your Azure API Management service instance in the Azure portal.
- Select APIs from the menu on the left.
- Click on your API, for example Color API.
- Go to the Settings tab from the top bar.
- Scroll down to the Diagnostics Logs section.
- Check the Enable box.
- Select your attached logger in the Destination dropdown.
- Input 100 as Sampling (%) and tick the Always log errors checkbox.
- Click Save.
Overriding the default value 0 in the First bytes of body field may significantly decrease the performance of your APIs.
Behind the scene, a Diagnostic entity named ‘applicationinsights’ is created at the API level.
What data is added to Azure Application Insights
Azure Application Insights receives:
- Request telemetry item, for every incoming request (frontend request, frontend response),
- Dependency telemetry item, for every request forwarded to a backend service (backend request, backend response),
- Exception telemetry item, for every failed request.
A failed request is a request, which:
- failed because of a closed client connection, or
- triggered an on-error section of the API policies, or
- has a response HTTP status code matching 4xx or 5xx.
If you go into your Application Insights instance, after few seconds, you should be able to see logs and metrics
Performance implications and log sampling
Logging all events may have serious performance implications, depending on incoming requests rate.
Based on internal load tests, enabling this feature caused a 40%-50% reduction in throughput when request rate exceeded 1,000 requests per second. Azure Application Insights is designed to use statistical analysis for assessing application performances. It is not intended to be an audit system and is not suited for logging each individual request for high-volume APIs.
You can manipulate the number of requests being logged by adjusting the Sampling setting (see the steps above). Value 100% means all requests are logged, while 0% reflects no logging at all. Sampling helps to reduce the volume of telemetry, effectively preventing from significant performance degradation, while still carrying the benefits of logging.
Skipping logging of headers and body of requests and responses will also have positive impact on alleviating performance issues.