Skip to content

Conversation

martincostello
Copy link
Member

Contributes to #6278.

Changes

Resolve CA1815 warnings for LogRecordAttributeList and LogRecordData.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Resolve `CA1815` warnings for `LogRecordAttributeList` and `LogRecordData`.
- Add tests for CA1815 fixes.
- Fix `LogRecordAttributeList.GetHashCode()`.
@github-actions github-actions bot added the pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package label Oct 9, 2025
Copy link

codecov bot commented Oct 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.73%. Comparing base (9a18f76) to head (ed8165c).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests-Project-Experimental 86.67% <100.00%> (+0.14%) ⬆️
unittests-Project-Stable 86.30% <100.00%> (-0.30%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...c/OpenTelemetry.Api/Logs/LogRecordAttributeList.cs 74.43% <100.00%> (+4.79%) ⬆️
src/OpenTelemetry.Api/Logs/LogRecordData.cs 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

@martincostello martincostello marked this pull request as ready for review October 9, 2025 15:52
@martincostello martincostello requested a review from a team as a code owner October 9, 2025 15:52
@Copilot Copilot AI review requested due to automatic review settings October 9, 2025 15:52
Copy link

@Copilot 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 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 and GetHashCode 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
Copy link
Member

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:

  1. API stability commitment - Once these are public, we're committed to maintaining them
  2. Use case unclear - Are users actually comparing these structs or using them in hash-based collections where the default implementation would be problematic?
  3. 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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Contributor

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.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package Stale Issues and pull requests which have been flagged for closing due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants