[SqlClient] Support native AoT#4062
[SqlClient] Support native AoT#4062martincostello wants to merge 4 commits intoopen-telemetry:mainfrom
Conversation
Add support for native AoT when targeting .NET 8+.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4062 +/- ##
==========================================
+ Coverage 72.75% 72.89% +0.13%
==========================================
Files 458 448 -10
Lines 17876 17820 -56
==========================================
- Hits 13006 12989 -17
+ Misses 4870 4831 -39
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Remove hallucinated justifications and comments from Copilot.
Fix PR number.
There was a problem hiding this comment.
Pull request overview
This PR aims to make OpenTelemetry.Instrumentation.SqlClient usable in native AOT scenarios on .NET 8+ by removing trimming/AOT blockers and adjusting SqlClient DiagnosticSource payload handling.
Changes:
- Marks the SqlClient instrumentation package as AOT compatible for
.NETCoreAppTFMs. - Removes
RequiresUnreferencedCodeannotations from SqlClient public extension methods and internal types. - Refactors
SqlClientDiagnosticListenerto rely more onIDbCommand/DbConnectionAPIs and adds trim-warning suppressions aroundPropertyFetcherusage.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/OpenTelemetry.Instrumentation.SqlClient/TracerProviderBuilderExtensions.cs | Removes trimming warning annotations from tracing registration APIs. |
| src/OpenTelemetry.Instrumentation.SqlClient/SqlClientMeterProviderBuilderExtensions.cs | Removes trimming warning annotations from metrics registration API. |
| src/OpenTelemetry.Instrumentation.SqlClient/SqlClientInstrumentation.cs | Removes trimming warning annotation and trimming message constant. |
| src/OpenTelemetry.Instrumentation.SqlClient/OpenTelemetry.Instrumentation.SqlClient.csproj | Sets <IsAotCompatible>true</IsAotCompatible> for .NETCoreApp TFMs. |
| src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs | Reduces reflection usage for command/connection data; adds trim suppressions for remaining PropertyFetcher calls. |
| src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md | Documents native AOT support addition. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.SqlClient/OpenTelemetry.Instrumentation.SqlClient.csproj
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs
Show resolved
Hide resolved
- Use local variable that's already captured the command's connection. - Dispose of created command.
Changes
Add support for native AoT when targeting .NET 8+.
While an individual application's usage of SqlClient will determine the overall application's native AoT compatibility, this should avoid us being the blocker for an application that is otherwise able to use it.
Manually tested with a native AoT Minimal APIs application with SQL Server. Queries worked as expected, and metrics and traces are observed in the console.
Test Application and Results
WebApplication1.csproj
Program cs
docker-compose.yml
Results
Merge requirement checklist
Unit tests added/updatedCHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)