Use Azure Application Insights in Data API builder
Diagram of the sequence of the deployment guide including these locations, in order: Overview, Plan, Prepare, Publish, Monitor, and Optimization. The 'Monitor' location is currently highlighted.
Azure Application Insights is a service provided by Microsoft Azure that enables developers to monitor and gain insights into the performance and usage of their applications. The guide illustrates how to enable Application Insights for Data API builder (DAB). With Application Insights, you can track application availability, response times, performance metrics, user behavior, and other useful metrics.
Prerequisites
Warning
Application Insights for Data API builder isn't supported when hosting Data API builder in Azure App Service web apps.
- A running solution using Data API builder
Update configuration file
First, you should add an application-insights
section to your existing configuration file. This section includes the credentials necessary to connect DAB to Application Insights.
Locate and open the existing configuration file for your DAB solution.
In the
runtime
section, of the configuration file, add atelemetry
section with the following properties.Description enabled
Enables or disables application insights connection-string
Connection string for Application Insights instance { "runtime": { ... "telemetry": { "application-insights": { "enabled": true, "connection-string": "@env('app-insights-connection-string')" } }, ... } }
Tip
Alternatively, you can use the DAB CLI to add telemetry:
dab add-telemetry --app-insights-enabled true --app-insights-conn-string "@env('app-insights-connection-string')"
Note
This sample assumes that your host has an environment variable named
app-insights-connection-string
with the connection string. For more information on retrieving the connection string, see Azure Monitor connection strings.Save the configuration file and redeploy your solution.
Review metrics
When you enable Application Insights in your application, it starts sending data to the Application Insights service immediately.
Navigate to the Application Insights resource in the Azure portal (https://portal.azure.com).
Review the following types of data captured by Application Insights about your DAB solution.
Description Request telemetry Information about each incoming request to DAB, such as the URL, response time, and status code Trace telemetry Logs generated by DAB Exception telemetry Information about any exceptions or errors that occur in DAB Performance counters Metrics related to the performance of DAB, such as CPU usage, memory usage, and network traffic Note
The logs that are sent to Application Insights are same as the logs printed by Data API builder in the console.
Navigate to the Logs section of the Application Insights page. Review the logs using this query.
traces | order by timestamp
Review the results of the query. The
LogLevel
is mapped to severity levels using this table.LogLevel Severity Level Severity Level Value Trace Verbose 0 Debug Verbose 0 Information Information 1 Warning Warning 2 Error Error 3 Critical Critical 4 Tip
Set the current log level using the
--LogLevel
option for the DAB command-line interface (CLI). Otherwise, the host mode in the config file determines the minimum loglevel. If the host mode is set toProduction
, the minimum log level isError
. For theDevelopment
host mode, the minimum log level isDebug
.Navigate to the Live Metrics page.
Check the Application Requests using this query.
requests | order by timestamp
Enumerate exceptions using the Application Exceptions page.
exceptions | order by timestamp