Enable Azure Monitor OpenTelemetry for .NET, Node.js, Python, and Java applications

This article describes how to enable and configure OpenTelemetry-based data collection within Azure Monitor Application Insights. The Azure Monitor OpenTelemetry Distro:

  • Provides an OpenTelemetry distribution which includes support for features specific to Azure Monitor.
  • Enables automatic telemetry by including OpenTelemetry instrumentation libraries for collecting traces, metrics, logs, and exceptions.
  • Allows collecting custom telemetry.
  • Supports Live Metrics to monitor and collect more telemetry from live, in-production web applications.

For more information about the advantages of using the Azure Monitor OpenTelemetry Distro, see Why should I use the Azure Monitor OpenTelemetry Distro.

To learn more about collecting data using OpenTelemetry, check out Data Collection Basics or the OpenTelemetry FAQ.

OpenTelemetry release status

OpenTelemetry offerings are available for .NET, Node.js, Python, and Java applications. For a feature-by-feature release status, see the FAQ.

Enable OpenTelemetry with Application Insights

Follow the steps in this section to instrument your application with OpenTelemetry. Select a tab for langauge-specific instructions.

Note

.NET covers multiple scenarios, including classic ASP.NET, console apps, Windows Forms (WinForms), and more.

Prerequisites

  • A Java application using Java 8+

Install the client library

Download the latest applicationinsights-agent-3.7.1.jar file.

Warning

If you are upgrading from an earlier 3.x version, you may be impacted by changing defaults or slight differences in the data we collect. For more information, see the migration section in the release notes. 3.5.0, 3.4.0, 3.3.0, 3.2.0, and 3.1.0

Modify your application

Autoinstrumentation is enabled through configuration changes. No code changes are required.

Point the Java virtual machine (JVM) to the jar file by adding -javaagent:"path/to/applicationinsights-agent-3.7.1.jar" to your application's JVM args.

Note

Sampling is enabled by default at a rate of 5 requests per second, aiding in cost management. Telemetry data may be missing in scenarios exceeding this rate. For more information on modifying sampling configuration, see sampling overrides.

Tip

For scenario-specific guidance, see Get Started (Supplemental).

Tip

If you develop a Spring Boot application, you can optionally replace the JVM argument by a programmatic configuration. For more information, see Using Azure Monitor Application Insights with Spring Boot.

Copy the connection string from your Application Insights resource

The connection string is unique and specifies where the Azure Monitor OpenTelemetry Distro sends the telemetry it collects.

Tip

If you don't already have an Application Insights resource, create one following this guide. We recommend you create a new resource rather than using an existing one.

To copy the connection string:

  1. Go to the Overview pane of your Application Insights resource.
  2. Find your connection string.
  3. Hover over the connection string and select the Copy to clipboard icon.

Screenshot that shows Application Insights overview and connection string.

Paste the connection string in your environment

To paste your connection string, select from the following options:

Important

We recommend setting the connection string through code only in local development and test environments.

For production, use an environment variable or configuration file (Java only).

  • Set via environment variable - recommended

    Replace <Your connection string> in the following command with your connection string.

    APPLICATIONINSIGHTS_CONNECTION_STRING=<Your connection string>
    
  • Set via configuration file - Java only

    Create a configuration file named applicationinsights.json, and place it in the same directory as applicationinsights-agent-3.7.1.jar with the following content:

    {
      "connectionString": "<Your connection string>"
    }
    

    Replace <Your connection string> in the preceding JSON with your unique connection string.

  • Set via code - ASP.NET Core, Node.js, and Python only

    See connection string configuration for an example of setting connection string via code.

Note

If you set the connection string in multiple places, the environment variable will be prioritized in the following order:

  1. Code
  2. Environment variable
  3. Configuration file

Confirm data is flowing

Run your application, then open Application Insights in the Azure portal. It might take a few minutes for data to show up.

Screenshot of the Application Insights Overview tab with server requests and server response time highlighted.

Application Insights is now enabled for your application. The following steps are optional and allow for further customization.

Important

If you have two or more services that emit telemetry to the same Application Insights resource, you're required to set Cloud Role Names to represent them properly on the Application Map.

As part of using Application Insights instrumentation, we collect and send diagnostic data to Microsoft. This data helps us run and improve Application Insights. To learn more, see Statsbeat in Azure Application Insights.

Sample applications

Azure Monitor OpenTelemetry sample applications are available for all supported languages:

Next steps