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
[AOT] Annotate APIs which call IServiceCollection.TryAddSingleton
for trim compatibility
#4688
[AOT] Annotate APIs which call IServiceCollection.TryAddSingleton
for trim compatibility
#4688
Conversation
…r trim compatibility `IServiceCollection.TryAddSingleton<T>` has trim annotation on `T`, this needs to be propagated to the caller to make it trim compatible. This change just propagates the annotation to the signature of the method calling the `TryAddSingleton`. The trim tooling will make sure that the annotation is fulfilled by the caller of the OTel public methods with this change.
b7130e7
to
948bb66
Compare
...derBuilderExtensions/Logs/OpenTelemetryDependencyInjectionLoggerProviderBuilderExtensions.cs
Show resolved
Hide resolved
+1 |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4688 +/- ##
==========================================
+ Coverage 85.11% 85.18% +0.07%
==========================================
Files 314 314
Lines 12735 12735
==========================================
+ Hits 10839 10848 +9
+ Misses 1896 1887 -9
|
I created #4690 to track the work make a new CI leg for AOT/trim compatibility tests. |
@vitek-karas Could you explain a bit more as to what this means for the users of our APIs? |
For users which don't trim/AOT their app there's no effect at all (the attribute is completely ignored by compiler and runtime). void RegisterInstrumentation<TInstrumentation>(LoggerProviderBuilder builder)
{
builder.AddInstrumentation<TInstrumentation>(); // IL#### - the annotation on TInstrumentation doesn't match those required by AddInstrumentation
} Fixed: void RegisterInstrumentation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructor)] TInstrumentation>(LoggerProviderBuilder builder)
{
builder.AddInstrumentation<TInstrumentation>(); // no warning
} This is a standard behavior of many other APIs which are annotated with the |
The test failure is a timed out AOT publish test. I ran it locally multiple times and it passes just fine. It also passed on Linux (in 1.5 minutes, on Windows it timed out after 4 minutes). |
Towards #3429
IServiceCollection.TryAddSingleton<T>
has trim annotation onT
, this needs to be propagated to the caller to make it trim compatible.This change just propagates the annotation to the signature of the method calling the
TryAddSingleton
. The trim tooling will make sure that the annotation is fulfilled by the caller of the OTel public methods with this change.Note that these changes don't affect the outcome of the
EnsureAotCompatibility
test. This is because that test uses .NET 7 AOT compiler which has a bug and it doesn't report the warning it should have in these cases. Running the same test as a Trim compatibility test instead (/p:PublishAot=false /p:PublishTrimmed=true
) will show warnings for each of the change in this PR. The .NET 8 version of the AOT compiler is fixed and will also report these warnings, so we need to fix these for both trimming and AOT compatibility.I'd be open to adding a
EnsureTrimCompatibility
test, but it will make CI slower as it takes similar amount of time to the AOT compatibility test which is already causing CI slowdowns. @Yun-Ting has been discussing possibility of moving the AOT test into its own CI leg, adding the trim test there would be much less disruptive.Merge requirement checklist
CHANGELOG.md
files updated for non-trivial changes@Yun-Ting @eerhardt