Skip to content

WIP: Migrate ApplicationInsights to v3 with OpenTelemetry Activities#1505

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/update-application-insights-sdk
Draft

WIP: Migrate ApplicationInsights to v3 with OpenTelemetry Activities#1505
Copilot wants to merge 5 commits intomainfrom
copilot/update-application-insights-sdk

Conversation

Copy link
Contributor

Copilot AI commented Feb 11, 2026

Application Insights SDK v3 removed TrackPageView and PageViewTelemetry in favor of OpenTelemetry. View tracking now uses Activities with ActivityKind.Server to generate request telemetry.

Changes

  • Package: Microsoft.ApplicationInsights 2.23.0 → 3.0.0 (OpenTelemetry comes transitively)

  • ApplicationInsightsViewTracking constructor: Takes ActivitySource instead of TelemetryClient

  • View navigation: Stops previous activity, starts new ActivityKind.Server activity with semantic convention tags:

    • HTTP tags: http.url, http.method, http.scheme, url.scheme, url.path
    • Custom tags: view.name, view.type
  • Thread safety: Documented not thread-safe (matches existing APM implementations)

Usage

// Before
var telemetryClient = new TelemetryClient(config);
var viewTracking = new ApplicationInsightsViewTracking(telemetryClient);

// After  
var activitySource = new ActivitySource("MyApp");
var viewTracking = new ApplicationInsightsViewTracking(activitySource);

// IViewTracking.OnViewNavigation(string) unchanged - non-breaking at interface level
viewTracking.OnViewNavigation("HomePage");

Note: ApplicationInsightsFeatureUsageTrackingSession unchanged - TrackEvent and TrackException still supported in v3.

Original prompt

Problem

Application Insights SDK v3 for .NET has removed the TrackPageView method and PageViewTelemetry class. The current implementation in src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs uses these deprecated APIs and will not compile with Application Insights v3.

According to Microsoft's official documentation, Application Insights v3 is built on OpenTelemetry, and page view tracking should be done using OpenTelemetry Activities with ActivityKind.Server to generate request telemetry.

Required Changes

1. Update Package Version

In src/Directory.Packages.props, update the Microsoft.ApplicationInsights version from 2.23.0 to 3.0.0:

<PackageVersion Include="Microsoft.ApplicationInsights" Version="3.0.0" />

Note: OpenTelemetry packages will come in transitively from Microsoft.ApplicationInsights 3.0.0, so no additional package references are needed in the csproj.

2. Rewrite ApplicationInsightsViewTracking.cs

Update src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs to use OpenTelemetry Activities:

Key Requirements:

  • Constructor should accept ActivitySource instead of TelemetryClient
  • Use ActivityKind.Server so page views appear as requests in Application Insights (not custom events)
  • Track the current page activity and stop it when navigating to a new view
  • Set standard HTTP semantic convention tags:
    • http.url - the view URL
    • http.method - set to "GET"
    • http.scheme or url.scheme - set to "view"
    • url.path - the view path
  • Add custom tags like view.name and view.type for filtering
  • Follow Splat coding standards from .editorconfig:
    • Allman brace style (opening brace on new line)
    • Private fields use _camelCase
    • Use var for local variables
    • 4-space indentation

Implementation approach:

  • Store a private Activity? _currentPageActivity field
  • When OnViewNavigation is called, stop the previous activity and start a new one
  • The activity lifetime automatically tracks the duration

3. Update Tests

Update src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs:

  • Change the test to create an ActivitySource instead of TelemetryClient
  • The test should instantiate ApplicationInsightsViewTracking with the ActivitySource
  • Keep the existing test inheritance structure (BaseViewTrackingTests.ConstructorMethod)

4. Maintain IViewTracking Interface

The IViewTracking interface in src/Splat/ApplicationPerformanceMonitoring/IViewTracking.cs should NOT be modified - it only has:

void OnViewNavigation(string name);

This is a non-breaking change at the interface level.

References

Success Criteria

  • ✅ Application Insights package updated to 3.0.0 in Directory.Packages.props
  • ✅ No additional explicit package references added (OpenTelemetry comes transitively)
  • ✅ ApplicationInsightsViewTracking uses ActivitySource and ActivityKind.Server
  • ✅ Activities have proper semantic convention tags for Application Insights
  • ✅ Tests compile and pass
  • ✅ Code follows Splat style guidelines
  • ✅ IViewTracking interface remains unchanged (non-breaking for consumers)

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 11, 2026 09:36
Co-authored-by: dpvreony <170983+dpvreony@users.noreply.github.com>
Co-authored-by: dpvreony <170983+dpvreony@users.noreply.github.com>
Copilot AI changed the title [WIP] Update Application Insights SDK to version 3.0.0 Migrate ApplicationInsights to v3 with OpenTelemetry Activities Feb 11, 2026
Copilot AI requested a review from dpvreony February 11, 2026 09:42
@dpvreony dpvreony changed the title Migrate ApplicationInsights to v3 with OpenTelemetry Activities WIP: Migrate ApplicationInsights to v3 with OpenTelemetry Activities Feb 11, 2026
_ = GetPageViewTelemetry();
telemetryClient.TrackPageView(telemetry);
}
var tags = new KeyValuePair<string, object?>[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: check how this compares to a Javascript SDK page view in Application Insights dashboard and queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants