Modify track calls to not modify the passed in dictionary#3119
Merged
Modify track calls to not modify the passed in dictionary#3119
Conversation
Contributor
There was a problem hiding this comment.
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, andTrackExceptionmethods 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.
rajkumar-rangaraj
approved these changes
Feb 19, 2026
rajkumar-rangaraj
approved these changes
Feb 20, 2026
Co-authored-by: Rajkumar Rangaraj <rajrang@microsoft.com>
rajkumar-rangaraj
approved these changes
Feb 20, 2026
This was referenced Apr 2, 2026
Open
This was referenced Apr 3, 2026
Open
Merged
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.
Related to: #3117