From f0c22332f62697afd90af92851c56f6fc26d950e Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 11:03:09 +1300 Subject: [PATCH 01/36] Add Trim test app --- .github/workflows/build.yml | 38 ++++++++++++++++++++ Sentry-CI-Build-Linux.slnf | 1 + Sentry-CI-Build-Windows.slnf | 1 + Sentry-CI-Build-macOS.slnf | 5 +-- Sentry.sln | 7 ++++ SentryNoMobile.slnf | 1 + SentryNoSamples.slnf | 3 +- test/Sentry.TrimTest/Directory.Build.props | 2 ++ test/Sentry.TrimTest/Directory.Build.targets | 2 ++ test/Sentry.TrimTest/Program.cs | 2 ++ test/Sentry.TrimTest/README.md | 14 ++++++++ test/Sentry.TrimTest/Sentry.TrimTest.csproj | 18 ++++++++++ 12 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 test/Sentry.TrimTest/Directory.Build.props create mode 100644 test/Sentry.TrimTest/Directory.Build.targets create mode 100644 test/Sentry.TrimTest/Program.cs create mode 100644 test/Sentry.TrimTest/README.md create mode 100644 test/Sentry.TrimTest/Sentry.TrimTest.csproj diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 51b7fa118c..86596e800a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -187,6 +187,44 @@ jobs: with: path: integration-test + + trim-analysis: + needs: build + name: Trim analysis + runs-on: macos-15 + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 2 # default is 1 and codecov needs > 1 + + # We use macOS for the final publishing build so we get all the iOS/macCatalyst targets in the packages + - name: Set Environment Variables + run: echo "CI_PUBLISHING_BUILD=true" >> $GITHUB_ENV + + - name: Download sentry-native (macOS) + uses: actions/cache/restore@v4 + with: + path: src/Sentry/Platforms/Native/sentry-native + key: sentry-native-macOS-${{ hashFiles('scripts/build-sentry-native.ps1') }}-${{ hashFiles('.git/modules/modules/sentry-native/HEAD') }} + fail-on-cache-miss: true + + - name: Setup Environment + uses: ./.github/actions/environment + + - name: Build Native Dependencies + uses: ./.github/actions/buildnative + + - 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/" + + - name: Publish Test app + run: dotnet publish test/Sentry.TrimTest/Sentry.TrimTest.csproj -c Release -r osx-arm64 + test-solution-filters: runs-on: ubuntu-latest if: ${{ !startsWith(github.ref_name, 'release/') }} diff --git a/Sentry-CI-Build-Linux.slnf b/Sentry-CI-Build-Linux.slnf index bc53783e35..ac013aba4e 100644 --- a/Sentry-CI-Build-Linux.slnf +++ b/Sentry-CI-Build-Linux.slnf @@ -71,6 +71,7 @@ "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj", + "test\\Sentry.TrimTest\\Sentry.TrimTest.csproj", "test\\SingleFileTestApp\\SingleFileTestApp.csproj" ] } diff --git a/Sentry-CI-Build-Windows.slnf b/Sentry-CI-Build-Windows.slnf index 1ad751775d..c9d4cd2189 100644 --- a/Sentry-CI-Build-Windows.slnf +++ b/Sentry-CI-Build-Windows.slnf @@ -74,6 +74,7 @@ "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj", + "test\\Sentry.TrimTest\\Sentry.TrimTest.csproj", "test\\SingleFileTestApp\\SingleFileTestApp.csproj" ] } diff --git a/Sentry-CI-Build-macOS.slnf b/Sentry-CI-Build-macOS.slnf index 7857558117..dc585e87db 100644 --- a/Sentry-CI-Build-macOS.slnf +++ b/Sentry-CI-Build-macOS.slnf @@ -38,10 +38,10 @@ "samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj", "src\\Sentry.Analyzers\\Sentry.Analyzers.csproj", "src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj", - "src\\Sentry.AspNet\\Sentry.AspNet.csproj", "src\\Sentry.AspNetCore.Blazor.WebAssembly\\Sentry.AspNetCore.Blazor.WebAssembly.csproj", "src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj", "src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj", + "src\\Sentry.AspNet\\Sentry.AspNet.csproj", "src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj", "src\\Sentry.Bindings.Android\\Sentry.Bindings.Android.csproj", "src\\Sentry.Bindings.Cocoa\\Sentry.Bindings.Cocoa.csproj", @@ -80,7 +80,8 @@ "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj", + "test\\Sentry.TrimTest\\Sentry.TrimTest.csproj", "test\\SingleFileTestApp\\SingleFileTestApp.csproj" ] } -} +} \ No newline at end of file diff --git a/Sentry.sln b/Sentry.sln index d6474cf575..cf45937a18 100644 --- a/Sentry.sln +++ b/Sentry.sln @@ -193,6 +193,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Analyzers.Tests", "t EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.Console.HeapDump", "samples\Sentry.Samples.Console.HeapDump\Sentry.Samples.Console.HeapDump.csproj", "{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.TrimTest", "test\Sentry.TrimTest\Sentry.TrimTest.csproj", "{6030B748-0000-43B5-B8A8-399AA42F5229}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -520,6 +522,10 @@ Global {D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Release|Any CPU.ActiveCfg = Release|Any CPU {D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Release|Any CPU.Build.0 = Release|Any CPU + {6030B748-0000-43B5-B8A8-399AA42F5229}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6030B748-0000-43B5-B8A8-399AA42F5229}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6030B748-0000-43B5-B8A8-399AA42F5229}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6030B748-0000-43B5-B8A8-399AA42F5229}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -605,5 +611,6 @@ Global {E36C8DCA-464E-41CB-B189-F58553AAA8D4} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} {5A17FEF9-07BB-47B8-9883-9C2CC93F09E8} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821} = {21B42F60-5802-404E-90F0-AEBCC56760C0} + {6030B748-0000-43B5-B8A8-399AA42F5229} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} EndGlobalSection EndGlobal diff --git a/SentryNoMobile.slnf b/SentryNoMobile.slnf index e6e27c6ee7..27baabfc5d 100644 --- a/SentryNoMobile.slnf +++ b/SentryNoMobile.slnf @@ -68,6 +68,7 @@ "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj", + "test\\Sentry.TrimTest\\Sentry.TrimTest.csproj", "test\\SingleFileTestApp\\SingleFileTestApp.csproj" ] } diff --git a/SentryNoSamples.slnf b/SentryNoSamples.slnf index 66ce4d76a5..b20803c72b 100644 --- a/SentryNoSamples.slnf +++ b/SentryNoSamples.slnf @@ -43,7 +43,8 @@ "test\\Sentry.Serilog.Tests\\Sentry.Serilog.Tests.csproj", "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", - "test\\Sentry.Tests\\Sentry.Tests.csproj" + "test\\Sentry.Tests\\Sentry.Tests.csproj", + "test\\Sentry.TrimTest\\Sentry.TrimTest.csproj" ] } } diff --git a/test/Sentry.TrimTest/Directory.Build.props b/test/Sentry.TrimTest/Directory.Build.props new file mode 100644 index 0000000000..bbb7413d29 --- /dev/null +++ b/test/Sentry.TrimTest/Directory.Build.props @@ -0,0 +1,2 @@ + + diff --git a/test/Sentry.TrimTest/Directory.Build.targets b/test/Sentry.TrimTest/Directory.Build.targets new file mode 100644 index 0000000000..bbb7413d29 --- /dev/null +++ b/test/Sentry.TrimTest/Directory.Build.targets @@ -0,0 +1,2 @@ + + diff --git a/test/Sentry.TrimTest/Program.cs b/test/Sentry.TrimTest/Program.cs new file mode 100644 index 0000000000..3751555cbd --- /dev/null +++ b/test/Sentry.TrimTest/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/test/Sentry.TrimTest/README.md b/test/Sentry.TrimTest/README.md new file mode 100644 index 0000000000..4b0bbce080 --- /dev/null +++ b/test/Sentry.TrimTest/README.md @@ -0,0 +1,14 @@ +# Sentry Trimming Test App + +This project does not contain any unit or integration tests. However, if we are able to successfully publish it without +warning/error then Sentry should be trim compatible. + +To test this we need to publish the app with the following command: + +```bash +dotnet publish -c Release -r +``` + +See: +- [Show all warnings with test app](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming#show-all-warnings-with-test-app) +- [.NET RID Catalog](https://learn.microsoft.com/en-us/dotnet/core/rid-catalog) diff --git a/test/Sentry.TrimTest/Sentry.TrimTest.csproj b/test/Sentry.TrimTest/Sentry.TrimTest.csproj new file mode 100644 index 0000000000..87458f8b34 --- /dev/null +++ b/test/Sentry.TrimTest/Sentry.TrimTest.csproj @@ -0,0 +1,18 @@ + + + + Exe + net9.0 + enable + enable + + + true + + + + + + + + From 1fcfee5716586bfc67c0b9b2ad20871cb35e8494 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 11:13:21 +1300 Subject: [PATCH 02/36] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f810839299..eb07fad88a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixes - Fixed JNI Error when accessing Android device data from multiple threads ([#3802](https://github.com/getsentry/sentry-dotnet/pull/3802)) +- Address Trim warnings so that MAUI applications can be compiled AOT ([#3841](https://github.com/getsentry/sentry-dotnet/pull/3841)) ### Dependencies From 4e8c7d0687237da0e90cfd93bd21ed2b0fe21b9e Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 11:14:38 +1300 Subject: [PATCH 03/36] Update build.yml --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 86596e800a..4a0f15fa51 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -189,7 +189,6 @@ jobs: trim-analysis: - needs: build name: Trim analysis runs-on: macos-15 From 88d70bc5f233a9c5eb292471819e227813d1c393 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 11 Dec 2024 22:25:22 +0000 Subject: [PATCH 04/36] Format code --- test/Sentry.TrimTest/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Sentry.TrimTest/Program.cs b/test/Sentry.TrimTest/Program.cs index 3751555cbd..39946ea18e 100644 --- a/test/Sentry.TrimTest/Program.cs +++ b/test/Sentry.TrimTest/Program.cs @@ -1,2 +1,2 @@ -// See https://aka.ms/new-console-template for more information +// See https://aka.ms/new-console-template for more information Console.WriteLine("Hello, World!"); From 04bc9ec4b5676c5af73a8fb74e07883d8537e1a5 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 14:09:39 +1300 Subject: [PATCH 05/36] Update Sentry.TrimTest.csproj --- test/Sentry.TrimTest/Sentry.TrimTest.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Sentry.TrimTest/Sentry.TrimTest.csproj b/test/Sentry.TrimTest/Sentry.TrimTest.csproj index 87458f8b34..6c84ed27cb 100644 --- a/test/Sentry.TrimTest/Sentry.TrimTest.csproj +++ b/test/Sentry.TrimTest/Sentry.TrimTest.csproj @@ -8,6 +8,7 @@ true + true From b3f71a5a2a6eb64ea7561c1dc196b3bc41f94a87 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 14:23:24 +1300 Subject: [PATCH 06/36] Update solution filters --- .generated.NoMobile.sln | 7 +++++++ Sentry-CI-Build-Linux.slnf | 2 +- Sentry-CI-Build-Windows.slnf | 2 +- Sentry-CI-Build-macOS.slnf | 6 +++--- Sentry.Azure.Functions.slnf | 1 + SentryNoMobile.slnf | 2 +- SentryNoSamples.slnf | 3 +-- scripts/generate-solution-filters-config.yaml | 5 +++++ 8 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.generated.NoMobile.sln b/.generated.NoMobile.sln index d6474cf575..cf45937a18 100644 --- a/.generated.NoMobile.sln +++ b/.generated.NoMobile.sln @@ -193,6 +193,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Analyzers.Tests", "t EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.Console.HeapDump", "samples\Sentry.Samples.Console.HeapDump\Sentry.Samples.Console.HeapDump.csproj", "{D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.TrimTest", "test\Sentry.TrimTest\Sentry.TrimTest.csproj", "{6030B748-0000-43B5-B8A8-399AA42F5229}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -520,6 +522,10 @@ Global {D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Release|Any CPU.ActiveCfg = Release|Any CPU {D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821}.Release|Any CPU.Build.0 = Release|Any CPU + {6030B748-0000-43B5-B8A8-399AA42F5229}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6030B748-0000-43B5-B8A8-399AA42F5229}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6030B748-0000-43B5-B8A8-399AA42F5229}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6030B748-0000-43B5-B8A8-399AA42F5229}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -605,5 +611,6 @@ Global {E36C8DCA-464E-41CB-B189-F58553AAA8D4} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} {5A17FEF9-07BB-47B8-9883-9C2CC93F09E8} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821} = {21B42F60-5802-404E-90F0-AEBCC56760C0} + {6030B748-0000-43B5-B8A8-399AA42F5229} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} EndGlobalSection EndGlobal diff --git a/Sentry-CI-Build-Linux.slnf b/Sentry-CI-Build-Linux.slnf index ac013aba4e..eb63166b4b 100644 --- a/Sentry-CI-Build-Linux.slnf +++ b/Sentry-CI-Build-Linux.slnf @@ -12,6 +12,7 @@ "samples\\Sentry.Samples.AspNetCore.Serilog\\Sentry.Samples.AspNetCore.Serilog.csproj", "samples\\Sentry.Samples.AspNetCore.WebAPI.Profiling\\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "samples\\Sentry.Samples.Aws.Lambda.AspNetCoreServer\\Sentry.Samples.Aws.Lambda.AspNetCoreServer.csproj", + "samples\\Sentry.Samples.Azure.Functions.Worker\\obj\\Release\\net8.0\\WorkerExtensions\\WorkerExtensions.csproj", "samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj", "samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj", "samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj", @@ -71,7 +72,6 @@ "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj", - "test\\Sentry.TrimTest\\Sentry.TrimTest.csproj", "test\\SingleFileTestApp\\SingleFileTestApp.csproj" ] } diff --git a/Sentry-CI-Build-Windows.slnf b/Sentry-CI-Build-Windows.slnf index c9d4cd2189..9e2f3f1951 100644 --- a/Sentry-CI-Build-Windows.slnf +++ b/Sentry-CI-Build-Windows.slnf @@ -13,6 +13,7 @@ "samples\\Sentry.Samples.AspNetCore.Serilog\\Sentry.Samples.AspNetCore.Serilog.csproj", "samples\\Sentry.Samples.AspNetCore.WebAPI.Profiling\\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "samples\\Sentry.Samples.Aws.Lambda.AspNetCoreServer\\Sentry.Samples.Aws.Lambda.AspNetCoreServer.csproj", + "samples\\Sentry.Samples.Azure.Functions.Worker\\obj\\Release\\net8.0\\WorkerExtensions\\WorkerExtensions.csproj", "samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj", "samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj", "samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj", @@ -74,7 +75,6 @@ "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj", - "test\\Sentry.TrimTest\\Sentry.TrimTest.csproj", "test\\SingleFileTestApp\\SingleFileTestApp.csproj" ] } diff --git a/Sentry-CI-Build-macOS.slnf b/Sentry-CI-Build-macOS.slnf index dc585e87db..836e438ac8 100644 --- a/Sentry-CI-Build-macOS.slnf +++ b/Sentry-CI-Build-macOS.slnf @@ -14,6 +14,7 @@ "samples\\Sentry.Samples.AspNetCore.Serilog\\Sentry.Samples.AspNetCore.Serilog.csproj", "samples\\Sentry.Samples.AspNetCore.WebAPI.Profiling\\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "samples\\Sentry.Samples.Aws.Lambda.AspNetCoreServer\\Sentry.Samples.Aws.Lambda.AspNetCoreServer.csproj", + "samples\\Sentry.Samples.Azure.Functions.Worker\\obj\\Release\\net8.0\\WorkerExtensions\\WorkerExtensions.csproj", "samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj", "samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj", "samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj", @@ -38,10 +39,10 @@ "samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj", "src\\Sentry.Analyzers\\Sentry.Analyzers.csproj", "src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj", + "src\\Sentry.AspNet\\Sentry.AspNet.csproj", "src\\Sentry.AspNetCore.Blazor.WebAssembly\\Sentry.AspNetCore.Blazor.WebAssembly.csproj", "src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj", "src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj", - "src\\Sentry.AspNet\\Sentry.AspNet.csproj", "src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj", "src\\Sentry.Bindings.Android\\Sentry.Bindings.Android.csproj", "src\\Sentry.Bindings.Cocoa\\Sentry.Bindings.Cocoa.csproj", @@ -80,8 +81,7 @@ "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj", - "test\\Sentry.TrimTest\\Sentry.TrimTest.csproj", "test\\SingleFileTestApp\\SingleFileTestApp.csproj" ] } -} \ No newline at end of file +} diff --git a/Sentry.Azure.Functions.slnf b/Sentry.Azure.Functions.slnf index 54c80b23c9..d41b7aa4ee 100644 --- a/Sentry.Azure.Functions.slnf +++ b/Sentry.Azure.Functions.slnf @@ -2,6 +2,7 @@ "solution": { "path": "Sentry.sln", "projects": [ + "samples\\Sentry.Samples.Azure.Functions.Worker\\obj\\Release\\net8.0\\WorkerExtensions\\WorkerExtensions.csproj", "samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj", "samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj", "src\\Sentry.Analyzers\\Sentry.Analyzers.csproj", diff --git a/SentryNoMobile.slnf b/SentryNoMobile.slnf index 27baabfc5d..3df3f5ce93 100644 --- a/SentryNoMobile.slnf +++ b/SentryNoMobile.slnf @@ -11,6 +11,7 @@ "samples\\Sentry.Samples.AspNetCore.Serilog\\Sentry.Samples.AspNetCore.Serilog.csproj", "samples\\Sentry.Samples.AspNetCore.WebAPI.Profiling\\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "samples\\Sentry.Samples.Aws.Lambda.AspNetCoreServer\\Sentry.Samples.Aws.Lambda.AspNetCoreServer.csproj", + "samples\\Sentry.Samples.Azure.Functions.Worker\\obj\\Release\\net8.0\\WorkerExtensions\\WorkerExtensions.csproj", "samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj", "samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj", "samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj", @@ -68,7 +69,6 @@ "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj", - "test\\Sentry.TrimTest\\Sentry.TrimTest.csproj", "test\\SingleFileTestApp\\SingleFileTestApp.csproj" ] } diff --git a/SentryNoSamples.slnf b/SentryNoSamples.slnf index b20803c72b..66ce4d76a5 100644 --- a/SentryNoSamples.slnf +++ b/SentryNoSamples.slnf @@ -43,8 +43,7 @@ "test\\Sentry.Serilog.Tests\\Sentry.Serilog.Tests.csproj", "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", - "test\\Sentry.Tests\\Sentry.Tests.csproj", - "test\\Sentry.TrimTest\\Sentry.TrimTest.csproj" + "test\\Sentry.Tests\\Sentry.Tests.csproj" ] } } diff --git a/scripts/generate-solution-filters-config.yaml b/scripts/generate-solution-filters-config.yaml index daad716898..e0cd3cd6af 100644 --- a/scripts/generate-solution-filters-config.yaml +++ b/scripts/generate-solution-filters-config.yaml @@ -41,6 +41,7 @@ filterConfigs: - "**/*Maui.Device.TestApp.csproj" - "**/*SourceGen.csproj" - "**/*TestUtils*.csproj" + - "**/*Sentry.TrimTest.csproj" - outputPath: Sentry-CI-Build-macOS.slnf include: @@ -54,6 +55,7 @@ filterConfigs: - "**/*AndroidTestApp.csproj" - "**/*DeviceTests*.csproj" - "**/*SourceGen.csproj" + - "**/*Sentry.TrimTest.csproj" - outputPath: Sentry-CI-Build-Windows.slnf include: @@ -72,6 +74,7 @@ filterConfigs: - "**/*Sentry.Samples.Android.csproj" - "**/*OpenTelemetry.AspNet.csproj" - "**/*SourceGen.csproj" + - "**/*Sentry.TrimTest.csproj" - outputPath: Sentry-CI-CodeQL.slnf include: @@ -178,6 +181,7 @@ filterConfigs: - "**/*Android*.csproj" - "**/*Ios*.csproj" - "**/*Maui*.csproj" + - "**/*Sentry.TrimTest.csproj" - outputPath: SentryNoSamples.slnf include: @@ -189,3 +193,4 @@ filterConfigs: - "**/*Bindings*" - "**/*DeviceTests*" - "**/*TestApp*" + - "**/*Sentry.TrimTest.csproj" From 55ea8c0e9258f8e239f5ed4da836ee7f40d23496 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 14:33:26 +1300 Subject: [PATCH 07/36] Address trim warnings in Sentry core package --- modules/Ben.Demystifier | 2 +- .../SentryFunctionsWorkerMiddleware.cs | 2 +- .../DiagnosticSource/ReflectionHelper.cs | 2 +- .../WinUIUnhandledExceptionIntegration.cs | 6 ++-- src/Sentry/Internal/AotHelper.cs | 36 +++++++++---------- src/Sentry/Internal/DebugStackTrace.cs | 6 ++-- .../Internal/Extensions/JsonExtensions.cs | 8 ++--- src/Sentry/Internal/ModuleExtensions.cs | 2 +- src/Sentry/Internal/StackFrame.cs | 4 +-- src/Sentry/SentryClient.cs | 6 ++++ src/Sentry/SentrySdk.cs | 12 +++---- 11 files changed, 41 insertions(+), 45 deletions(-) diff --git a/modules/Ben.Demystifier b/modules/Ben.Demystifier index b1dd53b9b1..fe04751006 160000 --- a/modules/Ben.Demystifier +++ b/modules/Ben.Demystifier @@ -1 +1 @@ -Subproject commit b1dd53b9b194de9430dc31df27184966ee28e7d0 +Subproject commit fe0475100614508fff1c76aa896e17807adde83f diff --git a/src/Sentry.Azure.Functions.Worker/SentryFunctionsWorkerMiddleware.cs b/src/Sentry.Azure.Functions.Worker/SentryFunctionsWorkerMiddleware.cs index 889153bcd6..ce521805f6 100644 --- a/src/Sentry.Azure.Functions.Worker/SentryFunctionsWorkerMiddleware.cs +++ b/src/Sentry.Azure.Functions.Worker/SentryFunctionsWorkerMiddleware.cs @@ -81,7 +81,7 @@ public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next } } - [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = AotHelper.SuppressionJustification)] + [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AotHelper.AvoidAtRuntime)] private async Task StartOrContinueTraceAsync(FunctionContext context) { var transactionName = context.FunctionDefinition.Name; diff --git a/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/ReflectionHelper.cs b/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/ReflectionHelper.cs index f569c885f3..a7414ef865 100644 --- a/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/ReflectionHelper.cs +++ b/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/ReflectionHelper.cs @@ -12,7 +12,7 @@ namespace Sentry.Internal.DiagnosticSource; /// internal static class ReflectionHelper { - [UnconditionalSuppressMessage("TrimAnalyzer", "IL2075", Justification = AotHelper.SuppressionJustification)] + [UnconditionalSuppressMessage("TrimAnalyzer", "IL2075: DynamicallyAccessedMembers", Justification = AotHelper.AvoidAtRuntime)] public static object? GetProperty(this object obj, string name, IDiagnosticLogger? logger = null) { if (AotHelper.IsTrimmed) diff --git a/src/Sentry/Integrations/WinUIUnhandledExceptionIntegration.cs b/src/Sentry/Integrations/WinUIUnhandledExceptionIntegration.cs index 3ff6e4bcfa..d9b2fc3f9c 100644 --- a/src/Sentry/Integrations/WinUIUnhandledExceptionIntegration.cs +++ b/src/Sentry/Integrations/WinUIUnhandledExceptionIntegration.cs @@ -82,8 +82,8 @@ public void Register(IHub hub, SentryOptions options) /// This method uses reflection to hook up an UnhandledExceptionHandler. When IsTrimmed is true, users will have /// follow our guidance to perform this initialization manually. /// - [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = AotHelper.SuppressionJustification)] - [UnconditionalSuppressMessage("Trimming", "IL2075:\'this\' argument does not satisfy \'DynamicallyAccessedMembersAttribute\' in call to target method. The return value of the source method does not have matching annotations.", Justification = AotHelper.SuppressionJustification)] + [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AotHelper.AvoidAtRuntime)] + [UnconditionalSuppressMessage("TrimAnalyzer", "IL2075: DynamicallyAccessedMembers", Justification = AotHelper.AvoidAtRuntime)] private void AttachEventHandler() { try @@ -105,7 +105,7 @@ private void AttachEventHandler() } } - [UnconditionalSuppressMessage("TrimAnalyzer", "IL2075", Justification = AotHelper.SuppressionJustification)] + [UnconditionalSuppressMessage("TrimAnalyzer", "IL2075: DynamicallyAccessedMembers", Justification = AotHelper.AvoidAtRuntime)] private void WinUIUnhandledExceptionHandler(object sender, object e) { bool handled; diff --git a/src/Sentry/Internal/AotHelper.cs b/src/Sentry/Internal/AotHelper.cs index 5c3387b535..e391699fed 100644 --- a/src/Sentry/Internal/AotHelper.cs +++ b/src/Sentry/Internal/AotHelper.cs @@ -1,35 +1,31 @@ +using Sentry.Protocol; + namespace Sentry.Internal; internal static class AotHelper { - internal const string SuppressionJustification = "Non-trimmable code is avoided at runtime"; - internal static bool IsTrimmed { get; } - - private class AotTester - { - public void Test() { } - } + internal const string AvoidAtRuntime = "Non-trimmable code is avoided at runtime"; -#if NET8_0_OR_GREATER - // TODO this probably more closely represents trimming rather than NativeAOT? + internal static bool IsTrimmed { get; } + internal static bool IsDynamicCodeSupported { get; } internal static bool IsNativeAot { get; } - [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = AotHelper.SuppressionJustification)] static AotHelper() { - var stackTrace = new StackTrace(false); - IsTrimmed = stackTrace.GetFrame(0)?.GetMethod() is null; - IsNativeAot = IsTrimmed; - } + IsTrimmed = SupportsUnreferencedCode(); +#if NETSTANDARD2_0 || NETFRAMEWORK + IsDynamicCodeSupported = true; #else - // This is a compile-time const so that the irrelevant code is removed during compilation. - internal const bool IsNativeAot = false; + IsDynamicCodeSupported = RuntimeFeature.IsDynamicCodeSupported; +#endif + // This is our best guess at determining whether AOT is enabled + IsNativeAot = IsTrimmed && !IsDynamicCodeSupported; + } - [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = AotHelper.SuppressionJustification)] - static AotHelper() + [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AvoidAtRuntime)] + private static bool SupportsUnreferencedCode() { var stackTrace = new StackTrace(false); - IsTrimmed = stackTrace.GetFrame(0)?.GetMethod() is null; + return stackTrace.GetFrame(0)?.GetMethod() is null; } -#endif } diff --git a/src/Sentry/Internal/DebugStackTrace.cs b/src/Sentry/Internal/DebugStackTrace.cs index c048d78b75..a5093c4c01 100644 --- a/src/Sentry/Internal/DebugStackTrace.cs +++ b/src/Sentry/Internal/DebugStackTrace.cs @@ -173,7 +173,7 @@ internal void MergeDebugImagesInto(SentryEvent @event) /// /// Creates an enumerator of from a . /// - [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = AotHelper.SuppressionJustification)] + [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AotHelper.AvoidAtRuntime)] private IEnumerable CreateFrames(StackTrace stackTrace, bool isCurrentStackTrace, Func skipFrame) { var frames = (!AotHelper.IsNativeAot && _options.StackTraceMode == StackTraceMode.Enhanced) @@ -291,7 +291,7 @@ internal static SentryStackFrame ParseNativeAOTToString(string info) /// /// Default the implementation of CreateFrame. /// - [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = AotHelper.SuppressionJustification)] + [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AotHelper.AvoidAtRuntime)] private SentryStackFrame? TryCreateManagedFrame(IStackFrame stackFrame) { if (stackFrame.GetMethod() is not { } method) @@ -508,7 +508,7 @@ private static void DemangleLambdaReturnType(SentryStackFrame frame) } } - [UnconditionalSuppressMessage("SingleFile", "IL3002:Avoid calling members marked with 'RequiresAssemblyFilesAttribute' when publishing as a single-file", Justification = "Code is avoided at runtime.")] + [UnconditionalSuppressMessage("SingleFile", "IL3002: calling members marked with 'RequiresAssemblyFilesAttribute'", Justification = AotHelper.AvoidAtRuntime)] private static PEReader? TryReadAssemblyFromDisk(Module module, SentryOptions options, out string? assemblyName) { try diff --git a/src/Sentry/Internal/Extensions/JsonExtensions.cs b/src/Sentry/Internal/Extensions/JsonExtensions.cs index e8a919d23c..fa29909eac 100644 --- a/src/Sentry/Internal/Extensions/JsonExtensions.cs +++ b/src/Sentry/Internal/Extensions/JsonExtensions.cs @@ -564,8 +564,8 @@ byte[] AotSerializeToUtf8Bytes() return JitSerializeToUtf8Bytes(); #endif - [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = AotHelper.SuppressionJustification)] - [UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.", Justification = AotHelper.SuppressionJustification)] + [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AotHelper.AvoidAtRuntime)] + [UnconditionalSuppressMessage("AOT", "IL3050: RequiresDynamicCode", Justification = AotHelper.AvoidAtRuntime)] byte[] JitSerializeToUtf8Bytes() => JsonSerializer.SerializeToUtf8Bytes(value, SerializerOptions); } @@ -586,8 +586,8 @@ private static void InternalSerialize(Utf8JsonWriter writer, object value, bool #endif return; - [UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.", Justification = AotHelper.SuppressionJustification)] - [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = AotHelper.SuppressionJustification)] + [UnconditionalSuppressMessage("AOT", "IL3050: RequiresDynamicCode", Justification = AotHelper.AvoidAtRuntime)] + [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AotHelper.AvoidAtRuntime)] void JitSerialize() { var options = preserveReferences ? AltSerializerOptions : SerializerOptions; diff --git a/src/Sentry/Internal/ModuleExtensions.cs b/src/Sentry/Internal/ModuleExtensions.cs index bb48ff5d88..cd27293732 100644 --- a/src/Sentry/Internal/ModuleExtensions.cs +++ b/src/Sentry/Internal/ModuleExtensions.cs @@ -11,7 +11,7 @@ internal static class ModuleExtensions /// /// A Module instance /// module.Name, if this is available. module.ScopeName otherwise - [UnconditionalSuppressMessage("SingleFile", "IL3002:Avoid calling members marked with 'RequiresAssemblyFilesAttribute' when publishing as a single-file", Justification = AotHelper.SuppressionJustification)] + [UnconditionalSuppressMessage("SingleFile", "IL3002: calling members marked with 'RequiresAssemblyFilesAttribute'", Justification = AotHelper.AvoidAtRuntime)] public static string? GetNameOrScopeName(this Module module) { return (AotHelper.IsNativeAot || module?.Name is null || module.Name.Equals(UnknownLocation)) diff --git a/src/Sentry/Internal/StackFrame.cs b/src/Sentry/Internal/StackFrame.cs index cdfe61f01a..4e5bb95b15 100644 --- a/src/Sentry/Internal/StackFrame.cs +++ b/src/Sentry/Internal/StackFrame.cs @@ -109,9 +109,7 @@ public RealStackFrame(StackFrame frame) public int GetILOffset() => _frame.GetILOffset(); - [UnconditionalSuppressMessage("Trimming", - "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", - Justification = AotHelper.SuppressionJustification)] + [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AotHelper.AvoidAtRuntime)] public MethodBase? GetMethod() { #pragma warning disable 0162 // Unreachable code on old .NET frameworks diff --git a/src/Sentry/SentryClient.cs b/src/Sentry/SentryClient.cs index 9d7a91e40d..99a618a4a1 100644 --- a/src/Sentry/SentryClient.cs +++ b/src/Sentry/SentryClient.cs @@ -176,6 +176,9 @@ public void CaptureTransaction(SentryTransaction transaction, Scope? scope, Sent CaptureEnvelope(Envelope.FromTransaction(processedTransaction)); } +#if NET6_0_OR_GREATER + [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AotHelper.AvoidAtRuntime)] +#endif private SentryTransaction? BeforeSendTransaction(SentryTransaction transaction, SentryHint hint) { if (_options.BeforeSendTransactionInternal is null) @@ -415,6 +418,9 @@ public bool CaptureEnvelope(Envelope envelope) return false; } +#if NET6_0_OR_GREATER + [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AotHelper.AvoidAtRuntime)] +#endif private SentryEvent? BeforeSend(SentryEvent? @event, SentryHint hint) { if (_options.BeforeSendInternal == null) diff --git a/src/Sentry/SentrySdk.cs b/src/Sentry/SentrySdk.cs index cfd0fe2956..85c3cecdfa 100644 --- a/src/Sentry/SentrySdk.cs +++ b/src/Sentry/SentrySdk.cs @@ -48,18 +48,14 @@ internal static IHub InitHub(SentryOptions options) options.LogWarning("The provided DSN that contains a secret key. This is not required and will be ignored."); } - if (AotHelper.IsNativeAot) #pragma warning disable CS0162 // Unreachable code detected - { #pragma warning disable 0162 // Unreachable code on old .NET frameworks - options.LogDebug("This looks like a Native AOT application build."); + options.LogDebug(AotHelper.IsDynamicCodeSupported + ? "This doesn't look like a Native AOT application build." + : "This looks like a Native AOT application build." + ); #pragma warning restore 0162 - } - else - { #pragma warning restore CS0162 // Unreachable code detected - options.LogDebug("This doesn't look like a Native AOT application build."); - } // Initialize native platform SDKs here if (options.InitNativeSdks) From 81f29947b03906ca41b2e9ac920d63728ffa1cc0 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 14:38:05 +1300 Subject: [PATCH 08/36] Update generate-solution-filters-config.yaml --- scripts/generate-solution-filters-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/generate-solution-filters-config.yaml b/scripts/generate-solution-filters-config.yaml index e0cd3cd6af..b624e50853 100644 --- a/scripts/generate-solution-filters-config.yaml +++ b/scripts/generate-solution-filters-config.yaml @@ -24,6 +24,10 @@ groupConfigs: windowsOnly: # .NET Framework projects - "**/*.AspNet.csproj" + artefacts: + # Any projects in the obj or bin directories + - "**/obj/**/*.csproj" + - "**/bin/**/*.csproj" filterConfigs: From e371e7e3ed58b1fac89bc8e0e785af94bcb0580a Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 14:42:49 +1300 Subject: [PATCH 09/36] Removed extraneous project --- Sentry-CI-Build-Linux.slnf | 1 - Sentry-CI-Build-Windows.slnf | 1 - Sentry-CI-Build-macOS.slnf | 1 - Sentry.Azure.Functions.slnf | 1 - SentryNoMobile.slnf | 1 - scripts/generate-solution-filters-config.yaml | 11 +++++++++++ 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Sentry-CI-Build-Linux.slnf b/Sentry-CI-Build-Linux.slnf index eb63166b4b..bc53783e35 100644 --- a/Sentry-CI-Build-Linux.slnf +++ b/Sentry-CI-Build-Linux.slnf @@ -12,7 +12,6 @@ "samples\\Sentry.Samples.AspNetCore.Serilog\\Sentry.Samples.AspNetCore.Serilog.csproj", "samples\\Sentry.Samples.AspNetCore.WebAPI.Profiling\\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "samples\\Sentry.Samples.Aws.Lambda.AspNetCoreServer\\Sentry.Samples.Aws.Lambda.AspNetCoreServer.csproj", - "samples\\Sentry.Samples.Azure.Functions.Worker\\obj\\Release\\net8.0\\WorkerExtensions\\WorkerExtensions.csproj", "samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj", "samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj", "samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj", diff --git a/Sentry-CI-Build-Windows.slnf b/Sentry-CI-Build-Windows.slnf index 9e2f3f1951..1ad751775d 100644 --- a/Sentry-CI-Build-Windows.slnf +++ b/Sentry-CI-Build-Windows.slnf @@ -13,7 +13,6 @@ "samples\\Sentry.Samples.AspNetCore.Serilog\\Sentry.Samples.AspNetCore.Serilog.csproj", "samples\\Sentry.Samples.AspNetCore.WebAPI.Profiling\\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "samples\\Sentry.Samples.Aws.Lambda.AspNetCoreServer\\Sentry.Samples.Aws.Lambda.AspNetCoreServer.csproj", - "samples\\Sentry.Samples.Azure.Functions.Worker\\obj\\Release\\net8.0\\WorkerExtensions\\WorkerExtensions.csproj", "samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj", "samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj", "samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj", diff --git a/Sentry-CI-Build-macOS.slnf b/Sentry-CI-Build-macOS.slnf index 836e438ac8..7857558117 100644 --- a/Sentry-CI-Build-macOS.slnf +++ b/Sentry-CI-Build-macOS.slnf @@ -14,7 +14,6 @@ "samples\\Sentry.Samples.AspNetCore.Serilog\\Sentry.Samples.AspNetCore.Serilog.csproj", "samples\\Sentry.Samples.AspNetCore.WebAPI.Profiling\\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "samples\\Sentry.Samples.Aws.Lambda.AspNetCoreServer\\Sentry.Samples.Aws.Lambda.AspNetCoreServer.csproj", - "samples\\Sentry.Samples.Azure.Functions.Worker\\obj\\Release\\net8.0\\WorkerExtensions\\WorkerExtensions.csproj", "samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj", "samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj", "samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj", diff --git a/Sentry.Azure.Functions.slnf b/Sentry.Azure.Functions.slnf index d41b7aa4ee..54c80b23c9 100644 --- a/Sentry.Azure.Functions.slnf +++ b/Sentry.Azure.Functions.slnf @@ -2,7 +2,6 @@ "solution": { "path": "Sentry.sln", "projects": [ - "samples\\Sentry.Samples.Azure.Functions.Worker\\obj\\Release\\net8.0\\WorkerExtensions\\WorkerExtensions.csproj", "samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj", "samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj", "src\\Sentry.Analyzers\\Sentry.Analyzers.csproj", diff --git a/SentryNoMobile.slnf b/SentryNoMobile.slnf index 3df3f5ce93..e6e27c6ee7 100644 --- a/SentryNoMobile.slnf +++ b/SentryNoMobile.slnf @@ -11,7 +11,6 @@ "samples\\Sentry.Samples.AspNetCore.Serilog\\Sentry.Samples.AspNetCore.Serilog.csproj", "samples\\Sentry.Samples.AspNetCore.WebAPI.Profiling\\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "samples\\Sentry.Samples.Aws.Lambda.AspNetCoreServer\\Sentry.Samples.Aws.Lambda.AspNetCoreServer.csproj", - "samples\\Sentry.Samples.Azure.Functions.Worker\\obj\\Release\\net8.0\\WorkerExtensions\\WorkerExtensions.csproj", "samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj", "samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj", "samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj", diff --git a/scripts/generate-solution-filters-config.yaml b/scripts/generate-solution-filters-config.yaml index b624e50853..7540b423d8 100644 --- a/scripts/generate-solution-filters-config.yaml +++ b/scripts/generate-solution-filters-config.yaml @@ -39,6 +39,7 @@ filterConfigs: groups: - "macOnly" - "windowsOnly" + - "artefacts" patterns: - "**/*AndroidTestApp.csproj" - "**/*DeviceTests*.csproj" @@ -55,6 +56,8 @@ filterConfigs: - "modules/perfview/**/TraceEvent.csproj" - "modules/perfview/**/FastSerialization.csproj" exclude: + groups: + - "artefacts" patterns: - "**/*AndroidTestApp.csproj" - "**/*DeviceTests*.csproj" @@ -71,6 +74,7 @@ filterConfigs: exclude: groups: - "macOnly" + - "artefacts" patterns: - "**/*AndroidTestApp.csproj" - "**/*DeviceTests*.csproj" @@ -85,6 +89,8 @@ filterConfigs: groups: - "allProjects" exclude: + groups: + - "artefacts" patterns: - "**/Sentry.Bindings*.csproj" - "benchmarks/**/*.csproj" @@ -122,6 +128,9 @@ filterConfigs: - "**/Sentry.Testing.CrashableApp.csproj" - "**/Sentry.Tests.csproj" - "**/Sentry.Analyzers.Tests.csproj" + exclude: + groups: + - "artefacts" - outputPath: SentryCore.slnf solution: .generated.NoMobile.sln @@ -180,6 +189,8 @@ filterConfigs: groups: - "allProjects" exclude: + groups: + - "artefacts" patterns: - "**/*Bindings*.csproj" - "**/*Android*.csproj" From af59166b96ba5cd2c4a37d003c095c39e7767019 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 14:50:49 +1300 Subject: [PATCH 10/36] Fix naming --- src/Sentry/Internal/AotHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sentry/Internal/AotHelper.cs b/src/Sentry/Internal/AotHelper.cs index e391699fed..1fb4e7122c 100644 --- a/src/Sentry/Internal/AotHelper.cs +++ b/src/Sentry/Internal/AotHelper.cs @@ -12,7 +12,7 @@ internal static class AotHelper static AotHelper() { - IsTrimmed = SupportsUnreferencedCode(); + IsTrimmed = CheckIsTrimmed(); #if NETSTANDARD2_0 || NETFRAMEWORK IsDynamicCodeSupported = true; #else @@ -23,7 +23,7 @@ static AotHelper() } [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AvoidAtRuntime)] - private static bool SupportsUnreferencedCode() + private static bool CheckIsTrimmed() { var stackTrace = new StackTrace(false); return stackTrace.GetFrame(0)?.GetMethod() is null; From 94370ad5344cffadc526109a57c5ba105721fd5b Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 15:37:41 +1300 Subject: [PATCH 11/36] Removed misleading AotHelper.IsNativeAot property --- .../SentryFunctionsWorkerMiddleware.cs | 2 +- src/Sentry/Internal/AotHelper.cs | 3 --- src/Sentry/Internal/DebugStackTrace.cs | 2 +- src/Sentry/Internal/ModuleExtensions.cs | 2 +- src/Sentry/Internal/StackFrame.cs | 2 +- src/Sentry/Platforms/Native/SentryNative.cs | 2 +- src/Sentry/SentryClient.cs | 4 ++-- src/Sentry/SentrySdk.cs | 11 +++++++---- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Sentry.Azure.Functions.Worker/SentryFunctionsWorkerMiddleware.cs b/src/Sentry.Azure.Functions.Worker/SentryFunctionsWorkerMiddleware.cs index ce521805f6..c846e8fdf9 100644 --- a/src/Sentry.Azure.Functions.Worker/SentryFunctionsWorkerMiddleware.cs +++ b/src/Sentry.Azure.Functions.Worker/SentryFunctionsWorkerMiddleware.cs @@ -101,7 +101,7 @@ private async Task StartOrContinueTraceAsync(FunctionContext // attribute. In that case the route name will always be /api/ // If this is ever a problem for customers, we can potentially see if there are alternate ways to get this info // from route tables or something. We're not even sure if anyone will use this functionality for now though. - if (!AotHelper.IsNativeAot && !TransactionNameCache.TryGetValue(transactionNameKey, out transactionName)) + if (!AotHelper.IsTrimmed && !TransactionNameCache.TryGetValue(transactionNameKey, out transactionName)) { // Find the HTTP Trigger attribute via reflection var assembly = Assembly.LoadFrom(context.FunctionDefinition.PathToAssembly); diff --git a/src/Sentry/Internal/AotHelper.cs b/src/Sentry/Internal/AotHelper.cs index 1fb4e7122c..97c6ced4c4 100644 --- a/src/Sentry/Internal/AotHelper.cs +++ b/src/Sentry/Internal/AotHelper.cs @@ -8,7 +8,6 @@ internal static class AotHelper internal static bool IsTrimmed { get; } internal static bool IsDynamicCodeSupported { get; } - internal static bool IsNativeAot { get; } static AotHelper() { @@ -18,8 +17,6 @@ static AotHelper() #else IsDynamicCodeSupported = RuntimeFeature.IsDynamicCodeSupported; #endif - // This is our best guess at determining whether AOT is enabled - IsNativeAot = IsTrimmed && !IsDynamicCodeSupported; } [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AvoidAtRuntime)] diff --git a/src/Sentry/Internal/DebugStackTrace.cs b/src/Sentry/Internal/DebugStackTrace.cs index a5093c4c01..3f43297772 100644 --- a/src/Sentry/Internal/DebugStackTrace.cs +++ b/src/Sentry/Internal/DebugStackTrace.cs @@ -176,7 +176,7 @@ internal void MergeDebugImagesInto(SentryEvent @event) [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AotHelper.AvoidAtRuntime)] private IEnumerable CreateFrames(StackTrace stackTrace, bool isCurrentStackTrace, Func skipFrame) { - var frames = (!AotHelper.IsNativeAot && _options.StackTraceMode == StackTraceMode.Enhanced) + var frames = (!AotHelper.IsTrimmed && _options.StackTraceMode == StackTraceMode.Enhanced) ? EnhancedStackTrace.GetFrames(stackTrace).Select(p => new RealStackFrame(p)) : stackTrace.GetFrames().Select(p => new RealStackFrame(p)); diff --git a/src/Sentry/Internal/ModuleExtensions.cs b/src/Sentry/Internal/ModuleExtensions.cs index cd27293732..40657986e6 100644 --- a/src/Sentry/Internal/ModuleExtensions.cs +++ b/src/Sentry/Internal/ModuleExtensions.cs @@ -14,7 +14,7 @@ internal static class ModuleExtensions [UnconditionalSuppressMessage("SingleFile", "IL3002: calling members marked with 'RequiresAssemblyFilesAttribute'", Justification = AotHelper.AvoidAtRuntime)] public static string? GetNameOrScopeName(this Module module) { - return (AotHelper.IsNativeAot || module?.Name is null || module.Name.Equals(UnknownLocation)) + return (AotHelper.IsTrimmed || module?.Name is null || module.Name.Equals(UnknownLocation)) ? module?.ScopeName : module?.Name; } diff --git a/src/Sentry/Internal/StackFrame.cs b/src/Sentry/Internal/StackFrame.cs index 4e5bb95b15..5d11ec2145 100644 --- a/src/Sentry/Internal/StackFrame.cs +++ b/src/Sentry/Internal/StackFrame.cs @@ -113,7 +113,7 @@ public RealStackFrame(StackFrame frame) public MethodBase? GetMethod() { #pragma warning disable 0162 // Unreachable code on old .NET frameworks - return AotHelper.IsNativeAot ? null : _frame.GetMethod(); + return AotHelper.IsTrimmed ? null : _frame.GetMethod(); #pragma warning restore 0162 } diff --git a/src/Sentry/Platforms/Native/SentryNative.cs b/src/Sentry/Platforms/Native/SentryNative.cs index 3cb8fd868c..758d365feb 100644 --- a/src/Sentry/Platforms/Native/SentryNative.cs +++ b/src/Sentry/Platforms/Native/SentryNative.cs @@ -11,7 +11,7 @@ internal static class SentryNative static SentryNative() { - IsAvailable = AotHelper.IsNativeAot && !SentryRuntime.Current.IsBrowserWasm(); + IsAvailable = AotHelper.IsTrimmed && !SentryRuntime.Current.IsBrowserWasm(); } #else // This is a compile-time const so that the irrelevant code is removed during compilation. diff --git a/src/Sentry/SentryClient.cs b/src/Sentry/SentryClient.cs index 99a618a4a1..7d5b071dc5 100644 --- a/src/Sentry/SentryClient.cs +++ b/src/Sentry/SentryClient.cs @@ -194,7 +194,7 @@ public void CaptureTransaction(SentryTransaction transaction, Scope? scope, Sent } catch (Exception e) { - if (!AotHelper.IsNativeAot) + if (!AotHelper.IsTrimmed) { // Attempt to demystify exceptions before adding them as breadcrumbs. e.Demystify(); @@ -435,7 +435,7 @@ public bool CaptureEnvelope(Envelope envelope) } catch (Exception e) { - if (!AotHelper.IsNativeAot) + if (!AotHelper.IsTrimmed) { // Attempt to demystify exceptions before adding them as breadcrumbs. e.Demystify(); diff --git a/src/Sentry/SentrySdk.cs b/src/Sentry/SentrySdk.cs index 85c3cecdfa..505bf7bb1b 100644 --- a/src/Sentry/SentrySdk.cs +++ b/src/Sentry/SentrySdk.cs @@ -50,9 +50,9 @@ internal static IHub InitHub(SentryOptions options) #pragma warning disable CS0162 // Unreachable code detected #pragma warning disable 0162 // Unreachable code on old .NET frameworks - options.LogDebug(AotHelper.IsDynamicCodeSupported - ? "This doesn't look like a Native AOT application build." - : "This looks like a Native AOT application build." + options.LogDebug(AotHelper.IsTrimmed + ? "This looks like a Native AOT application build." + : "This doesn't look like a Native AOT application build." ); #pragma warning restore 0162 #pragma warning restore CS0162 // Unreachable code detected @@ -65,6 +65,9 @@ internal static IHub InitHub(SentryOptions options) #elif ANDROID InitSentryAndroidSdk(options); #elif NET8_0_OR_GREATER + // TODO: Is this working properly? Currently we don't have any way to check if the app is being compiled AOT + // All we know is whether trimming has been enabled or not. I think at the moment we'll be initialising + // SentryNative for managed applications when they've been trimmed! if (SentryNative.IsAvailable) { InitNativeSdk(options); @@ -90,7 +93,7 @@ internal static IHub InitHub(SentryOptions options) LogWarningIfProfilingMisconfigured(options, " on Android"); #else #if NET8_0_OR_GREATER - if (AotHelper.IsNativeAot) + if (AotHelper.IsTrimmed) { LogWarningIfProfilingMisconfigured(options, " for NativeAOT"); } From cd1aafb5a188ebf37542c22c51ec117fb5aa630d Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 19:21:42 +1300 Subject: [PATCH 12/36] Update AotHelper.cs --- src/Sentry/Internal/AotHelper.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Sentry/Internal/AotHelper.cs b/src/Sentry/Internal/AotHelper.cs index 97c6ced4c4..53165c81ca 100644 --- a/src/Sentry/Internal/AotHelper.cs +++ b/src/Sentry/Internal/AotHelper.cs @@ -7,16 +7,10 @@ internal static class AotHelper internal const string AvoidAtRuntime = "Non-trimmable code is avoided at runtime"; internal static bool IsTrimmed { get; } - internal static bool IsDynamicCodeSupported { get; } static AotHelper() { IsTrimmed = CheckIsTrimmed(); -#if NETSTANDARD2_0 || NETFRAMEWORK - IsDynamicCodeSupported = true; -#else - IsDynamicCodeSupported = RuntimeFeature.IsDynamicCodeSupported; -#endif } [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AvoidAtRuntime)] From 4128643f66c30b2334cceb9545b257365936f779 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 20:29:53 +1300 Subject: [PATCH 13/36] Addressed trim warnings for Sentry.Maui --- .../Internal/PageNavigationExtensions.cs | 30 ++++++++++++++++--- test/Sentry.TrimTest/Sentry.TrimTest.csproj | 2 ++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Sentry.Maui/Internal/PageNavigationExtensions.cs b/src/Sentry.Maui/Internal/PageNavigationExtensions.cs index 3c1af81839..a3bfb267a8 100644 --- a/src/Sentry.Maui/Internal/PageNavigationExtensions.cs +++ b/src/Sentry.Maui/Internal/PageNavigationExtensions.cs @@ -1,16 +1,38 @@ +using Sentry.Internal; + namespace Sentry.Maui.Internal; internal static class PageNavigationExtensions { - private static readonly PropertyInfo? DestinationPageProperty = - typeof(NavigatedFromEventArgs).GetProperty("DestinationPage", BindingFlags.Instance | BindingFlags.NonPublic); + private static readonly PropertyInfo? DestinationPageProperty; + private static readonly PropertyInfo? PreviousPageProperty; + + [UnconditionalSuppressMessage("Trimming", "IL2075: DynamicallyAccessedMembers", Justification = AotHelper.AvoidAtRuntime)] + static PageNavigationExtensions() + { + if (AotHelper.IsTrimmed) + { + return; + } - private static readonly PropertyInfo? PreviousPageProperty = - typeof(NavigatedToEventArgs).GetProperty("PreviousPage", BindingFlags.Instance | BindingFlags.NonPublic); + var eventArgsType = typeof(NavigatedFromEventArgs); + DestinationPageProperty = + eventArgsType.GetProperty("DestinationPage", BindingFlags.Instance | BindingFlags.NonPublic); + PreviousPageProperty = + eventArgsType.GetProperty("PreviousPage", BindingFlags.Instance | BindingFlags.NonPublic); + } + /// + /// Reads the (internal) NavigatedFromEventArgs.DestinationPage property via reflection. + /// Note that this will return null if trimming is enabled. + /// public static Page? GetDestinationPage(this NavigatedFromEventArgs eventArgs) => DestinationPageProperty?.GetValue(eventArgs) as Page; + /// + /// Reads the (internal) NavigatedFromEventArgs.PreviousPage property via reflection. + /// Note that this will return null if trimming is enabled. + /// public static Page? GetPreviousPage(this NavigatedToEventArgs eventArgs) => PreviousPageProperty?.GetValue(eventArgs) as Page; } diff --git a/test/Sentry.TrimTest/Sentry.TrimTest.csproj b/test/Sentry.TrimTest/Sentry.TrimTest.csproj index 6c84ed27cb..142ed5beb4 100644 --- a/test/Sentry.TrimTest/Sentry.TrimTest.csproj +++ b/test/Sentry.TrimTest/Sentry.TrimTest.csproj @@ -13,7 +13,9 @@ + + From a49791c7f58f2424533eb97b93ba69d2e348d97e Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 21:07:06 +1300 Subject: [PATCH 14/36] Update PageNavigationExtensions.cs --- src/Sentry.Maui/Internal/PageNavigationExtensions.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Sentry.Maui/Internal/PageNavigationExtensions.cs b/src/Sentry.Maui/Internal/PageNavigationExtensions.cs index a3bfb267a8..9ce0a221c6 100644 --- a/src/Sentry.Maui/Internal/PageNavigationExtensions.cs +++ b/src/Sentry.Maui/Internal/PageNavigationExtensions.cs @@ -14,12 +14,10 @@ static PageNavigationExtensions() { return; } - - var eventArgsType = typeof(NavigatedFromEventArgs); - DestinationPageProperty = - eventArgsType.GetProperty("DestinationPage", BindingFlags.Instance | BindingFlags.NonPublic); - PreviousPageProperty = - eventArgsType.GetProperty("PreviousPage", BindingFlags.Instance | BindingFlags.NonPublic); + DestinationPageProperty = typeof(NavigatedFromEventArgs) + .GetProperty("DestinationPage", BindingFlags.Instance | BindingFlags.NonPublic); + PreviousPageProperty = typeof(NavigatedToEventArgs) + .GetProperty("PreviousPage", BindingFlags.Instance | BindingFlags.NonPublic); } /// From a9de355066bb1409e9f3603cd373f181163ada52 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 12 Dec 2024 21:55:33 +1300 Subject: [PATCH 15/36] Addressed OpenTelemetry trim warnings --- .../Sentry.OpenTelemetry.csproj | 3 ++- .../SentrySpanProcessor.cs | 23 ++++++++++++++++--- .../Sentry.OpenTelemetry.Tests.csproj | 4 ++-- test/Sentry.TrimTest/Sentry.TrimTest.csproj | 9 ++++++++ 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/Sentry.OpenTelemetry/Sentry.OpenTelemetry.csproj b/src/Sentry.OpenTelemetry/Sentry.OpenTelemetry.csproj index 1af2c859eb..66daebfda3 100644 --- a/src/Sentry.OpenTelemetry/Sentry.OpenTelemetry.csproj +++ b/src/Sentry.OpenTelemetry/Sentry.OpenTelemetry.csproj @@ -16,7 +16,8 @@ - + + diff --git a/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs b/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs index 9f32987db5..b6137201ff 100644 --- a/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs +++ b/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs @@ -463,9 +463,12 @@ private void GenerateSentryErrorsFromOtelSpan(Activity activity, IDictionary - - + + diff --git a/test/Sentry.TrimTest/Sentry.TrimTest.csproj b/test/Sentry.TrimTest/Sentry.TrimTest.csproj index 142ed5beb4..94690df197 100644 --- a/test/Sentry.TrimTest/Sentry.TrimTest.csproj +++ b/test/Sentry.TrimTest/Sentry.TrimTest.csproj @@ -9,13 +9,22 @@ true true + false + + + + + + + + From 6102abb6c90221551e2573e2cbe8b4765bc969f1 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 12 Dec 2024 21:39:02 +0000 Subject: [PATCH 16/36] Format code --- src/Sentry.OpenTelemetry/SentrySpanProcessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs b/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs index b6137201ff..09172c0636 100644 --- a/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs +++ b/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs @@ -463,7 +463,7 @@ private void GenerateSentryErrorsFromOtelSpan(Activity activity, IDictionary Date: Fri, 13 Dec 2024 14:23:12 +1300 Subject: [PATCH 17/36] Addressed trim warnings in Sentry.Google.Cloud.Functions --- src/Sentry.AspNetCore/Sentry.AspNetCore.csproj | 3 +++ .../Sentry.Google.Cloud.Functions.csproj | 6 ++++++ src/Sentry.Google.Cloud.Functions/SentryStartup.cs | 4 +++- src/Sentry.Hangfire/Sentry.Hangfire.csproj | 2 ++ src/Sentry.Profiling/Sentry.Profiling.csproj | 1 + test/Sentry.TrimTest/Sentry.TrimTest.csproj | 11 +++++++++++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Sentry.AspNetCore/Sentry.AspNetCore.csproj b/src/Sentry.AspNetCore/Sentry.AspNetCore.csproj index 5220958947..d75cabef9f 100644 --- a/src/Sentry.AspNetCore/Sentry.AspNetCore.csproj +++ b/src/Sentry.AspNetCore/Sentry.AspNetCore.csproj @@ -19,6 +19,9 @@ + + + diff --git a/src/Sentry.Google.Cloud.Functions/Sentry.Google.Cloud.Functions.csproj b/src/Sentry.Google.Cloud.Functions/Sentry.Google.Cloud.Functions.csproj index b3961278f8..e704ddaf3a 100644 --- a/src/Sentry.Google.Cloud.Functions/Sentry.Google.Cloud.Functions.csproj +++ b/src/Sentry.Google.Cloud.Functions/Sentry.Google.Cloud.Functions.csproj @@ -6,9 +6,15 @@ Official Google Cloud Functions integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time. + + true + true + + + diff --git a/src/Sentry.Google.Cloud.Functions/SentryStartup.cs b/src/Sentry.Google.Cloud.Functions/SentryStartup.cs index 7d42e9f66a..73cae34ce8 100644 --- a/src/Sentry.Google.Cloud.Functions/SentryStartup.cs +++ b/src/Sentry.Google.Cloud.Functions/SentryStartup.cs @@ -29,7 +29,9 @@ public override void ConfigureLogging(WebHostBuilderContext context, ILoggingBui // TODO: refactor this with SentryWebHostBuilderExtensions var section = context.Configuration.GetSection("Sentry"); - logging.Services.Configure(section); + logging.Services.AddSingleton>( + _ => new SentryAspNetCoreOptionsSetup(section) + ); logging.Services.Configure(options => { diff --git a/src/Sentry.Hangfire/Sentry.Hangfire.csproj b/src/Sentry.Hangfire/Sentry.Hangfire.csproj index 03ff86933d..d2f0ba0aa1 100644 --- a/src/Sentry.Hangfire/Sentry.Hangfire.csproj +++ b/src/Sentry.Hangfire/Sentry.Hangfire.csproj @@ -8,6 +8,8 @@ + true diff --git a/src/Sentry.Profiling/Sentry.Profiling.csproj b/src/Sentry.Profiling/Sentry.Profiling.csproj index 0d67c7291b..c453876242 100644 --- a/src/Sentry.Profiling/Sentry.Profiling.csproj +++ b/src/Sentry.Profiling/Sentry.Profiling.csproj @@ -8,6 +8,7 @@ + true diff --git a/test/Sentry.TrimTest/Sentry.TrimTest.csproj b/test/Sentry.TrimTest/Sentry.TrimTest.csproj index 94690df197..851d2f5614 100644 --- a/test/Sentry.TrimTest/Sentry.TrimTest.csproj +++ b/test/Sentry.TrimTest/Sentry.TrimTest.csproj @@ -16,15 +16,26 @@ + + + + + + + + + + + From 2aee8022760586b874afa241e0b36bfd0fe553b2 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Fri, 13 Dec 2024 15:43:07 +1300 Subject: [PATCH 18/36] Addressed Sentry.AspNetCore.Grpc trim warnings --- src/Sentry.AspNetCore.Grpc/Sentry.AspNetCore.Grpc.csproj | 2 +- test/Sentry.TrimTest/Sentry.TrimTest.csproj | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Sentry.AspNetCore.Grpc/Sentry.AspNetCore.Grpc.csproj b/src/Sentry.AspNetCore.Grpc/Sentry.AspNetCore.Grpc.csproj index 8963ddfd82..9e8c414b3b 100644 --- a/src/Sentry.AspNetCore.Grpc/Sentry.AspNetCore.Grpc.csproj +++ b/src/Sentry.AspNetCore.Grpc/Sentry.AspNetCore.Grpc.csproj @@ -11,7 +11,7 @@ - + diff --git a/test/Sentry.TrimTest/Sentry.TrimTest.csproj b/test/Sentry.TrimTest/Sentry.TrimTest.csproj index 851d2f5614..dbd964c1b0 100644 --- a/test/Sentry.TrimTest/Sentry.TrimTest.csproj +++ b/test/Sentry.TrimTest/Sentry.TrimTest.csproj @@ -14,6 +14,8 @@ + + @@ -22,6 +24,8 @@ + + @@ -33,6 +37,7 @@ + From fce29a970fc7d5229dd0e8f09739ecbfeb9977f1 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Fri, 13 Dec 2024 16:37:22 +1300 Subject: [PATCH 19/36] Addressed trim warnings in Sentry.Azure.Functions.Worker --- .../SentryFunctionsWorkerMiddleware.cs | 1 + test/Sentry.TrimTest/Sentry.TrimTest.csproj | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Sentry.Azure.Functions.Worker/SentryFunctionsWorkerMiddleware.cs b/src/Sentry.Azure.Functions.Worker/SentryFunctionsWorkerMiddleware.cs index c846e8fdf9..c3c57fe71e 100644 --- a/src/Sentry.Azure.Functions.Worker/SentryFunctionsWorkerMiddleware.cs +++ b/src/Sentry.Azure.Functions.Worker/SentryFunctionsWorkerMiddleware.cs @@ -82,6 +82,7 @@ public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next } [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AotHelper.AvoidAtRuntime)] + [UnconditionalSuppressMessage("Trimming", "IL2075: DynamicallyAccessedMembers", Justification = AotHelper.AvoidAtRuntime)] private async Task StartOrContinueTraceAsync(FunctionContext context) { var transactionName = context.FunctionDefinition.Name; diff --git a/test/Sentry.TrimTest/Sentry.TrimTest.csproj b/test/Sentry.TrimTest/Sentry.TrimTest.csproj index dbd964c1b0..4abdaebe66 100644 --- a/test/Sentry.TrimTest/Sentry.TrimTest.csproj +++ b/test/Sentry.TrimTest/Sentry.TrimTest.csproj @@ -9,7 +9,7 @@ true true - false + true @@ -17,6 +17,7 @@ + @@ -27,6 +28,7 @@ + @@ -38,8 +40,9 @@ + - + From daa1b71405579bcb3d03dcc0d235097864a013f1 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Mon, 16 Dec 2024 13:36:55 +1300 Subject: [PATCH 20/36] Added MAUI trim test app to ensure trimming works on ios and android --- .github/actions/environment/action.yml | 2 +- .github/workflows/build.yml | 13 +- test/Sentry.MauiTrimTest/App.xaml | 14 + test/Sentry.MauiTrimTest/App.xaml.cs | 14 + test/Sentry.MauiTrimTest/AppShell.xaml | 15 + test/Sentry.MauiTrimTest/AppShell.xaml.cs | 9 + .../Sentry.MauiTrimTest/Directory.Build.props | 2 + .../Directory.Build.targets | 2 + test/Sentry.MauiTrimTest/MainPage.xaml | 36 + test/Sentry.MauiTrimTest/MainPage.xaml.cs | 24 + test/Sentry.MauiTrimTest/MauiProgram.cs | 24 + .../Platforms/Android/AndroidManifest.xml | 6 + .../Platforms/Android/MainActivity.cs | 10 + .../Platforms/Android/MainApplication.cs | 15 + .../Android/Resources/values/colors.xml | 6 + .../Platforms/MacCatalyst/AppDelegate.cs | 9 + .../Platforms/MacCatalyst/Entitlements.plist | 14 + .../Platforms/MacCatalyst/Info.plist | 38 + .../Platforms/MacCatalyst/Program.cs | 15 + .../Platforms/Tizen/Main.cs | 16 + .../Platforms/Tizen/tizen-manifest.xml | 15 + .../Platforms/Windows/App.xaml | 8 + .../Platforms/Windows/App.xaml.cs | 24 + .../Platforms/Windows/Package.appxmanifest | 46 + .../Platforms/Windows/app.manifest | 15 + .../Platforms/iOS/AppDelegate.cs | 9 + .../Platforms/iOS/Info.plist | 32 + .../Platforms/iOS/Program.cs | 15 + .../iOS/Resources/PrivacyInfo.xcprivacy | 51 + .../Properties/launchSettings.json | 8 + test/Sentry.MauiTrimTest/README.md | 15 + .../Resources/AppIcon/appicon.svg | 4 + .../Resources/AppIcon/appiconfg.svg | 8 + .../Resources/Fonts/FluentUI.cs | 7920 +++++++++++++++++ .../Resources/Fonts/OpenSans-Regular.ttf | Bin 0 -> 107280 bytes .../Resources/Fonts/OpenSans-Semibold.ttf | Bin 0 -> 111184 bytes .../Resources/Images/dotnet_bot.png | Bin 0 -> 93437 bytes .../Resources/Raw/AboutAssets.txt | 15 + .../Resources/Splash/splash.svg | 8 + .../Resources/Styles/Colors.xaml | 45 + .../Resources/Styles/Styles.xaml | 451 + .../Sentry.MauiTrimTest.csproj | 83 + 42 files changed, 9052 insertions(+), 4 deletions(-) create mode 100644 test/Sentry.MauiTrimTest/App.xaml create mode 100644 test/Sentry.MauiTrimTest/App.xaml.cs create mode 100644 test/Sentry.MauiTrimTest/AppShell.xaml create mode 100644 test/Sentry.MauiTrimTest/AppShell.xaml.cs create mode 100644 test/Sentry.MauiTrimTest/Directory.Build.props create mode 100644 test/Sentry.MauiTrimTest/Directory.Build.targets create mode 100644 test/Sentry.MauiTrimTest/MainPage.xaml create mode 100644 test/Sentry.MauiTrimTest/MainPage.xaml.cs create mode 100644 test/Sentry.MauiTrimTest/MauiProgram.cs create mode 100644 test/Sentry.MauiTrimTest/Platforms/Android/AndroidManifest.xml create mode 100644 test/Sentry.MauiTrimTest/Platforms/Android/MainActivity.cs create mode 100644 test/Sentry.MauiTrimTest/Platforms/Android/MainApplication.cs create mode 100644 test/Sentry.MauiTrimTest/Platforms/Android/Resources/values/colors.xml create mode 100644 test/Sentry.MauiTrimTest/Platforms/MacCatalyst/AppDelegate.cs create mode 100644 test/Sentry.MauiTrimTest/Platforms/MacCatalyst/Entitlements.plist create mode 100644 test/Sentry.MauiTrimTest/Platforms/MacCatalyst/Info.plist create mode 100644 test/Sentry.MauiTrimTest/Platforms/MacCatalyst/Program.cs create mode 100644 test/Sentry.MauiTrimTest/Platforms/Tizen/Main.cs create mode 100644 test/Sentry.MauiTrimTest/Platforms/Tizen/tizen-manifest.xml create mode 100644 test/Sentry.MauiTrimTest/Platforms/Windows/App.xaml create mode 100644 test/Sentry.MauiTrimTest/Platforms/Windows/App.xaml.cs create mode 100644 test/Sentry.MauiTrimTest/Platforms/Windows/Package.appxmanifest create mode 100644 test/Sentry.MauiTrimTest/Platforms/Windows/app.manifest create mode 100644 test/Sentry.MauiTrimTest/Platforms/iOS/AppDelegate.cs create mode 100644 test/Sentry.MauiTrimTest/Platforms/iOS/Info.plist create mode 100644 test/Sentry.MauiTrimTest/Platforms/iOS/Program.cs create mode 100644 test/Sentry.MauiTrimTest/Platforms/iOS/Resources/PrivacyInfo.xcprivacy create mode 100644 test/Sentry.MauiTrimTest/Properties/launchSettings.json create mode 100644 test/Sentry.MauiTrimTest/README.md create mode 100644 test/Sentry.MauiTrimTest/Resources/AppIcon/appicon.svg create mode 100644 test/Sentry.MauiTrimTest/Resources/AppIcon/appiconfg.svg create mode 100644 test/Sentry.MauiTrimTest/Resources/Fonts/FluentUI.cs create mode 100644 test/Sentry.MauiTrimTest/Resources/Fonts/OpenSans-Regular.ttf create mode 100644 test/Sentry.MauiTrimTest/Resources/Fonts/OpenSans-Semibold.ttf create mode 100644 test/Sentry.MauiTrimTest/Resources/Images/dotnet_bot.png create mode 100644 test/Sentry.MauiTrimTest/Resources/Raw/AboutAssets.txt create mode 100644 test/Sentry.MauiTrimTest/Resources/Splash/splash.svg create mode 100644 test/Sentry.MauiTrimTest/Resources/Styles/Colors.xaml create mode 100644 test/Sentry.MauiTrimTest/Resources/Styles/Styles.xaml create mode 100644 test/Sentry.MauiTrimTest/Sentry.MauiTrimTest.csproj diff --git a/.github/actions/environment/action.yml b/.github/actions/environment/action.yml index 82012aa43e..f67824f33f 100644 --- a/.github/actions/environment/action.yml +++ b/.github/actions/environment/action.yml @@ -15,7 +15,7 @@ runs: - name: Pin the Xcode Version if: runner.os == 'macOS' shell: bash - run: sudo xcode-select --switch /Applications/Xcode_16.0.app + run: sudo xcode-select --switch /Applications/Xcode_16.2.app # Needed for Android SDK setup step - uses: actions/setup-java@v3 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4a0f15fa51..ee7667da40 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: false matrix: - # Pin macos to get the version of XCode that we need: https://github.com/actions/runner-images/issues/10703 + # Pin macos to get the version of Xcode that we need: https://github.com/actions/runner-images/issues/10703 os: [ubuntu-latest, windows-latest, macos-15] steps: @@ -53,7 +53,7 @@ jobs: strategy: fail-fast: false matrix: - # Pin macos to get the version of XCode that we need: https://github.com/actions/runner-images/issues/10703 + # Pin macos to get the version of Xcode that we need: https://github.com/actions/runner-images/issues/10703 os: [ubuntu-latest, windows-latest, macos-15] steps: @@ -154,7 +154,7 @@ jobs: strategy: fail-fast: false matrix: - # Pin macos to get the version of XCode that we need: https://github.com/actions/runner-images/issues/10703 + # Pin macos to get the version of Xcode that we need: https://github.com/actions/runner-images/issues/10703 os: [ubuntu-latest, windows-latest, macos-15] steps: @@ -224,6 +224,13 @@ jobs: - name: Publish Test app run: dotnet publish test/Sentry.TrimTest/Sentry.TrimTest.csproj -c Release -r osx-arm64 + - name: Publish Test app (Android) + run: dotnet publish test/Sentry.TrimTest/Sentry.TrimTest.csproj -c Release -r osx-arm64 + + - name: Publish Test app (iOS) + run: dotnet publish test/Sentry.MauiTrimTest/Sentry.MauiTrimTest.csproj -c Release -f net9.0-ios18.0 -r ios-arm64 + run: dotnet publish test/Sentry.TrimTest/Sentry.TrimTest.csproj -c Release -r osx-arm64 + test-solution-filters: runs-on: ubuntu-latest if: ${{ !startsWith(github.ref_name, 'release/') }} diff --git a/test/Sentry.MauiTrimTest/App.xaml b/test/Sentry.MauiTrimTest/App.xaml new file mode 100644 index 0000000000..abbee2a6f8 --- /dev/null +++ b/test/Sentry.MauiTrimTest/App.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/test/Sentry.MauiTrimTest/App.xaml.cs b/test/Sentry.MauiTrimTest/App.xaml.cs new file mode 100644 index 0000000000..ecf338d093 --- /dev/null +++ b/test/Sentry.MauiTrimTest/App.xaml.cs @@ -0,0 +1,14 @@ +namespace Sentry.MauiTrimTest; + +public partial class App : Application +{ + public App() + { + InitializeComponent(); + } + + protected override Window CreateWindow(IActivationState? activationState) + { + return new Window(new AppShell()); + } +} \ No newline at end of file diff --git a/test/Sentry.MauiTrimTest/AppShell.xaml b/test/Sentry.MauiTrimTest/AppShell.xaml new file mode 100644 index 0000000000..2a252bfebb --- /dev/null +++ b/test/Sentry.MauiTrimTest/AppShell.xaml @@ -0,0 +1,15 @@ + + + + + + diff --git a/test/Sentry.MauiTrimTest/AppShell.xaml.cs b/test/Sentry.MauiTrimTest/AppShell.xaml.cs new file mode 100644 index 0000000000..3a01412daa --- /dev/null +++ b/test/Sentry.MauiTrimTest/AppShell.xaml.cs @@ -0,0 +1,9 @@ +namespace Sentry.MauiTrimTest; + +public partial class AppShell : Shell +{ + public AppShell() + { + InitializeComponent(); + } +} diff --git a/test/Sentry.MauiTrimTest/Directory.Build.props b/test/Sentry.MauiTrimTest/Directory.Build.props new file mode 100644 index 0000000000..bbb7413d29 --- /dev/null +++ b/test/Sentry.MauiTrimTest/Directory.Build.props @@ -0,0 +1,2 @@ + + diff --git a/test/Sentry.MauiTrimTest/Directory.Build.targets b/test/Sentry.MauiTrimTest/Directory.Build.targets new file mode 100644 index 0000000000..bbb7413d29 --- /dev/null +++ b/test/Sentry.MauiTrimTest/Directory.Build.targets @@ -0,0 +1,2 @@ + + diff --git a/test/Sentry.MauiTrimTest/MainPage.xaml b/test/Sentry.MauiTrimTest/MainPage.xaml new file mode 100644 index 0000000000..d9866e8519 --- /dev/null +++ b/test/Sentry.MauiTrimTest/MainPage.xaml @@ -0,0 +1,36 @@ + + + + + + + +