Edit

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

Note

For .NET, Node.js, and Python applications:

For Java applications, use the Azure Monitor OpenTelemetry Distro.

For AI-assisted instrumentation guidance, see the Application Insights instrumentation skill. For guided setup and analysis of existing Application Insights instrumentation, see the Azure MCP Server tools for Azure Monitor.

This guidance shows you how to add observability to your application with Microsoft OpenTelemetry Distro. The Distro automatically collects traces, metrics, and logs with built-in instrumentations, and exports the telemetry to Azure Monitor, any OpenTelemetry Protocol (OTLP) endpoint, or Microsoft Agent 365.

For other collection and export options, see OpenTelemetry with Azure Monitor.

OpenTelemetry release status

For package details and release notes, see Next steps.

Note

For Azure Function Apps, see Use OpenTelemetry with Azure Functions.

Enable OpenTelemetry with Application Insights

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

The Microsoft OpenTelemetry Distro package identifiers and install commands are:

Language Package Install command
Python microsoft-opentelemetry pip install microsoft-opentelemetry
Node.js @microsoft/opentelemetry npm install @microsoft/opentelemetry
.NET Microsoft.OpenTelemetry dotnet add package Microsoft.OpenTelemetry

For Java, use the agent or native-image integration described in the Java and Java native tabs.

Use the ASP.NET Core tab for web applications and the .NET tab for console and other non-hosted applications.

Prerequisites

Tip

If you're upgrading from Application Insights .NET SDK 2.x, follow the SDK 3.x migration guidance. That upgrade doesn't require switching to the Microsoft OpenTelemetry Distro.

Install the client library

Note

These installation steps are for applications that use the Microsoft OpenTelemetry Distro. They aren't an upgrade requirement for existing Azure Monitor OpenTelemetry Distro users. Don't initialize both distros in the same application. Standalone Azure Monitor exporter packages keep their existing names.

Install the Microsoft.OpenTelemetry NuGet package:

dotnet add package Microsoft.OpenTelemetry

Modify your application

Initialize the Microsoft OpenTelemetry Distro before your application starts handling work. The following examples select Azure Monitor as the destination and read the connection string from the APPLICATIONINSIGHTS_CONNECTION_STRING environment variable. Set that variable before starting your application, as described later in this article.

You can also set the connection string in code. For .NET, use options.AzureMonitor.ConnectionString inside UseMicrosoftOpenTelemetry(). For all supported languages, see Connection string configuration.

In Program.cs, configure the application builder to use the Microsoft OpenTelemetry Distro:

// Import the distro API.
using Microsoft.OpenTelemetry;

// Create the application builder.
var builder = WebApplication.CreateBuilder(args);

// Initialize the Microsoft OpenTelemetry Distro with Azure Monitor export.
builder.UseMicrosoftOpenTelemetry(options =>
{
    options.Exporters = ExportTarget.AzureMonitor;
});

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

Copy the connection string from your Application Insights resource

The connection string identifies the Application Insights resource that receives your telemetry.

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, use one of the following methods:

Method Supported languages Recommended for
Environment variable All Production
Configuration file (applicationinsights.json) Java only Production (Java)
Code .NET, Node.js, Python Local dev/test only

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 the Application Insights connection string as an environment variable (recommended for production)

    In Bash:

    export APPLICATIONINSIGHTS_CONNECTION_STRING="<ConnectionString>"
    

    In PowerShell:

    $env:APPLICATIONINSIGHTS_CONNECTION_STRING = "<ConnectionString>"
    
  • Set the Application Insights connection string in a configuration file - Java only

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

        {
            "connectionString": "<ConnectionString>"
        }
    
  • Set the Application Insights connection string in code - .NET, Node.js, and Python only

    For Microsoft OpenTelemetry Distro options, see the .NET, Node.js, or Python documentation.

Confirm data is flowing

After you configure the distro and set the connection string, run your application and generate traffic or log messages. Open your Application Insights resource in the Azure portal to verify that telemetry appears. 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.

Note

As part of using Application Insights instrumentation, we collect and send diagnostic data to Microsoft. This data helps us run and improve Application Insights. Learn more in the Application Insights FAQ.

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.

Troubleshooting, feedback, and support

Tip

The following sections are available across all OpenTelemetry Distro articles.

Troubleshooting

OpenTelemetry Feedback

To provide feedback:

Support

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

Next steps