Skip to content
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

Trimming for .NET 7+ #2732

Merged
merged 117 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 101 commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
5717371
net8 sdk
bruno-garcia Sep 15, 2023
9de053f
net8 in ci
bruno-garcia Sep 15, 2023
9575f68
new import needed
bruno-garcia Sep 15, 2023
00590b5
hack to build on mac
bruno-garcia Sep 15, 2023
de035bc
Merge branch 'feat/4.0.0' into feat/net8-2
bruno-garcia Sep 18, 2023
ad557a0
Merge branch 'feat/4.0.0' into feat/net8-2
bruno-garcia Sep 18, 2023
eaef79f
net7 min
bruno-garcia Sep 19, 2023
13c3e7c
update cli integration test
vaind Sep 25, 2023
291ff21
fix cli integration test paths
vaind Sep 25, 2023
c1320df
Merge remote-tracking branch 'origin/feat/4.0.0' into feat/net8-2
vaind Oct 4, 2023
a85d7f8
add SelfContained=true (previously implied by RuntimeIdentifier)
vaind Oct 4, 2023
b8a3082
Merge remote-tracking branch 'origin' into feat/net8-2
bruno-garcia Oct 6, 2023
33a2e8b
Removed `Scope.Platform` as it would never be applied. (#2695)
jamescrosswell Oct 5, 2023
e4f2a07
feat: Native AOT frame info (#2701)
vaind Oct 5, 2023
4cb767d
fix build on mac m1 (#2702)
vaind Oct 5, 2023
67c0bd1
Upgraded to `NLog 5` (#2697)
bitsandfoxes Oct 6, 2023
7e0e916
fix: CaptureFailedRequests xml docs
bruno-garcia Oct 6, 2023
bebb2f4
Fallback to `AssemblyVersion` if `InformalVersion` is `NullOrEmpty` (…
bitsandfoxes Oct 10, 2023
e75bcfa
Reenabled API Verify tests (#2716)
bitsandfoxes Oct 11, 2023
4ed996a
Reordered parameters to TransactionContext and SpanContext constructo…
jamescrosswell Oct 11, 2023
e11f3fb
Change signature order in `DiagnosticLogger` for exceptions (#2715)
bitsandfoxes Oct 12, 2023
7dac060
build(deps): bump styfle/cancel-workflow-action from 0.11.0 to 0.12.0…
dependabot[bot] Oct 9, 2023
cc21277
Fix: Scope not being applied to OpenTelemetry spans in ASP.NET Core (…
jamescrosswell Oct 9, 2023
2fa8a6b
Delete SentryAzureFunctions.slnf (#2708)
bruno-garcia Oct 10, 2023
6b74c2e
Apply Scope to exceptions captured via Activity.RecordException (#2712)
jamescrosswell Oct 10, 2023
e839285
release: 3.40.0
getsentry-bot Oct 10, 2023
a4f681e
Update .craft.yml (#2615)
jamescrosswell Oct 11, 2023
008dfca
Make ISentryUserFactory public (#2719)
jamescrosswell Oct 12, 2023
c8fa788
chore: update scripts/update-java.ps1 to 6.31.0 (#2723)
github-actions[bot] Oct 13, 2023
6b484a5
release: 3.40.1
getsentry-bot Oct 12, 2023
8e8a159
chore(deps): update Cocoa SDK to v8.13.1 (#2722)
github-actions[bot] Oct 13, 2023
1182b90
Merge branch 'feat/4.0.0' into feat/net8-2
vaind Oct 14, 2023
1eb587c
Merge branch 'feat/4.0.0' into feat/net8-2
vaind Oct 14, 2023
dc1f34e
temporarily drop caching
bitsandfoxes Oct 16, 2023
e685d3f
loggig
bitsandfoxes Oct 16, 2023
51d7b58
pinning the version
bitsandfoxes Oct 16, 2023
fffe04d
restore and update
bitsandfoxes Oct 16, 2023
f58540b
no rollback
bitsandfoxes Oct 16, 2023
db71be6
no more tizen
bitsandfoxes Oct 16, 2023
c1ac3c4
fix
bitsandfoxes Oct 16, 2023
67be026
restore and updte #2
bitsandfoxes Oct 16, 2023
cb50e2f
suddenly I need iOS?
bitsandfoxes Oct 16, 2023
1ed4aa1
restore and update #3
bitsandfoxes Oct 16, 2023
df4d5c9
added .NET 6 for tests
bitsandfoxes Oct 16, 2023
7000964
Everything except the Ben.Demystifier errors
jamescrosswell Oct 17, 2023
c233375
Updated AndroidScopeObserver
jamescrosswell Oct 17, 2023
4c766e5
Fixed Error NETSDK1022 : Duplicate 'Compile' items were included.
jamescrosswell Oct 17, 2023
aeb9379
Update device-tests-android.yml
jamescrosswell Oct 17, 2023
6abe29d
Update device-tests-ios.yml
jamescrosswell Oct 17, 2023
4592d67
Update device-tests-ios.yml
jamescrosswell Oct 17, 2023
873786e
Update device-tests-ios.yml
jamescrosswell Oct 17, 2023
51861c5
Try to force .NET 7.0 for Sentry.Maui.Device.TestApp
jamescrosswell Oct 17, 2023
2001dad
Attempt workload restore from specific project
jamescrosswell Oct 17, 2023
21aab6d
Merge branch 'feat/4.0.0' into net8-trimming
jamescrosswell Oct 18, 2023
02f4c13
Added SentryAot.slnf solution filter and AOT specific tests
jamescrosswell Oct 18, 2023
c595407
Merge branch 'feat/4.0.0' into net8-trimming
jamescrosswell Oct 18, 2023
e6bedf6
Set PublishAot instead of IsTrimmable
jamescrosswell Oct 19, 2023
0845926
Updated verify tests
jamescrosswell Oct 19, 2023
fb9026a
All tests green!
jamescrosswell Oct 19, 2023
f46ba4e
Disabled warnings about ModuleInitializer
jamescrosswell Oct 19, 2023
d7d193b
Merge branch 'feat/4.0.0' into net8-trimming
jamescrosswell Oct 22, 2023
f644f1a
Update ApiApprovalTests.Run.DotNet8_0.verified.txt
jamescrosswell Oct 22, 2023
731c682
Removed redundant .NET 8 install
jamescrosswell Oct 22, 2023
8e7f239
Merge branch 'feat/4.0.0' into net8-trimming
jamescrosswell Oct 24, 2023
8f195eb
Added attribution for GraphQLRequestContentReader
jamescrosswell Oct 24, 2023
87703bb
Implemented GetNetCoreVersion for AOT apps
jamescrosswell Oct 24, 2023
d13b9e0
Merge branch 'feat/4.0.0' into net8-trimming
jamescrosswell Oct 24, 2023
2c5c4f5
Added job to build/test SentryAot.slnf on CI
jamescrosswell Oct 25, 2023
b9d4397
Fixed unit test for SentryAot.slnf
jamescrosswell Oct 25, 2023
a8c1397
Update Sentry.Testing.csproj
jamescrosswell Oct 25, 2023
0ece950
Update sentry-cli-integration.Tests.ps1
jamescrosswell Oct 25, 2023
7e47537
build tweaks
jamescrosswell Oct 25, 2023
b40853d
Aot compilation passed as a parameter in integration tests
jamescrosswell Oct 25, 2023
71cdf04
Update sentry-cli-integration.Tests.ps1
jamescrosswell Oct 26, 2023
339fb2a
Added UniqueForAotAttribute for use with Verify
jamescrosswell Oct 26, 2023
9aaf0f8
Removed unecessary AOT verify tests
jamescrosswell Oct 26, 2023
a633efb
Update DebugStackTrace.cs
jamescrosswell Oct 26, 2023
fd1c591
Resolved NETSDK1022 when uncommenting Link to BenDemystifier
jamescrosswell Oct 26, 2023
aaa116a
fix CLI integration tests
vaind Oct 27, 2023
0f21483
remove net8.0 TF because of test failures
vaind Oct 27, 2023
7020603
remove aot arg
vaind Oct 27, 2023
7d59dab
Update scripts/generate-solution-filters-config.yaml
jamescrosswell Oct 30, 2023
d6e0529
Update scripts/generate-solution-filters.ps1
jamescrosswell Oct 30, 2023
fa532d0
Removed TRIMMABLE directive from WinUIUnhandledExceptionIntegration
jamescrosswell Oct 30, 2023
84b62a1
Removed TRIMMABLE directive from JsonExtensions
jamescrosswell Oct 30, 2023
368ec4a
Merge branch 'net8-trimming' of github.com:getsentry/sentry-dotnet in…
jamescrosswell Oct 30, 2023
da95925
Removed TRIMMABLE from SentryOptions
jamescrosswell Oct 30, 2023
4e57157
Removed TRIMMABLE from RuntimeInfo
jamescrosswell Oct 30, 2023
24ade65
Removed TRIMMABLE from Sentry source
jamescrosswell Oct 30, 2023
38c109f
Removed AOT build job
jamescrosswell Oct 30, 2023
2c231c3
Merge branch 'feat/4.0.0' into net8-trimming
jamescrosswell Oct 30, 2023
bd1edbb
Removed UniqueForAotAttribute
jamescrosswell Oct 30, 2023
fee3771
Integrated review feedback
jamescrosswell Oct 30, 2023
afe3b27
Update Sentry.csproj
jamescrosswell Oct 30, 2023
f3a9f8e
Removed TRIMMABLE from tests and removed .net8.0 targets
jamescrosswell Oct 30, 2023
56cbdc0
Removed dangling .NET 8 verify test results
jamescrosswell Oct 30, 2023
1553728
Update HubTests.cs
jamescrosswell Oct 30, 2023
1f31a65
Added missing UnconditionalSuppressMessage attributes
jamescrosswell Oct 31, 2023
6f7e44a
Fixed Ben.Demystifier warnings when IsAotCompatible is true
jamescrosswell Oct 31, 2023
fb34208
Update Ben.Demystifier
jamescrosswell Oct 31, 2023
bba7ed2
Revert "Update Ben.Demystifier"
jamescrosswell Oct 31, 2023
7496595
Added AOT Test to CI
jamescrosswell Oct 31, 2023
7ffc102
Integrated review suggestions
jamescrosswell Oct 31, 2023
685e186
Update Ben.Demystifier
jamescrosswell Nov 1, 2023
7c591c0
Revert "Update Ben.Demystifier"
jamescrosswell Nov 1, 2023
e42f9fc
Update Ben.Demystifier
jamescrosswell Nov 1, 2023
bf5fcb6
Update Ben.Demystifier
jamescrosswell Nov 1, 2023
4f5aae0
Removed PublishAot from samples/Directory.Build.props
jamescrosswell Nov 1, 2023
c420322
Update Ben.Demystifier
jamescrosswell Nov 1, 2023
a58ae04
Update Ben.Demystifier
jamescrosswell Nov 1, 2023
014f6f5
Fixed for mobile targets and removed Sentry.Aot.sln
jamescrosswell Nov 1, 2023
07cb4bd
Update Directory.Build.props
jamescrosswell Nov 2, 2023
d640fdb
Disabled for net7.0-android
jamescrosswell Nov 2, 2023
2908bbc
Delete Sentry.Aot.sln.DotSettings
jamescrosswell Nov 2, 2023
9e34789
Update CHANGELOG.md
jamescrosswell Nov 2, 2023
1b3a5ba
Update CHANGELOG.md
jamescrosswell Nov 2, 2023
257787b
Merge branch 'feat/4.0.0' into net8-trimming
jamescrosswell Nov 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<NoWarn>$(NoWarn);CS8002</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(SolutionName)' == 'Sentry.NoMobile'">
<PropertyGroup Condition="'$(SolutionName)' == 'Sentry.NoMobile' or '$(SolutionName)' == 'Sentry.Aot'">
jamescrosswell marked this conversation as resolved.
Show resolved Hide resolved
<NO_MOBILE>true</NO_MOBILE>
</PropertyGroup>

Expand Down
549 changes: 549 additions & 0 deletions Sentry.Aot.sln

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Sentry.Aot.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UI/@EntryIndexedValue">UI</s:String></wpf:ResourceDictionary>
4 changes: 3 additions & 1 deletion Sentry.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QL/@EntryIndexedValue">QL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UI/@EntryIndexedValue">UI</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Enricher/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=enrichers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=instrumenter/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=otel/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=otel/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
12 changes: 12 additions & 0 deletions SentryAot.slnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"solution": {
"path": "Sentry.Aot.sln",
"projects": [
"samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj",
"src\\Sentry\\Sentry.csproj",
jamescrosswell marked this conversation as resolved.
Show resolved Hide resolved
"test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj",
"test\\Sentry.Testing\\Sentry.Testing.csproj",
"test\\Sentry.Tests\\Sentry.Tests.csproj"
]
}
}
4 changes: 4 additions & 0 deletions samples/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
<MtouchUseLlvm>false</MtouchUseLlvm>
</PropertyGroup>

<!-- AOT not supported for osx-arm64 on .NET 7 -->
<PropertyGroup Condition="'$(SolutionName)' == 'Sentry.Aot' and (!$([MSBuild]::IsOSPlatform('OSX')) or '$(TargetFramework)' == 'net8.0')">
<PublishAot>true</PublishAot>
</PropertyGroup>
jamescrosswell marked this conversation as resolved.
Show resolved Hide resolved
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="!$([MSBuild]::IsOSPlatform('OSX')) or '$(TargetFramework)' == 'net8.0'">
<!-- AOT not supported for osx-arm64 on .NET 7 -->
<!-- TODO, consider updating after changes from #2732 come into effect -->
<PublishAot Condition="!$([MSBuild]::IsOSPlatform('OSX')) or '$(TargetFramework)' == 'net8.0'">true</PublishAot>
<PublishAot>true</PublishAot>
</PropertyGroup>

<PropertyGroup>
Expand Down
18 changes: 17 additions & 1 deletion scripts/generate-solution-filters-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
# the *.slnf solution filters for the Sentry solution.
################################################################

defaultSolution: Sentry.sln
coreSolution: Sentry.sln
# We don't maintain the buildSolutions manually... these are just
# copies of Sentry.sln that are used to set certain build
# properties when using solution filters that are based on these
buildSolutions:
- Sentry.NoMobile.sln
- Sentry.Aot.sln

groupConfigs:
allProjects:
Expand Down Expand Up @@ -170,3 +176,13 @@ filterConfigs:
- "**/*Bindings*"
- "**/*DeviceTests*"
- "**/*TestApp*"

- outputPath: SentryAot.slnf
solution: Sentry.Aot.sln
include:
patterns:
- "**/Sentry.Samples.Console.Basic.csproj"
- "**/Sentry.csproj"
- "**/Sentry.Testing.csproj"
- "**/Sentry.Testing.CrashableApp.csproj"
- "**/Sentry.Tests.csproj"
12 changes: 7 additions & 5 deletions scripts/generate-solution-filters.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ foreach($filter in $config.filterConfigs){
$solution = if ($filter.ContainsKey('solution')) {
$filter.solution
} else {
$config.defaultSolution
$config.coreSolution
}
$content = "{
`"solution`": {
Expand Down Expand Up @@ -138,7 +138,9 @@ foreach($filter in $config.filterConfigs){
Write-Debug "Created $outputPath"
}

# Update solution files from Sentry.sln
$source = Join-Path $repoRoot "Sentry.sln"
$destination = Join-Path $repoRoot "Sentry.NoMobile.sln"
Copy-Item -Path $source -Destination $destination -Force
# Copy the Core solution to each of the required build solutions
$source = Join-Path $repoRoot $config.coreSolution
foreach ($buildSolution in $config.buildSolutions) {
$destination = Join-Path $repoRoot $buildSolution
Copy-Item -Path $source -Destination $destination -Force
}
4 changes: 4 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodeAnalysis.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<PropertyGroup Condition="'$(SolutionName)' == 'Sentry.Aot' and ($(TargetFramework.StartsWith('net6')) or $(TargetFramework.StartsWith('net7')) or $(TargetFramework.StartsWith('net8')))">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

jamescrosswell marked this conversation as resolved.
Show resolved Hide resolved
<PropertyGroup>
<!-- Used by SIL.ReleaseTasks below -->
<ChangelogFile>$(MSBuildThisFileDirectory)..\CHANGELOG.md</ChangelogFile>
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.AspNetCore.Grpc/Sentry.AspNetCore.Grpc.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
<PackageTags>$(PackageTags);AspNetCore;gRPC</PackageTags>
<Description>Official ASP.NET Core gRPC integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.AspNetCore/Sentry.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netstandard2.0</TargetFrameworks>
<PackageTags>$(PackageTags);AspNetCore;MVC</PackageTags>
<Description>Official ASP.NET Core integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netstandard2.0</TargetFrameworks>
<PackageTags>$(PackageTags);Logging;Microsoft.Extensions.Logging</PackageTags>
<Description>Official Microsoft.Extensions.Logging integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
</PropertyGroup>
Expand All @@ -15,9 +15,9 @@
<PackageReference Include="Microsoft.Extensions.Http" Version="2.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.0.0" />
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
6 changes: 3 additions & 3 deletions src/Sentry.OpenTelemetry/SentrySpanProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal SentrySpanProcessor(IHub hub, IEnumerable<IOpenTelemetryEnricher>? enri
// Resource attributes are consistent between spans, but not available during construction.
// Thus, get a single instance lazily.
_resourceAttributes = new Lazy<IDictionary<string, object>>(() =>
ParentProvider?.GetResource().Attributes.ToDictionary() ?? new Dictionary<string, object>(0));
ParentProvider?.GetResource().Attributes.ToDict() ?? new Dictionary<string, object>(0));
}

/// <inheritdoc />
Expand Down Expand Up @@ -111,7 +111,7 @@ public override void OnStart(Activity data)
public override void OnEnd(Activity data)
{
// Make a dictionary of the attributes (aka "tags") for faster lookup when used throughout the processor.
var attributes = data.TagObjects.ToDictionary();
var attributes = data.TagObjects.ToDict();

if (attributes.TryGetTypedValue("http.url", out string? url) && (_options?.IsSentryRequest(url) ?? false))
{
Expand Down Expand Up @@ -325,7 +325,7 @@ private void GenerateSentryErrorsFromOtelSpan(Activity activity, IDictionary<str
// https://opentelemetry.io/docs/specs/otel/trace/semantic_conventions/exceptions/
foreach (var @event in activity.Events.Where(e => e.Name == OtelSemanticConventions.AttributeExceptionEventName))
{
var eventAttributes = @event.Tags.ToDictionary();
var eventAttributes = @event.Tags.ToDict();
// This would be where we would ideally implement full exception capture. That's not possible at the
// moment since the full exception isn't yet available via the OpenTelemetry API.
// See https://github.com/open-telemetry/opentelemetry-dotnet/issues/2439#issuecomment-1577314568
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/GraphQLRequestContent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Sentry.Extensibility;
using Sentry.Internal.Extensions;
using Sentry.Internal.GraphQL;

namespace Sentry;

Expand All @@ -25,8 +26,7 @@ public GraphQLRequestContent(string? requestContent, SentryOptions? options = nu

try
{
var deserialized = JsonSerializer.Deserialize<Dictionary<string, object>>(requestContent, SerializerOptions);
Items = (deserialized ?? new Dictionary<string, object>()).AsReadOnly();
Items = GraphQLRequestContentReader.Read(requestContent);
}
catch (Exception e)
{
Expand Down
11 changes: 10 additions & 1 deletion src/Sentry/Integrations/WinUIUnhandledExceptionIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if NET5_0_OR_GREATER
using Sentry.Extensibility;
using Sentry.Internal;

namespace Sentry.Integrations;

Expand Down Expand Up @@ -35,7 +36,7 @@ internal class WinUIUnhandledExceptionIntegration : ISdkIntegration
private IHub _hub = null!;
private SentryOptions _options = null!;

public static bool IsApplicable => WinUIAssembly != null;
internal static bool IsApplicable => WinUIAssembly != null;

public void Register(IHub hub, SentryOptions options)
{
Expand Down Expand Up @@ -73,6 +74,12 @@ public void Register(IHub hub, SentryOptions options)
});
}

/// <summary>
jamescrosswell marked this conversation as resolved.
Show resolved Hide resolved
/// This method uses reflection to hook up an UnhandledExceptionHandler. When IsTrimmed is true, users will have
/// follow our guidance to perform this initialization manually.
/// </summary>
[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)]
private void AttachEventHandler()
{
try
Expand All @@ -89,6 +96,8 @@ private void AttachEventHandler()
}
catch (Exception ex)
{
// If we get an exception we should let the user know how they can manually wire up the event handler.
// TODO: We need to create a mechanism for users to wire this up manually and document this in a separate PR
_options.LogError(ex, "Could not attach WinUIUnhandledExceptionHandler.");
}
}
Expand Down
28 changes: 28 additions & 0 deletions src/Sentry/Internal/AotHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Sentry.Internal;

internal static class AotHelper
{
internal const string SuppressionJustification = "Non-trimmable code is avoided at runtime";

private class AotTester
{
public void Test() { }
}

internal static bool IsAot { get; }

static AotHelper()
{
try
{
// GetMethod should throw an exception if Trimming is enabled
var type = typeof(AotTester);
_ = type.GetMethod(nameof(AotTester.Test));
}
catch
{
IsAot = true;
}
IsAot = false;
}
}
42 changes: 23 additions & 19 deletions src/Sentry/Internal/DebugStackTrace.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Sentry.Internal.Extensions;
using Sentry.Extensibility;
using Sentry.Internal.ILSpy;
using Sentry.Native;
using Sentry.Internal.ILSpy;

namespace Sentry.Internal;

Expand Down Expand Up @@ -155,20 +155,19 @@ internal void MergeDebugImagesInto(SentryEvent @event)
/// <summary>
/// Creates an enumerator of <see cref="SentryStackFrame"/> from a <see cref="StackTrace"/>.
/// </summary>
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = AotHelper.SuppressionJustification)]
private IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool isCurrentStackTrace)
{
var frames = _options.StackTraceMode switch
{
StackTraceMode.Enhanced => EnhancedStackTrace.GetFrames(stackTrace).Select(p => new RealStackFrame(p)),
_ => stackTrace.GetFrames()
// error CS8619: Nullability of reference types in value of type 'StackFrame?[]' doesn't match target type 'IEnumerable<StackFrame>'.
#if NETCOREAPP3_0
var frames = (!AotHelper.IsAot && _options.StackTraceMode == StackTraceMode.Enhanced)
? EnhancedStackTrace.GetFrames(stackTrace).Select(p => new RealStackFrame(p))
: stackTrace.GetFrames()
// error CS8619: Nullability of reference types in value of type 'StackFrame?[]' doesn't match target type 'IEnumerable<StackFrame>'.
#if NETCOREAPP3_1
.Where(f => f is not null)
.Select(p => new RealStackFrame(p!))
.Select(p => new RealStackFrame(p!));
#else
.Select(p => new RealStackFrame(p))
.Select(p => new RealStackFrame(p));
#endif
};

// Not to throw on code that ignores nullability warnings.
if (frames.IsNull())
Expand Down Expand Up @@ -229,7 +228,7 @@ private IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool i

/// <summary>
/// Native AOT implementation of CreateFrame.
/// Native frames have only limited method information at runtime (and even that can be disabled).
/// Native frames have only limited method information at runtime (and even that can be disabled).
/// We try to parse that and also add addresses for server-side symbolication.
/// </summary>
private SentryStackFrame? TryCreateNativeAOTFrame(IStackFrame stackFrame)
Expand All @@ -255,7 +254,7 @@ private IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool i
}

// Method info is currently only exposed by ToString(), see https://github.com/dotnet/runtime/issues/92869
// We only care about the case where the method is available (`StackTraceSupport` property is the default `true`):
// We only care about the case where the method is available (`StackTraceSupport` property is the default `true`):
// https://github.com/dotnet/runtime/blob/254230253da143a082f47cfaf8711627c0bf2faf/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/DeveloperExperience/DeveloperExperience.cs#L42
internal static SentryStackFrame ParseNativeAOTToString(string info)
{
Expand All @@ -272,6 +271,7 @@ internal static SentryStackFrame ParseNativeAOTToString(string info)
/// <summary>
/// Default the implementation of CreateFrame.
/// </summary>
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = AotHelper.SuppressionJustification)]
private SentryStackFrame? TryCreateManagedFrame(IStackFrame stackFrame)
{
if (stackFrame.GetMethod() is not { } method)
Expand All @@ -286,6 +286,8 @@ internal static SentryStackFrame ParseNativeAOTToString(string info)
Package = method.DeclaringType?.Assembly.FullName
};

frame.Function = method.Name;

if (stackFrame.Frame is EnhancedStackFrame enhancedStackFrame)
{
var stringBuilder = new StringBuilder();
Expand All @@ -305,10 +307,6 @@ internal static SentryStackFrame ParseNativeAOTToString(string info)
: module;
}
}
else
{
frame.Function = method.Name;
}

// Originally we didn't skip methods from dynamic assemblies, so not to break compatibility:
if (_options.StackTraceMode != StackTraceMode.Original && method.Module.Assembly.IsDynamic)
Expand Down Expand Up @@ -336,7 +334,7 @@ internal static SentryStackFrame ParseNativeAOTToString(string info)
{
// method.MetadataToken may throw
// see https://learn.microsoft.com/en-us/dotnet/api/system.reflection.memberinfo.metadatatoken?view=net-6.0
_options.LogDebug("Could not get MetadataToken for stack frame {0} from {1}", frame.Function, method.Module.Name);
_options.LogDebug("Could not get MetadataToken for stack frame {0} from {1}", frame.Function, method.Module.GetNameOrScopeName());
}
}

Expand Down Expand Up @@ -393,8 +391,7 @@ internal static SentryStackFrame ParseNativeAOTToString(string info)
DemangleAnonymousFunction(frame);
DemangleLambdaReturnType(frame);
}

if (stackFrame.Frame is EnhancedStackFrame)
else
{
// In Enhanced mode, Module (which in this case is the Namespace)
// is already prepended to the function, after return type.
Expand Down Expand Up @@ -489,8 +486,15 @@ private static void DemangleLambdaReturnType(SentryStackFrame frame)
}
}

[UnconditionalSuppressMessage("SingleFile", "IL3002:Avoid calling members marked with 'RequiresAssemblyFilesAttribute' when publishing as a single-file", Justification = AotHelper.SuppressionJustification)]
private static PEReader? TryReadAssemblyFromDisk(Module module, SentryOptions options, out string? assemblyName)
{
if (AotHelper.IsAot)
{
assemblyName = null;
return null;
}

assemblyName = module.FullyQualifiedName;
if (options.AssemblyReader is { } reader)
{
Expand Down
Loading
Loading