Edit

Share via


Migrate from Application Insights Classic API SDKs to Azure Monitor OpenTelemetry

This guide provides step-by-step instructions to migrate applications from using Application Insights SDKs (Classic API) to Azure Monitor OpenTelemetry.

Expect a similar experience with Azure Monitor OpenTelemetry instrumentation as with the Application Insights SDKs. For more information and a feature-by-feature comparison, see release state of features.

Use Application Insights .NET software development kit (SDK) 3.x to upgrade from Application Insights .NET SDK 2.x to an OpenTelemetry (OTel)-based implementation. The 3.x SDK keeps most TelemetryClient and TelemetryConfiguration application programming interfaces (APIs) and uses the Azure Monitor OpenTelemetry Exporter to send telemetry to Application Insights.

Most classic Track* calls continue to work after the upgrade, but they're routed through an internal mapping layer that emits OpenTelemetry signals.

If you build a new application or you already use the Azure Monitor OpenTelemetry Distro, use the Azure Monitor OpenTelemetry Distro instead. Don't use Application Insights .NET SDK 3.x and the Azure Monitor OpenTelemetry Distro in the same application.

Application Insights .NET SDK 3.x overview

Application Insights .NET SDK 3.x provides these NuGet packages:

  • Microsoft.ApplicationInsights for TelemetryClient and TelemetryConfiguration
  • Microsoft.ApplicationInsights.AspNetCore for ASP.NET (Active Server Pages .NET) Core web apps
  • Microsoft.ApplicationInsights.WorkerService for Worker Service and console apps
  • Microsoft.ApplicationInsights.Web for ASP.NET apps on .NET Framework
  • Microsoft.ApplicationInsights.NLogTarget for NLog integration (beta)

Use the repository documentation for code examples and detailed migration guidance:

Upgrade to 3.x

Step 1: Remove references to incompatible packages

Remove these packages because they aren't compatible with SDK 3.x:

  • Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel
  • Microsoft.ApplicationInsights.DependencyCollector
  • Microsoft.ApplicationInsights.EventCounterCollector
  • Microsoft.ApplicationInsights.PerfCounterCollector
  • Microsoft.ApplicationInsights.WindowsServer
  • Microsoft.Extensions.Logging.ApplicationInsights
  • Microsoft.ApplicationInsights.Log4NetAppender
  • Microsoft.ApplicationInsights.TraceListener
  • Microsoft.ApplicationInsights.DiagnosticSourceListener
  • Microsoft.ApplicationInsights.EtwCollector
  • Microsoft.ApplicationInsights.EventSourceListener

SDK 3.x doesn't publish 3.x versions of these packages. Use the supported 3.x packages listed in Application Insights .NET SDK 3.x overview instead. The following sections describe the intended replacements for these packages. In some cases, the functionality is built into the supported 3.x packages or replaced by OpenTelemetry APIs.

Note

This list includes only Microsoft packages. If you use third-party packages that depend on Microsoft.ApplicationInsights 2.x (for example, Serilog.Sinks.ApplicationInsights), verify those packages support SDK 3.x before upgrading. Follow guidance from the package maintainers.

Step 2: Upgrade package versions to 3.x

Upgrade any remaining supported Application Insights packages to the latest 3.x version.

Important

Don't mix Application Insights 2.x and 3.x packages in the same application. Upgrade all Application Insights package references together.

Step 3: Update code and configuration for breaking changes

Review both the breaking changes reference and the detailed migration guidance. Most applications need to update code or configuration in one or more of the following areas:

2.x API, setting, or pattern 3.x guidance
TrackPageView Remove TrackPageView calls. Page view tracking is removed in the .NET 3.x SDK.
TrackEvent, TrackException, and TrackAvailability overloads that include IDictionary<string, double> metrics Remove the custom metrics parameter. Track metrics separately by using TrackMetric().
GetMetric overloads that use MetricConfiguration or MetricAggregationScope Use the simplified GetMetric overloads. Metrics configuration and aggregation are managed internally in SDK 3.x.
InstrumentationKey configuration or TelemetryClient.InstrumentationKey Use TelemetryConfiguration.ConnectionString and provide a connection string instead of an instrumentation key. SDK 3.x requires a connection string and can fail at startup if one isn't configured. For test scenarios, you can use a dummy connection string such as InstrumentationKey=00000000-0000-0000-0000-000000000000.
TelemetryClient() or TelemetryConfiguration.Active Create a configuration explicitly by using TelemetryConfiguration.CreateDefault(), and pass it to new TelemetryClient(config).
TelemetryModule, TelemetryInitializer, or TelemetryProcessor customization Custom initializers or processors should be migrated to OpenTelemetry-based processors. References to built-in 2.x processors, initializers, and modules should be removed. For more information, see migration guidance.
ITelemetryChannel or TelemetryConfiguration.TelemetryChannel The classic channel abstraction is removed because 3.x internally incorporates the Azure Monitor exporter. For tests, use OpenTelemetry-friendly validation such as an in-memory exporter.
EnableAdaptiveSampling Replace adaptive sampling with TracesPerSecond or SamplingRatio.
Microsoft.ApplicationInsights.Web targeting .NET Framework 4.5.2 Target .NET Framework 4.6.2 or later.
Metric name and namespace conventions To follow OpenTelemetry instrument naming syntax, update the name, metricId, and metricNamespace values used with TrackMetric(), GetMetric(), and MetricIdentifier. Metric names and namespaces must start with a letter and can contain only letters, digits, _, ., -, or /. Spaces aren't allowed.

Replace removed extensibility points

Application Insights .NET SDK 2.x provided Application Insights-specific extensibility types such as telemetry modules, initializers, processors, and channels. Application Insights .NET SDK 3.x uses OpenTelemetry extensibility instead.

For detailed guidance on replacing 2.x extensibility points, including edge cases, see migration guidance.

Tip

Resource-based values such as role metadata can flow through OpenTelemetry resource mappings instead of appearing on every telemetry item. If you need a key-value pair on every telemetry item, use GlobalProperties or a custom processor.

Configure sampling

Application Insights .NET SDK 3.x supports two sampling modes for traces (requests and dependencies):

  • Set SamplingRatio (0.0 to 1.0) for percentage-based sampling.
  • Set TracesPerSecond for rate-limited sampling (default: Five traces per second).

SDK 3.x applies the same sampling settings to requests and dependencies. SDK 3.x doesn't support separate sampling settings for requests and dependencies.

When a request or dependency is sampled in, SDK 3.x applies the sampling decision of the parent trace to related logs by default. To disable that behavior, set EnableTraceBasedLogsSampler to false.

You can set SamplingRatio, TracesPerSecond, and EnableTraceBasedLogsSampler in TelemetryConfiguration, appsettings.json, or applicationinsights.config.

Troubleshoot an upgrade

Use these steps to validate telemetry during an upgrade to SDK 3.x:

  • Confirm that a full connection string is configured before startup. If you validate telemetry in tests without a real resource, use a dummy connection string.
  • Collect Application Insights self-diagnostics logs to identify configuration errors and exporter failures.
  • Add the OpenTelemetry console exporter to verify that traces, metrics, and logs emit as expected before you rely on Azure Monitor ingestion.
  • If you previously unit tested telemetry by mocking ITelemetryChannel, switch to OpenTelemetry-friendly validation such as in-memory exporters or other test exporters in nonproduction environments.
  • Confirm that sampling settings behave as expected by validating parent-child trace decisions.
  • Validate resource attributes such as service name, role name, role instance, and environment to ensure correct attribution in Application Insights.
  • If you migrated custom enrichment, verify that your properties appear where you expect. Resource-based mappings can differ from 2.x behavior.

For detailed troubleshooting guidance and examples, use the following resources:

OpenTelemetry Terminology

For terminology, see the glossary in the OpenTelemetry specifications.

The following table highlights legacy terms used in Application Insights and their OpenTelemetry replacements.

Application Insights OpenTelemetry
Autocollectors Instrumentation libraries
Channel Exporter
Codeless / Agent-based Autoinstrumentation
Traces Logs
Requests Server Spans
Dependencies Other Span Types (Client, Internal, etc.)
Operation ID Trace ID
ID or Operation Parent ID Span ID