[Infra] Disallow instance string.Equals methods#7210
Conversation
- Disallow use of string instance `Equals()` methods and require the static versions be used instead. - Apply minor refactoring suggested by Visual Studio in files touched. - Make some comments clearer.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7210 +/- ##
==========================================
- Coverage 89.53% 89.50% -0.03%
==========================================
Files 272 272
Lines 13345 13343 -2
==========================================
- Hits 11948 11943 -5
- Misses 1397 1400 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Pull request overview
This PR updates repository-wide conventions to disallow instance string.Equals(...) calls (via banned API enforcement) and refactors touched call sites to use the corresponding static string.Equals(...) overloads, along with a few small readability refactors.
Changes:
- Add banned-symbol rules for
System.String.Equals(string)andSystem.String.Equals(string, StringComparison)to enforce staticstring.Equals(...). - Replace instance
Equalsusages across metrics, propagators, OTLP exporter, shims, and shared helpers with staticstring.Equals(...). - Apply minor refactors (expression-bodied members, null-conditional dispose) and clarify performance-related comments.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/StatusHelper.cs | Refactors to expression-bodied switch and replaces instance Equals with static string.Equals. |
| src/OpenTelemetry/Metrics/Tags.cs | Uses static string.Equals for tag-key comparisons; minor formatting refactor. |
| src/OpenTelemetry/Metrics/StringArrayEqualityComparer.cs | Uses pattern-matching null checks and static string.Equals for element comparisons. |
| src/OpenTelemetry/Metrics/Builder/MeterProviderBuilderExtensions.cs | Replaces instance Equals in view matching; refactors Build to expression-bodied form. |
| src/OpenTelemetry/Internal/SelfDiagnosticsConfigRefresher.cs | Replaces instance Equals for directory compare; simplifies disposal with null-conditional operators. |
| src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs | Uses static string.Equals for special OpenTracing tag key handling. |
| src/OpenTelemetry.Shims.OpenTracing/SpanBuilderShim.cs | Uses static string.Equals for OpenTracing tag key comparisons. |
| src/OpenTelemetry.Extensions.Propagators/JaegerPropagator.cs | Uses static string.Equals for sampled-flag parsing. |
| src/OpenTelemetry.Extensions.Propagators/B3Propagator.cs | Uses static string.Equals for flags parsing (Recorded decision). |
| src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Serializer/ProtobufOtlpTraceSerializer.cs | Uses static string.Equals in status tag-value mapping and clarifies perf comment wording. |
| src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Serializer/ProtobufOtlpLogSerializer.cs | Uses static string.Equals for {OriginalFormat} attribute detection. |
| src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcExportClient.cs | Uses static string.Equals for gRPC “no reply detail” detection. |
| src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs | Uses static string.Equals for env-var parsing and refactors disk-path requirement logic. |
| src/OpenTelemetry.Api/Context/Propagation/B3Propagator.cs | Uses static string.Equals for flags parsing (Recorded decision). |
| build/BannedSymbols.txt | Adds banned API entries preventing instance string.Equals(...) overload usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add note about why. Co-authored-by: Piotr Kiełkowicz <pkielkow@cisco.com>
95cfbee
#7196 (comment)
Changes
Equals()methods and require the static versions be used instead.Merge requirement checklist
Unit tests added/updatedAppropriateCHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)