-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
Address Trim warnings and prevent future regressions #3841
Conversation
Sentry.ProfilingThere are a few trim warnings for
The warning on line 1995 of type = Type.GetType(fullName); and the related error on line 2017 relates to this code: return (IFastSerializable)Activator.CreateInstance(type); The code essentially seems to be trying to construct arbitrary types... which will definitely mess with trimming. The conventional solution to this would be to use @vaind I think you're the resident expert on all things profiling. Do you have any context for why the profiling module uses |
Sentry.AspNetCore.Blazor.WebAssemblyTrying to include
|
These all belong to |
Not code no. The only other code that we've used that had these trim warnings was our own code, which we updated for the 4.0.0 release to use the |
|
||
trim-analysis: | ||
name: Trim analysis | ||
runs-on: macos-15 |
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.
can this be latest
or we need to pin?
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.
We pin to get the correct version of Xcode. As of about a month ago, the GitHub macos runners are associated with specific major versions of Xcode.
- macos-14 has Xcode 15.x installed
- macos-15 has Xcode 16.x installed
I've basically started trying to pin everything (specific runner version, .NET workload versions via the ios18.0 or android35.0 monkiers etc.) since it gets us closer to deterministic builds. If we don't do this, too much changes arbitrarily between different runs against the same commit and CI fails arbitrarily.
- name: Install Android SDKs | ||
if: runner.os == 'macOS' | ||
run: | | ||
dotnet build src/Sentry/Sentry.csproj -t:InstallAndroidDependencies -f:net8.0-android34.0 -p:AcceptAndroidSDKLicenses=True -p:AndroidSdkPath="/usr/local/lib/android/sdk/" |
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.
do we need to set the specific android version here? I imagine it might go out of sync when we bump .NET for example
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.
What we're passing here is the target framework net8.0-android34.0
. That has to match one of the target frameworks in the csproj file and we pin android34.0 as the oldest possible set of APIs that can be used with net8.0 (for net9.0 it's net9.0-android35.0).
The main reason we're doing this is to ensure the android34.0 SDK gets installed as this is missing from the new GitHub runners. If we remove this, the build fails later on in the workflow.
run: dotnet publish test/Sentry.TrimTest/Sentry.TrimTest.csproj -c Release -r osx-arm64 | ||
|
||
- name: Publish Test app (Android) | ||
run: dotnet publish test/Sentry.MauiTrimTest/Sentry.MauiTrimTest.csproj -c Release -f net9.0-android35.0 -r android-arm64 |
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.
we use Android 35 here and 34 above. Is that by default? We could set this as vars at the top of the workflow at least?
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.
34.0 is used abote with the t:InstallAndroidDependencies
parameter to install some missing dependencies. For the trim tests, I've used net9.0 as there are some new analysers in net9.0 (i.e. it picks up more issues).
So yeah, unfortunately we want to use two separate target frameworks for the two different build steps.
Resolves #3808:
Summary
To get useful trim analysis when building libraries we need a test app that shows all warnings.
In this PR we've added
test/Sentry.TrimTest/Sentry.TrimTest.csproj
to serve as the test app that will produce said warnings for most of the sentry packages. We've also addedtest/Sentry.MauiTrimTest/Sentry.MauiTrimTest.csproj
to detect trim warnings for code targeting android and iOS (in theSentry.Maui
andSentry.Bindings.*
packages).Additionally, a new job has been added to CI to publish those two test apps. If the publish attempts succeed without error, we should be trim compatible.
Note to Reviewers
This looks like a 9k line PR. However, most of the "additions" are in
test/Sentry.MauiTrimTest/Resources/Fonts/FluentUI.cs
which is just part of the MAUI template (and can be ignored).Merge Note
This PR should also be merged in the Ben.Demystifier submodule when this PR is accepted/merged:
Sentry.Maui trimming limitations
We're using reflection to read the values of some internal properties on event args (so we can drop breadcrumbs). When apps are trimmed, we're not able to generate these breadcrumbs... so we don't have 100% functional equivalence for the SDK when MAUI apps are trimmed.
See:
Sentry.Maui trim analyser issues
There is currently a bug in System.Text.Json that prevents us from publishing AOT applications to iOS:
So we can't check for AOT warnings on iOS (only trim analyser warnings for the time being).
Packages incompatible with trimming
At this time, the following packages are not compatible with trimming:
sentry-dotnet/test/Sentry.TrimTest/Sentry.TrimTest.csproj
Lines 41 to 46 in fce29a9
Of those,
Sentry.Profiling
andSentry.AspNetCore.Blazor.WebAssembly
are currently the only two that we might be able to address... We should create separate issues for these if we want to trimming compatibility for them.