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 will automatically collect traces, metrics, logs, and exceptions across your application and its dependencies. The 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
Java ✅ 1
.NET ⚠️ 2
Node.js ⚠️ 2
Python ⚠️ 2

Footnotes

Note

For a feature-by-feature release status, see the FAQ.

Get started

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

Prerequisites

  • Application using an officially supported version of .NET Core or .NET Framework that's at least .NET Framework 4.6.2

Caution

We have not tested the Azure Monitor OpenTelemetry Distro running side-by-side with the OpenTelemetry Community Package. We recommend you uninstall any OpenTelemetry-related packages before installing the Distro.

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.

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry().UseAzureMonitor();

var app = builder.Build();

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.14.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 example 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.

That's it. Your application is now monitored by Application Insights. Everything else below is optional and available for further customization.

Not working? Check out the troubleshooting page for ASP.NET Core, Java, Node.js, or Python.

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.

Support

OpenTelemetry feedback

To provide feedback:

Next steps