Automate custom reports with Application Insights data

Periodical reports help keep a team informed on how their business-critical services are doing. Developers, DevOps/SRE teams, and their managers can be productive with automated reports that reliably deliver insights without requiring everyone to sign in to the portal. Such reports can also help identify gradual increases in latencies, load, or failure rates that might not trigger any alert rules.

Each enterprise has its unique reporting needs, such as:

  • Specific percentile aggregations of metrics or custom metrics in a report.
  • Different reports for daily, weekly, and monthly roll-ups of data for different audiences.
  • Segmentation by custom attributes like region or environment.
  • AI resources grouped together in a single report, even if they might be in different subscriptions or resource groups.
  • Separate reports that contain sensitive metrics sent to selective audiences.
  • Reports to stakeholders who might not have access to the portal resources.

Note

The weekly Application Insights digest email didn't allow any customization and will be discontinued in favor of the custom options listed here. The last weekly digest email was sent on June 11, 2018. Configure one of the following options to get similar custom reports. Use the query that's suggested in this article.

Automate custom report emails

You can programmatically query Application Insights data to generate custom reports on a schedule. The following options can help you get started quickly:

Sample query for a weekly digest email

The following query shows joining across multiple datasets for a weekly digest email-like report. Customize it as required and use it with any of the options previously listed to automate a weekly report.

let period=7d;
requests
| where timestamp > ago(period)
| summarize Row = 1, TotalRequests = sum(itemCount), FailedRequests = sum(toint(success == 'False')),
    RequestsDuration = iff(isnan(avg(duration)), '------', tostring(toint(avg(duration) * 100) / 100.0))
| join (
dependencies
| where timestamp > ago(period)
| summarize Row = 1, TotalDependencies = sum(itemCount), FailedDependencies = sum(success == 'False'),
    DependenciesDuration = iff(isnan(avg(duration)), '------', tostring(toint(avg(duration) * 100) / 100.0))
) on Row | join (
pageViews
| where timestamp > ago(period)
| summarize Row = 1, TotalViews = sum(itemCount)
) on Row | join (
exceptions
| where timestamp > ago(period)
| summarize Row = 1, TotalExceptions = sum(itemCount)
) on Row | join (
availabilityResults
| where timestamp > ago(period)
| summarize Row = 1, OverallAvailability = iff(isnan(avg(toint(success))), '------', tostring(toint(avg(toint(success)) * 10000) / 100.0)),
    AvailabilityDuration = iff(isnan(avg(duration)), '------', tostring(toint(avg(duration) * 100) / 100.0))
) on Row
| project TotalRequests, FailedRequests, RequestsDuration, TotalDependencies, FailedDependencies, DependenciesDuration, TotalViews, TotalExceptions, OverallAvailability, AvailabilityDuration

Application Insights scheduled digest report

  1. Create an Azure Functions app. Application Insights On is required only if you want to monitor your new Azure Functions app with Application Insights.

    See the Azure Functions documentation to learn how to create a function app.

  2. After your new Azure Functions app has finished deployment, select Go to resource.

  3. Select New function.

    Screenshot that shows Create a new function.

  4. Select the Application Insights scheduled digest template.

    Note

    By default, function apps are created with runtime version 3.x. You must target Azure Functions runtime version 1.x to use the Application Insights scheduled digest template. Go to Configuration > Function runtime settings to change the runtime version. Screenshot that shows the Function runtime settings tab.

    Screenshot that shows New Function Application Insights Template.

  5. Enter an appropriate recipient email address for your report and select Create.

    Screenshot that shows Function Settings.

  6. Select Function Apps > Platform features > Configuration.

    Screenshot that shows Azure Function Application settings.

  7. Create three new application settings with the appropriate corresponding values AI_APP_ID, AI_APP_KEY, and SendGridAPI. Select Save.

    Screenshot that shows Function integration interface.

    You can find the AI_ values under API Access for the Application Insights resource you want to report on. If you don't have an Application Insights API key, use the Create API Key option.

    • AI_APP_ID = Application ID

    • AI_APP_KEY = API Key

    • SendGridAPI =SendGrid API Key

      Note

      If you don't have a SendGrid account, you can create one. For more information, see Azure Functions SendGrid bindings for the SendGrid documentation for Azure Functions. If you want a brief explanation of how to set up SendGrid and generate an API key, one is provided at the end of this article.

  8. Select Integrate. Under Outputs, select SendGrid ($return).

    Screenshot that shows Outputs.

  9. Under the SendGridAPI Key App Setting, select your newly created app setting SendGridAPI.

    Screenshot that shows SendGridAPI.

  10. Run and test your function app.

    Screenshot that shows Test.

  11. Check your email to confirm that the message was sent or received successfully.

    Screenshot that shows the E-mail subject line.

SendGrid with Azure

These steps only apply if you don't already have a SendGrid account configured.

  1. On the Azure portal, select Create a resource. Search for SendGrid Email Delivery and select Create. Fill out the SendGrid instructions.

    Screenshot that shows the SendGrid Create button.

  2. Under SendGrid Accounts, select Manage.

    Screenshot that shows the Manage button.

  3. This action opens SendGrid's site. Select Settings > API Keys.

    Screenshot that shows API Keys under Settings.

  4. To create an API key, select Create & View. Review SendGrid's documentation on restricted access to determine what level of permissions is appropriate for your API key. Full Access is selected here only as an example.

    Screenshot that shows Full Access.

  5. Copy the entire key. This value is what you need in your function app settings as the value for SendGridAPI.

    Screenshot that shows the API Key Created pane.