Edit

Share via


Create and configure Application Insights resources

Important

This article applies to workspace-based Application Insights resources. Classic Application Insights resources have been retired. Transition to workspace-based Application Insights to take advantage of new capabilities.

Application Insights integrates with Log Analytics and sends telemetry to a common Log Analytics workspace. This setup provides full access to Log Analytics features, consolidates logs in one location, and allows for unified Azure role-based access control which eliminates the need for cross-app/workspace queries.

Enhanced capabilities include:

This article shows you how to create and configure Application Insights resources. Along with the Application Insights resource itself, you can add various configurations like setting the daily cap and pricing plan. You can also create availability tests, set up metric alerts, and automate the process using Azure Resource Manager.

Note

Data ingestion and retention for workspace-based Application Insights resources are billed through the Log Analytics workspace where the data is located. To learn more about billing, see Azure Monitor Logs pricing details.

Prerequisites

  • An active Azure subscription.
  • The necessary permissions to create resources.

Additional requirements

No additional requirements.

Create an Application Insights resource

  1. Sign in to the Azure portal.
  2. Select Create a resource.
  3. Open the category Monitoring & Diagnostics, then select Application Insights.
  4. Enter all relevant information, then Review + create your Application Insights resource.

Screenshot that shows an Application Insights resource.

Note

If you don't connect to an existing Log Analytics workspace during resource creation, a new Log Analytics resource is created automatically along with your Application Insights resource.

After creating your resource, you can find the corresponding workspace information in the Application Insights Overview pane.

Screenshot that shows a workspace name.

Select the blue link text to go to the associated Log Analytics workspace where you can take advantage of the new unified workspace query environment.

Note

We still provide full backward compatibility for your Application Insights classic resource queries, workbooks, and log-based alerts. To query or view the new workspace-based table structure or schema, you must first go to your Log Analytics workspace. Select Logs (Analytics) in the Application Insights panes for access to the classic Application Insights query experience.

Configure monitoring

After creating an Application Insights resource, you configure monitoring.

Get the connection string

The connection string identifies the resource that you want to associate your telemetry data with. You can also use it to modify the endpoints your resource uses as a destination for your telemetry. You must copy the connection string and add it to your application's code or to an environment variable.

To get the connection string of your Application Insights resource:

  1. Open your Application Insights resource in the Azure portal.
  2. On the Overview pane in the Essentials section, look for Connection string.
  3. If you hover over the connection string, an icon appears which allows you to copy it to your clipboard.

Application monitoring with OpenTelemetry

For application monitoring with OpenTelemetry, you install the appropriate Azure Monitor OpenTelemetry Distro and point the connection string to your newly created resource.

For information on how to set up application monitoring with OpenTelemetry, see the following documentation specific to the language:

Note

For web apps targeting browsers, we recommend using the Application Insights JavaScript SDK.

Automatic instrumentation

For monitoring services like Azure Functions and Azure App Service, you can first create your Application Insights resource, then point to it when you enable monitoring. Alternatively, you can create a new Application Insights resource during the enablement process.

Configure Application Insights resources

Modify the associated workspace

After creating an Application Insights resource, you can modify the associated Log Analytics workspace.

In your Application Insights resource, select Properties > Change workspace > Log Analytics Workspaces.

Export telemetry

The legacy continuous export functionality isn't supported for workspace-based resources. Instead, use Diagnostic settings.

Note

Diagnostic settings export might increase costs. For more information, see Export telemetry from Application Insights. For pricing information for this feature, see the Azure Monitor pricing page. Before the start of billing, notifications are sent. If you continue to use telemetry export after the notice period, you'll be billed at the applicable rate.

In your Application Insights resource, select Diagnostic settings > Add diagnostic setting.

You can select all tables or a subset of tables to archive to a storage account. You can also stream to an event hub.

Set the data retention

Data retention for Application Insights resources can be set in the associated Log Analytics workspace.

For more information, see Configure the default interactive retention period of Analytics tables.

Set the daily cap

The daily cap must be set independently for both Application Insights and the underlying Log Analytics workspace. The effective daily cap is the minimum of the two settings.

To learn how to set the daily cap in the Azure portal, see Set daily cap on Log Analytics workspace.

Set the pricing plan

The pricing plan for Application Insights resources can be set in the associated Log Analytics workspace. For more information about available pricing plans, see Azure Monitor Logs cost calculations and options.

To learn how to set the pricing plan in the Azure portal, see Application Insights billing.

Create additional resources

Create an availability test

To learn how to create an availability test in the Azure portal, see Application Insights availability tests.

Add a metric alert

Tip

Each Application Insights resource comes with metrics that are available out of the box. If separate components report to the same Application Insights resource, it might not make sense to alert on these metrics.

To learn how to create a metric alert in the Azure portal, see Tutorial: Create a metric alert for an Azure resource.

To automate the creation of metric alerts, see the Metric alerts template article.

Create more Application Insights resources

How many Application Insights resources should I deploy?

When you're developing the next version of a web application, you don't want to mix up the Application Insights telemetry from the new version and the already released version.

To avoid confusion, send the telemetry from different development stages to separate Application Insights resources with separate connection strings.

If your system is an instance of Azure Cloud Services, there's another method of setting separate connection strings.

When to use a single Application Insights resource

Use a single Application Insights resource for:

  • Streamlining DevOps/ITOps management for applications deployed together, typically developed and managed by the same team.
  • Centralizing key performance indicators, such as response times and failure rates, in a dashboard by default. Segment by role name in the metrics explorer if necessary.
  • When there's no need for different Azure role-based access control management between application components.
  • When identical metrics alert criteria, continuous exports, and billing/quotas management across components suffice.
  • When it's acceptable for an API key to access data from all components equally, and 10 API keys meet the needs across all components.
  • When the same smart detection and work item integration settings are suitable across all roles.

Note

If you want to consolidate multiple Application Insights resources, you can point your existing application components to a new, consolidated Application Insights resource. The telemetry stored in your old resource doesn't transfer to the new resource. Only delete the old resource when you have enough telemetry in the new resource for business continuity.

Other considerations

To activate portal experiences, add custom code to assign meaningful values to the Cloud_RoleName attribute. Without these values, portal features don't function.

For Azure Service Fabric applications and classic cloud services, the SDK automatically configures services by reading from the Azure Role Environment. For other app types, you typically need to set it explicitly.

Live Metrics can't split data by role name.

Version and release tracking

When you publish a new version of your application, you want to be able to separate the telemetry from different builds. You can set the Application Version property so you can filter search and metric explorer results.

There are several different methods of setting the Application Version property.

  • Option 1: Set the version directly

    Add the line telemetryClient.Context.Component.Version = typeof(MyProject.MyClass).Assembly.GetName().Version; to the initialization code of your application.

    To ensure that all TelemetryClient instances are set consistently, wrap that line in a telemetry initializer.

  • Option 2: Set the version in BuildInfo.config (ASP.NET only)

    The Application Insights web module picks up the version from the BuildLabel node. Include this file in your project and remember to set the Copy Always property in Solution Explorer.

    XML
    <?xml version="1.0" encoding="utf-8"?>
    <DeploymentEvent xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/VisualStudio/DeploymentEvent/2013/06">
      <ProjectName>AppVersionExpt</ProjectName>
      <Build type="MSBuild">
        <MSBuild>
          <BuildLabel kind="label">1.0.0.2</BuildLabel>
        </MSBuild>
      </Build>
    </DeploymentEvent>
    
    

    Generate BuildInfo.config automatically in the Microsoft Build Engine. Add the following lines to your .csproj file:

    XML
    <PropertyGroup>
      <GenerateBuildInfoConfigFile>true</GenerateBuildInfoConfigFile>
      <IncludeServerNameInBuildInfo>true</IncludeServerNameInBuildInfo>
    </PropertyGroup>
    

    This step generates a file called yourProjectName.BuildInfo.config. The Publish process renames it to BuildInfo.config.

    The build label contains a placeholder (*AutoGen_...*) when you build with Visual Studio. When built with the Microsoft Build Engine, the placeholder is populated with the correct version number.

    To allow the Microsoft Build Engine to generate version numbers, set the version like 1.0.* in AssemblyReference.cs.

Release annotations

If you use Azure DevOps, you can get an annotation marker added to your charts whenever you release a new version.

Automate the resource creation process

The resource creation process can be automated by using Bicep or JSON templates with Azure Resource Manager. You can package several resources together to create them in one deployment. For example, you can create an Application Insights resource with availability tests, metric alerts, and a diagnostic setting to send telemetry to an Azure Storage account.

Generate a template in the Azure portal

You can generate a template from existing resources.

Application Insights only

  1. Go to the Application Insights resource in the Azure portal.
  2. Open Export template listed under Automation in the left-hand navigation bar.
  3. (Optional): To use your own parameters, uncheck Include parameters.
  4. Download the template file or Deploy it directly in the Azure portal.

Multiple resources

  1. Go to the resource group of your Application Insights resource.
  2. On the Overview pane, mark all resources you want to be included in the template, then select Export template in the top navigation bar.
  3. (Optional): To use your own parameters, uncheck Include parameters.
  4. Download the template file or Deploy it directly in the Azure portal.

Create a template from scratch

To learn how to create an ARM template from scratch, visit our ARM template documentation which includes tutorials to create a template, add resources, add parameters, and more.

Available properties for Application Insights, availability tests, metric alerts, diagnostic settings, and other resources can be found in our Azure resource reference documentation under the Reference > Monitor > Insights node.

Tip

You can also use quickstart templates, available towards the bottom of each Azure resource reference documentation page linked in this section. To learn how to use templates, visit Tutorial: Use Azure Quickstart Templates.

Frequently asked questions

This section provides answers to common questions.

How do I move an Application Insights resource to a new region?

Transferring existing Application Insights resources between regions isn't supported, and you can't migrate historical data to a new region. The workaround involves:

  • Creating a new Application Insights resource in the desired region.
  • Re-creating any unique customizations from the original resource in the new one.
  • Updating your application with the new region resource's connection string.
  • Testing to ensure everything works as expected with the new Application Insights resource.
  • Decide to either keep or delete the original Application Insights resource. Deleting a classic resource means to lose all historical data. If the resource is workspace-based, the data remains in Log Analytics, enabling access to historical data until the retention period expires.

Unique customizations that commonly need to be manually re-created or updated for the resource in the new region include but aren't limited to:

  • Re-create custom dashboards and workbooks.
  • Re-create or update the scope of any custom log/metric alerts.
  • Re-create availability alerts.
  • Re-create any custom Azure role-based access control settings that are required for your users to access the new resource.
  • Replicate settings involving ingestion sampling, data retention, daily cap, and custom metrics enablement. These settings are controlled via the Usage and estimated costs pane.
  • Any integration that relies on API keys, such as release annotations and live metrics secure control channel. You need to generate new API keys and update the associated integration.
  • Continuous export in classic resources must be configured again.
  • Diagnostic settings in workspace-based resources must be configured again.

Can I use providers('Microsoft.Insights', 'components').apiVersions[0] in my Azure Resource Manager deployments?

We don't recommend using this method of populating the API version. The newest version can represent preview releases, which might contain breaking changes. Even with newer non-preview releases, the API versions aren't always backward compatible with existing templates. In some cases, the API version might not be available to all subscriptions.

Next steps