-
Notifications
You must be signed in to change notification settings - Fork 9
Add native AoT annotations #358
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
Conversation
Bubble-up `[RequiresUnreferencedCode]` to the public API surface to enable the AoT analyzer, but not actually support native AoT.
0061e45 to
cf643c4
Compare
|
@matt-hensley Thoughts on this approach? The most relevant changes are the annotations added to the |
Add entries for native AoT.
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 adds native AoT (Ahead-of-Time compilation) annotations to the Grafana OpenTelemetry distribution for .NET by adding [RequiresUnreferencedCode] attributes to public APIs and internal implementations. The purpose is to enable the AoT analyzer to warn developers when using features incompatible with native AoT, while explicitly acknowledging that full native AoT support is not yet implemented.
Key changes:
- Added
[RequiresUnreferencedCode]annotations to public API methods (UseGrafanaextension methods) - Added annotations to internal resource detector and instrumentation initializer classes
- Changed
IsAotCompatibleproperty fromfalsetotruein the project file to enable AoT analysis - Updated CHANGELOG.md with relevant entries
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 28 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Grafana.OpenTelemetry/OpenTelemetryBuilderExtension.cs | Added AoT annotation to public UseGrafana extension method with clear user-facing message |
| src/Grafana.OpenTelemetry.Base/TracerProviderBuilderExtensions.cs | Added AoT annotations to public UseGrafana method and internal AddResourceDetectors method |
| src/Grafana.OpenTelemetry.Base/MeterProviderBuilderExtensions.cs | Added AoT annotations to public UseGrafana method and internal AddResourceDetectors method |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/ResourceDetectorInitializer.cs | Added AoT annotation to base initializer class |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/ProcessRuntimeResource.cs | Added AoT annotation to process runtime resource detector |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/ProcessResourceInitializer.cs | Added AoT annotation to process resource detector |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/OperatingSystemResourceInitializer.cs | Added AoT annotation to OS resource detector |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/HostDetectorInitializer.cs | Added AoT annotation to host resource detector |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/ContainerResource.cs | Added AoT annotation to container resource detector |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/AzureVMDetectorInitializer.cs | Added AoT annotation to Azure VM resource detector |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/AzureContainerAppsDetectorInitializer.cs | Added AoT annotation to Azure Container Apps resource detector |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/AzureAppServiceDetectorInitializer.cs | Added AoT annotation to Azure App Service resource detector |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/AWSEKSDetectorInitializer.cs | Added AoT annotation to AWS EKS resource detector |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/AWSECSDetectorInitializer.cs | Added AoT annotation to AWS ECS resource detector |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/AWSEC2DetectorInitializer.cs | Added AoT annotation to AWS EC2 resource detector |
| src/Grafana.OpenTelemetry.Base/ResourceDetectors/AWSEBSDetectorInitializer.cs | Added AoT annotation to AWS EBS resource detector |
| src/Grafana.OpenTelemetry.Base/Instrumentations/WcfInitializer.cs | Added AoT annotation to WCF instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Instrumentations/StackExchangeRedisInitializer.cs | Added AoT annotation to Redis instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Instrumentations/QuartzInitializer.cs | Added AoT annotation to Quartz instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Instrumentations/OwinInitializer.cs | Added AoT annotation to OWIN instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Instrumentations/MySqlDataInitializer.cs | Added AoT annotation to MySQL instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Instrumentations/HangfireInitializer.cs | Added AoT annotation to Hangfire instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Instrumentations/EntityFrameworkCoreInitializer.cs | Added AoT annotation to Entity Framework Core instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Instrumentations/ElasticsearchClientInitializer.cs | Added AoT annotation to Elasticsearch instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Instrumentations/CassandraInitializer.cs | Added AoT annotation to Cassandra instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Instrumentations/AspNetInitializer.cs | Added AoT annotation to ASP.NET instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Instrumentations/AspNetCoreInitializer.cs | Added AoT annotation to ASP.NET Core instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Instrumentations/AWSLambdaInitializer.cs | Added AoT annotation to AWS Lambda instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Instrumentations/AWSInitializer.cs | Added AoT annotation to AWS instrumentation initializer |
| src/Grafana.OpenTelemetry.Base/Grafana.OpenTelemetry.Base.csproj | Changed IsAotCompatible from false to true to enable AoT analyzer warnings |
| CHANGELOG.md | Added entries documenting the addition of native AoT annotations |
| namespace Grafana.OpenTelemetry | ||
| { | ||
| #if NET8_0_OR_GREATER | ||
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")] |
Copilot
AI
Nov 25, 2025
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.
The error message "Types might be removed" is vague and doesn't provide actionable information to developers. Consider using a more descriptive message that explains why this code is incompatible with native AoT.
For example: "This resource detector uses reflection for type discovery, which is not compatible with native AoT compilation."
This would provide clearer context about the limitation.
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")] | |
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("This resource detector uses reflection for type discovery, which is not compatible with native AoT compilation.")] |
| namespace Grafana.OpenTelemetry | ||
| { | ||
| #if NET8_0_OR_GREATER | ||
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")] |
Copilot
AI
Nov 25, 2025
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.
The error message "Types might be removed" is vague and doesn't provide actionable information to developers. Consider using a more descriptive message that explains why this code is incompatible with native AoT.
For example: "This instrumentation uses reflection for type discovery, which is not compatible with native AoT compilation."
This would provide clearer context about the limitation.
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")] | |
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("This instrumentation uses reflection for type discovery, which is not compatible with native AoT compilation.")] |
| namespace Grafana.OpenTelemetry | ||
| { | ||
| #if NET8_0_OR_GREATER | ||
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")] |
Copilot
AI
Nov 25, 2025
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.
The error message "Types might be removed" is vague and doesn't provide actionable information to developers. Consider using a more descriptive message that explains why this code is incompatible with native AoT.
For example: "This instrumentation uses reflection for type discovery, which is not compatible with native AoT compilation."
This would provide clearer context about the limitation.
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")] | |
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("This instrumentation uses reflection for type discovery, which is not compatible with native AoT compilation.")] |
| namespace Grafana.OpenTelemetry | ||
| { | ||
| #if NET8_0_OR_GREATER | ||
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")] |
Copilot
AI
Nov 25, 2025
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.
The error message "Types might be removed" is vague and doesn't provide actionable information to developers. Consider using a more descriptive message that explains why this code is incompatible with native AoT.
For example: "This instrumentation uses reflection for type discovery, which is not compatible with native AoT compilation."
This would provide clearer context about the limitation.
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")] | |
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("This instrumentation uses reflection for type discovery, which is not compatible with native AoT compilation.")] |
| } | ||
|
|
||
| #if NET8_0_OR_GREATER | ||
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")] |
Copilot
AI
Nov 25, 2025
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.
The error message "Types might be removed" is vague and doesn't provide actionable information to developers. Consider using a more descriptive message that explains why this code is incompatible with native AoT.
For example: "This functionality uses reflection to discover and instantiate resource detectors, which is not compatible with native AoT compilation."
This would match the pattern used in the public API methods and provide clearer context.
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")] | |
| [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("This functionality uses reflection to discover and instantiate resource detectors, which is not compatible with native AoT compilation.")] |
Changes
Bubble-up
[RequiresUnreferencedCode]to the public API surface to enable the AoT analyzer, but not actually support native AoT.See #357 (comment).
Resolves #97.
Merge requirement checklist
Unit tests added/updatedCHANGELOG.mdupdatedChanges in public API reviewed (if applicable)