Skip to content

Bump Microsoft.ApplicationInsights to 3.1.2 and add local telemetry export#9725

Draft
Evangelink wants to merge 2 commits into
mainfrom
dev/amauryleve/bump-appinsights
Draft

Bump Microsoft.ApplicationInsights to 3.1.2 and add local telemetry export#9725
Evangelink wants to merge 2 commits into
mainfrom
dev/amauryleve/bump-appinsights

Conversation

@Evangelink

Copy link
Copy Markdown
Member

What

Bumps Microsoft.ApplicationInsights from 2.23.0 to 3.1.2 and adapts our telemetry extension to the 3.x API. Also adds a network-free local telemetry exporter so collected telemetry can be verified after the migration.

Fixes part of #7465.

Why

AppInsights 2.x was pinned because 3.x initially dropped netstandard2.0 (see ApplicationInsights-dotnet#3091). That restriction is gone — 3.1.2 ships netstandard2.0, net462, net8.0, net9.0, net10.0. 3.x is an OpenTelemetry shim (backed by Azure Monitor Exporter), which brings a modern, maintained System.Diagnostics.DiagnosticSource transitively.

Changes

  • Directory.Packages.props: Microsoft.ApplicationInsights 2.23.03.1.2. Removed the explicit System.Diagnostics.DiagnosticSource 6.0.0 pin — its purpose (override AI 2.x's unmaintained transitive 5.0.0) is obsolete; a modern version now flows transitively via Azure.Monitor.OpenTelemetry.ExporterAzure.Core. Keeping the pin caused an NU1605 downgrade error.
  • AppInsightTelemetryClient: 3.x removed the metrics parameter from TrackEvent. We now fold numeric measurements into the event's properties as invariant-culture strings and call the 2-arg overload. This keeps a single correlated, context-enriched customEvent and sidesteps the new OpenTelemetry metric-name syntax restriction (property keys have no such restriction, so no keys need renaming).
  • Local export: new LocalFileTelemetryClient, selected via TESTINGPLATFORM_TELEMETRY_LOCALEXPORTPATH through the existing ITelemetryClientFactory seam. When set, events are written to a file as JSON Lines instead of being shipped to AppInsights — the "local exporter" for verification, no network traffic. Documented in PACKAGE.md.
  • Telemetry schema version bumped 2021 (see below).

⚠️ Dashboard / Kusto query impact

In AI 2.x, numeric measurements were sent in customMeasurements. In 3.x they are folded into customDimensions (as strings). Dashboard queries that read numeric values must be updated, e.g. runStart timings, total ran/total passed counts, mstest.setting.*_timeout, parallelization_workers, etc.

To make the cutover queryable, the platform telemetry schema version (TelemetryProperties.VersionValue, emitted on every event as the telemetry version dimension) is bumped 2021. Dashboards can branch on it:

customEvents
| extend telemetryVersion = toint(customDimensions['telemetry version'])
| extend runStart = iff(telemetryVersion >= 21,
                        todouble(customDimensions['run start']),   // new: AI 3.x, folded into customDimensions
                        toreal(customMeasurements['run start']))    // old: AI 2.x

Testing

  • Telemetry project builds on all TFMs (netstandard2.0/net8.0/net9.0).
  • Microsoft.Testing.Extensions.UnitTests pass on net9.0 (612) and net472 (611), including 4 new LocalFileTelemetryClient/factory tests.
  • Runtime-smoke-verified that the real AI 3.x AppInsightTelemetryClient constructs, tracks, and flushes without throwing (throwaway test, removed).

Open questions for reviewers

  • Live ingestion under VS 2022 / old .NET SDK runtimes: 3.x loads on netstandard2.0/net462, but the actual push now goes through the heavier Azure.Monitor.OpenTelemetry.ExporterAzure.Core stack. Local export bypasses the network, so it does not validate real ingestion. A live smoke test against a (test) AI resource on those hosts is still needed before we're confident — this is the VS-2022 concern from Microsoft.Testing.Extensions.Telemetry blocked from upgrading to latest Microsoft.ApplicationInsights #7465.
  • Dependency surface: this pulls OpenTelemetry + Azure.Core into a shipping package on all TFMs. Acceptable?
  • Should we add a local-export acceptance test (asset that references the Telemetry extension, opts in, sets the export path, asserts the JSON-Lines output)? It would be the only end-to-end coverage of the live 3.x code path. Happy to add in this PR or a follow-up.

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

…xport

Microsoft.ApplicationInsights 3.x is an OpenTelemetry shim whose TrackEvent
overload no longer accepts a metrics dictionary. AppInsightTelemetryClient now
folds numeric measurements into the event's properties (invariant-culture
strings) so telemetry stays a single correlated, context-enriched customEvent
and avoids the OpenTelemetry metric-name-syntax restriction. The obsolete
explicit System.Diagnostics.DiagnosticSource pin is removed (a modern version
now flows transitively via Azure.Monitor.OpenTelemetry.Exporter -> Azure.Core).

Adds a network-free local exporter: setting TESTINGPLATFORM_TELEMETRY_LOCALEXPORTPATH
writes collected events to a file as JSON Lines via LocalFileTelemetryClient,
selected through the existing ITelemetryClientFactory seam, so telemetry can be
verified locally after the bump.

Fixes part of #7465

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 09:00
…t change

Numeric measurements now land in customDimensions (folded into event properties)
rather than customMeasurements. Bumping the schema version stamped on every event
lets telemetry dashboards branch old vs new query shapes on the boundary.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR upgrades Microsoft.ApplicationInsights from 2.23.0 to 3.1.2 in the Microsoft.Testing.Extensions.Telemetry MTP extension and adapts the code to the 3.x (OpenTelemetry-shim) API. Since 3.x removed the metrics parameter from TrackEvent, numeric measurements are now folded into the event's properties (i.e. customDimensions) as invariant-culture strings. It also introduces a network-free LocalFileTelemetryClient (selected via TESTINGPLATFORM_TELEMETRY_LOCALEXPORTPATH) that writes events to disk as JSON Lines for local verification, and removes the now-obsolete explicit System.Diagnostics.DiagnosticSource 6.0.0 pin.

Changes:

  • Bump Microsoft.ApplicationInsights to 3.1.2 and drop the explicit System.Diagnostics.DiagnosticSource pin (now flows transitively).
  • Adapt AppInsightTelemetryClient.TrackEvent to fold numeric metrics into event properties for the 3.x 2-arg overload.
  • Add opt-in LocalFileTelemetryClient + factory wiring via a new env var, with unit tests and PACKAGE.md docs.
Show a summary per file
File Description
Directory.Packages.props Bumps AppInsights to 3.1.2 and removes the DiagnosticSource pin/comment.
.../Microsoft.Testing.Extensions.Telemetry.csproj Removes the explicit System.Diagnostics.DiagnosticSource package reference.
.../AppInsightTelemetryClient.cs Folds numeric metrics into properties to fit the 3.x TrackEvent API.
.../AppInsightTelemetryClientFactory.cs Adds optional local-export path; returns LocalFileTelemetryClient when set.
.../AppInsightsProvider.cs Adds the TESTINGPLATFORM_TELEMETRY_LOCALEXPORTPATH env-var constant.
.../AppInsightsTelemetryProviderExtensions.cs Reads the local-export env var and passes it to the factory.
.../LocalFileTelemetryClient.cs New JSON-Lines local telemetry client with manual JSON escaping.
.../PACKAGE.md Documents the new local-export verification option.
.../LocalFileTelemetryClientTests.cs New unit tests for the local client and factory selection.

Review details

  • Files reviewed: 10/10 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment on lines +43 to +49
var combinedProperties = new Dictionary<string, string>(properties);
foreach (KeyValuePair<string, double> metric in metrics)
{
combinedProperties[metric.Key] = metric.Value.ToString("R", CultureInfo.InvariantCulture);
}

_telemetryClient.TrackEvent(eventName, combinedProperties);
Copilot AI review requested due to automatic review settings July 8, 2026 09:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 10/10 changed files
  • Comments generated: 2
  • Review effort level: Medium

@@ -0,0 +1,140 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
@@ -0,0 +1,95 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
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