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
- ✅ 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. 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
- An Azure subscription: Create an Azure subscription for free
- An Application Insights resource: Create an Application Insights resource
- ASP.NET Core Application using an officially supported version of .NET Core
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:
- 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.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:
- 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.
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.
- 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