-
Notifications
You must be signed in to change notification settings - Fork 848
[OpenTelemetry.Api] Resolve CA1815 #6595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Resolve `CA1815` warnings for `LogRecordAttributeList` and `LogRecordData`.
- Add tests for CA1815 fixes. - Fix `LogRecordAttributeList.GetHashCode()`.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6595 +/- ##
==========================================
+ Coverage 86.64% 86.73% +0.08%
==========================================
Files 258 258
Lines 11910 11961 +51
==========================================
+ Hits 10320 10374 +54
+ Misses 1590 1587 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this 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 resolves CA1815 analyzer warnings by implementing equality operations for LogRecordAttributeList
and LogRecordData
structs. The changes ensure these value types properly override Equals
, GetHashCode
, and implement equality operators as required by the CA1815 rule.
Key changes:
- Implement
IEquatable<T>
interface for both structs - Add equality operators (
==
and!=
) with appropriate documentation - Override
Equals
andGetHashCode
methods with proper implementations
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/OpenTelemetry.Api/Logs/LogRecordData.cs | Implements equality operations and removes CA1815 pragma warning suppression |
src/OpenTelemetry.Api/Logs/LogRecordAttributeList.cs | Implements equality operations and removes CA1815 pragma warning suppression |
test/OpenTelemetry.Api.Tests/Logs/LogRecordDataTests.cs | Adds comprehensive test coverage for equality operations |
test/OpenTelemetry.Api.Tests/Logs/LogRecordAttributeListTests.cs | Adds comprehensive test coverage for equality operations |
src/OpenTelemetry.Api/.publicApi/Experimental/PublicAPI.Unshipped.txt | Updates public API tracking with new equality methods |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
[OTEL1001]OpenTelemetry.Logs.LogRecordSeverity.Warn3 = 15 -> OpenTelemetry.Logs.LogRecordSeverity | ||
[OTEL1001]OpenTelemetry.Logs.LogRecordSeverity.Warn4 = 16 -> OpenTelemetry.Logs.LogRecordSeverity | ||
[OTEL1001]OpenTelemetry.Logs.LogRecordSeverityExtensions | ||
[OTEL1001]override OpenTelemetry.Logs.LogRecordAttributeList.Equals(object? obj) -> bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a strong reason why you want to increase the public API surface to remove the CA1815
suppression from the code?
CA1815
is a performance-oriented warning, but implementing Equals, GetHashCode, and equality operators (==, !=) on these structs would expose them as public APIs. This means:
- API stability commitment - Once these are public, we're committed to maintaining them
- Use case unclear - Are users actually comparing these structs or using them in hash-based collections where the default implementation would be problematic?
- Suppression is valid - If these structs aren't intended to be compared or hashed, suppressing CA1815 is the appropriate choice
If there's no demonstrated performance issue or user scenario requiring these equality members, it's better to keep the suppression rather than expanding the public API surface. Can you share the specific use case that necessitates implementing these methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I defer to the linked issue which tracks doing the work to remove the suppressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created this issue while working on enabling <AnalysisLevel>latest-all</AnalysisLevel>
across whole repository.
Touching public API was fully out of scope of this task so I created this one. I suppose that Raj's comment might be important, but it is still going case by case if it is worth to add all these methods. If not, it will be great to extend warning comments that is it no needed, and perf was tested.
This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
Contributes to #6278.
Changes
Resolve
CA1815
warnings forLogRecordAttributeList
andLogRecordData
.Merge requirement checklist
CHANGELOG.md
files updated for non-trivial changes