Skip to content

Modify track calls to not modify the passed in dictionary#3119

Merged
harsimar merged 6 commits intomainfrom
harskaur/mutableDictDocumentation
Feb 20, 2026
Merged

Modify track calls to not modify the passed in dictionary#3119
harsimar merged 6 commits intomainfrom
harskaur/mutableDictDocumentation

Conversation

@harsimar
Copy link
Copy Markdown
Member

Related to: #3117

Copilot AI review requested due to automatic review settings February 18, 2026 22:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 fixes a breaking change introduced in 3.x pre-releases where Track* methods mutated the caller's properties dictionary, causing System.NotSupportedException when passing immutable dictionary implementations (common in F# with dict/Map) and ArgumentException on repeated calls with the same dictionary instance.

Changes:

  • Modified TrackEvent, TrackTrace, and TrackException methods to create internal copies of properties dictionaries before adding framework attributes
  • Added comprehensive test coverage for immutable dictionary support and non-mutation guarantees
  • Updated breaking changes documentation to describe the fix

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
BASE/src/Microsoft.ApplicationInsights/TelemetryClient.cs Modified TrackEvent(string, IDictionary), TrackEvent(EventTelemetry), TrackTrace(TraceTelemetry), and TrackException(ExceptionTelemetry) to copy properties before adding internal attributes instead of mutating caller's dictionary
BASE/Test/Microsoft.ApplicationInsights.Test/Microsoft.ApplicationInsights.Tests/TelemetryClientTest.cs Added comprehensive tests verifying non-mutation behavior, immutable dictionary support (ReadOnlyDictionary), and repeated calls with same dictionary for TrackEvent, TrackTrace, and TrackException methods
BreakingChanges.md Added documentation section describing the issue in earlier 3.x pre-releases and confirming the fix ensures all Track* methods no longer mutate caller's dictionaries

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Rajkumar Rangaraj <rajrang@microsoft.com>
@harsimar harsimar merged commit e25bf3f into main Feb 20, 2026
18 checks passed
@harsimar harsimar deleted the harskaur/mutableDictDocumentation branch February 20, 2026 19:15
This was referenced Apr 3, 2026
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.

3 participants