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
- ✅ 1: OpenTelemetry is available to all customers with formal support.
- ⚠️ 2: OpenTelemetry is available as a public preview. Supplemental Terms of Use for Microsoft Azure Previews
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
- An Azure subscription: Create an Azure subscription for free
- An Application Insights resource: Create an Application Insights resource
- 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:
- Go to the Overview pane of your Application Insights resource.
- Find your Connection String.
- 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:
- Code
- Environment Variable
- 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.
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
- For Azure support issues, open an Azure support ticket.
- For OpenTelemetry issues, contact the OpenTelemetry .NET community directly.
- For a list of open issues related to Azure Monitor Exporter, see the GitHub Issues Page.
OpenTelemetry feedback
To provide feedback:
- Fill out the OpenTelemetry community's customer feedback survey.
- Tell Microsoft about yourself by joining the OpenTelemetry Early Adopter Community.
- Engage with other Azure Monitor users in the Microsoft Tech Community.
- Make a feature request at the Azure Feedback Forum.
Next steps
- For details on adding and modifying Azure Monitor OpenTelemetry, see Add and modify Azure Monitor OpenTelemetry
- To further configure the OpenTelemetry distro, see Azure Monitor OpenTelemetry configuration
- To review the source code, see the Azure Monitor AspNetCore GitHub repository.
- To install the NuGet package, check for updates, or view release notes, see the Azure Monitor AspNetCore NuGet Package page.
- To become more familiar with Azure Monitor and OpenTelemetry, see the Azure Monitor Example Application.
- To learn more about OpenTelemetry and its community, see the OpenTelemetry .NET GitHub repository.
- To enable usage experiences, enable web or browser user monitoring.
Feedback
Submit and view feedback for