Bump Microsoft.ApplicationInsights to 3.1.2 and add local telemetry export#9725
Draft
Evangelink wants to merge 2 commits into
Draft
Bump Microsoft.ApplicationInsights to 3.1.2 and add local telemetry export#9725Evangelink wants to merge 2 commits into
Evangelink wants to merge 2 commits into
Conversation
…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>
…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>
Contributor
There was a problem hiding this comment.
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.ApplicationInsightsto3.1.2and drop the explicitSystem.Diagnostics.DiagnosticSourcepin (now flows transitively). - Adapt
AppInsightTelemetryClient.TrackEventto 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 andPACKAGE.mddocs.
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); |
| @@ -0,0 +1,140 @@ | |||
| // Copyright (c) Microsoft Corporation. All rights reserved. | |||
| @@ -0,0 +1,95 @@ | |||
| // Copyright (c) Microsoft Corporation. All rights reserved. | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Bumps
Microsoft.ApplicationInsightsfrom2.23.0to3.1.2and 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 shipsnetstandard2.0,net462,net8.0,net9.0,net10.0. 3.x is an OpenTelemetry shim (backed by Azure Monitor Exporter), which brings a modern, maintainedSystem.Diagnostics.DiagnosticSourcetransitively.Changes
Directory.Packages.props:Microsoft.ApplicationInsights2.23.0→3.1.2. Removed the explicitSystem.Diagnostics.DiagnosticSource6.0.0 pin — its purpose (override AI 2.x's unmaintained transitive 5.0.0) is obsolete; a modern version now flows transitively viaAzure.Monitor.OpenTelemetry.Exporter→Azure.Core. Keeping the pin caused anNU1605downgrade error.AppInsightTelemetryClient: 3.x removed themetricsparameter fromTrackEvent. 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-enrichedcustomEventand sidesteps the new OpenTelemetry metric-name syntax restriction (property keys have no such restriction, so no keys need renaming).LocalFileTelemetryClient, selected viaTESTINGPLATFORM_TELEMETRY_LOCALEXPORTPATHthrough the existingITelemetryClientFactoryseam. 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 inPACKAGE.md.20→21(see below).In AI 2.x, numeric measurements were sent in
customMeasurements. In 3.x they are folded intocustomDimensions(as strings). Dashboard queries that read numeric values must be updated, e.g.runStarttimings,total ran/total passedcounts,mstest.setting.*_timeout,parallelization_workers, etc.To make the cutover queryable, the platform telemetry schema version (
TelemetryProperties.VersionValue, emitted on every event as thetelemetry versiondimension) is bumped20→21. Dashboards can branch on it:Testing
netstandard2.0/net8.0/net9.0).Microsoft.Testing.Extensions.UnitTestspass onnet9.0(612) andnet472(611), including 4 newLocalFileTelemetryClient/factory tests.AppInsightTelemetryClientconstructs, tracks, and flushes without throwing (throwaway test, removed).Open questions for reviewers
netstandard2.0/net462, but the actual push now goes through the heavierAzure.Monitor.OpenTelemetry.Exporter→Azure.Corestack. 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.Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com