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

This article describes how to enable and configure OpenTelemetry-based data collection to power the experiences within Azure Monitor Application Insights. We walk through how to install the "Azure Monitor OpenTelemetry Distro." The Distro automatically collects traces, metrics, logs, and exceptions across your application and its dependencies. To learn more about collecting data using OpenTelemetry, see Data Collection Basics or OpenTelemetry FAQ.

OpenTelemetry Release Status

OpenTelemetry offerings are available for .NET, Node.js, Python and Java applications.

Language Release Status
ASP.NET Core ⚠️ 2
.NET (Exporter) 1
Java 1
Node.js 1
Python 1

Footnotes

Note

For a feature-by-feature release status, see the FAQ. The ASP.NET Core Distro is undergoing additional stability testing prior to GA. You can use the .NET Exporter if you need a fully supported OpenTelemetry solution for your ASP.NET Core application.

Get started

Follow the steps in this section to instrument your application with OpenTelemetry.

Prerequisites

Tip

We don't recommend using the OTel Community SDK/API with the Azure Monitor OTel Distro since it automatically loads them as dependencies.

Install the client library

Install the latest Azure.Monitor.OpenTelemetry.AspNetCore NuGet package:

dotnet add package --prerelease Azure.Monitor.OpenTelemetry.AspNetCore 

Enable Azure Monitor Application Insights

To enable Azure Monitor Application Insights, you make a minor modification to your application and set your "Connection String." The Connection String tells your application where to send the telemetry the Distro collects, and it's unique to you.

Modify your Application

Add UseAzureMonitor() to your application startup. Depending on your version of .NET, it is in either your startup.cs or program.cs class.

// Import the Azure.Monitor.OpenTelemetry.AspNetCore namespace.
using Azure.Monitor.OpenTelemetry.AspNetCore;

// Create a new WebApplicationBuilder instance.
var builder = WebApplication.CreateBuilder(args);

// Add the OpenTelemetry NuGet package to the application's services and configure OpenTelemetry to use Azure Monitor.
builder.Services.AddOpenTelemetry().UseAzureMonitor();

// Build the application.
var app = builder.Build();

// Run the application.
app.Run();

Copy the Connection String from your Application Insights Resource

Tip

If you don't already have one, now is a great time to Create an Application Insights Resource. Here's when we recommend you create a new Application Insights Resource versus use an existing one.

To copy your unique Connection String:

Screenshot that shows Application Insights overview and 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.

Paste the Connection String in your environment

To paste your Connection String, select from the following options:

A. Set via Environment Variable (Recommended)

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

APPLICATIONINSIGHTS_CONNECTION_STRING=<Your Connection String>

B. Set via Configuration File - Java Only (Recommended)

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

{
  "connectionString": "<Your Connection String>"
}

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

C. Set via Code - ASP.NET Core, Node.js, and Python Only (Not recommended)

See Connection String Configuration for an example of setting Connection String via code.

Note

If you set the connection string in more than one place, we adhere to the following precendence:

  1. Code
  2. Environment Variable
  3. Configuration File

Confirm data is flowing

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

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

You've now enabled Application Insights for your application. All 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.

Troubleshooting

Not working? Check out the troubleshooting page for ASP.NET Core.

Support

Select a tab for the language of your choice to discover support options.

OpenTelemetry feedback

To provide feedback:

Next steps