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+ #2699

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8f81603
Conditionally include Ben.Demystifier only if IsTrimmable != true
jamescrosswell Oct 5, 2023
8c8615e
Review feedback
jamescrosswell Oct 9, 2023
edb9e38
Removed automatic registration of WinUIUnhandledExceptionIntegration …
jamescrosswell Oct 9, 2023
48c3f0a
Merge branch 'feat/4.0.0' into feat/4.0.0-sentry-trimmable
jamescrosswell Oct 9, 2023
5d2a51b
Merged DebugStackTrace from feat/4.0.0
jamescrosswell Oct 10, 2023
9ccc529
Checkpoint
jamescrosswell Oct 10, 2023
dcb7441
Compiles (serialization verify tests still fail)
jamescrosswell Oct 10, 2023
4f6644c
Added some tests for JsonText source generated serializers
jamescrosswell Oct 11, 2023
5479f1e
Added SentryOptions.AddJsonSerializerContext
jamescrosswell Oct 11, 2023
98a51c7
Update SerializationTests.verify.cs
jamescrosswell Oct 11, 2023
dc2c522
Update DebugStackTrace.cs
jamescrosswell Oct 11, 2023
a216116
Fixed JsonSerializerContext with CustomConverters
jamescrosswell Oct 11, 2023
3b24c7b
Update ContextsTests.cs
jamescrosswell Oct 11, 2023
ae56436
Update JsonExtensions.cs
jamescrosswell Oct 11, 2023
bfb0818
Added support for a SentryJsonContext as well as a user defined JsonS…
jamescrosswell Oct 11, 2023
7322b6a
Fixed almost all of the JsonTests
jamescrosswell Oct 11, 2023
bb41fbb
Resolved deserialization issues for GraphQLRequestContent
jamescrosswell Oct 12, 2023
c37926c
Fixed MS Build issues
jamescrosswell Oct 12, 2023
29818c7
Update SentryClientTests.CaptureEvent_BeforeEventThrows_ErrorToEventB…
jamescrosswell Oct 12, 2023
adabd5d
Fixed CapturesEventWithContextKey_Implementation test
jamescrosswell Oct 12, 2023
89684a2
Update JsonExtensions.cs
jamescrosswell Oct 12, 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
10 changes: 8 additions & 2 deletions src/Sentry/Internal/DebugStackTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ internal void MergeDebugImagesInto(SentryEvent @event)
/// </summary>
private IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool isCurrentStackTrace)
{
#if !IsTrimmable
var frames = _options.StackTraceMode switch
{
StackTraceMode.Enhanced => EnhancedStackTrace.GetFrames(stackTrace).Select(p => p as StackFrame),
Expand All @@ -130,7 +131,9 @@ private IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool i
.Where(f => f is not null)
#endif
};

#else
StackFrame[]? frames = null;
#endif
// Not to throw on code that ignores nullability warnings.
if (frames.IsNull())
{
Expand Down Expand Up @@ -185,7 +188,7 @@ private SentryStackFrame InternalCreateFrame(StackFrame stackFrame, bool demangl
{
frame.Module = method.DeclaringType?.FullName ?? unknownRequiredField;
frame.Package = method.DeclaringType?.Assembly.FullName;

#if !IsTrimmable
if (_options.StackTraceMode == StackTraceMode.Enhanced &&
stackFrame is EnhancedStackFrame enhancedStackFrame)
{
Expand All @@ -210,6 +213,9 @@ private SentryStackFrame InternalCreateFrame(StackFrame stackFrame, bool demangl
{
frame.Function = method.Name;
}
#else
frame.Function = method.Name;
#endif

// 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
32 changes: 18 additions & 14 deletions src/Sentry/Sentry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<NoWarn Condition="'$(TargetFramework)' == 'netstandard2.0'">$(NoWarn);RS0017</NoWarn>
<CLSCompliant Condition="'$(TargetPlatformIdentifier)' == ''">true</CLSCompliant>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsTrimmable>true</IsTrimmable>
<DefineConstants>$(DefineConstants);IsTrimmable</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(SolutionName)' != 'Sentry.Unity'">
Expand All @@ -22,21 +24,23 @@
<Import Project="Platforms\Android\Sentry.Android.props" Condition="'$(TargetPlatformIdentifier)' == 'android'" />
<Import Project="Platforms\iOS\Sentry.iOS.props" Condition="'$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst'" />

<!--
Ben.Demystifier is compiled directly into Sentry.
Note: It uses Microsoft.Bcl.AsyncInterfaces, which we get transitively from System.Text.Json.
-->
<ItemGroup>
<Compile Include="..\..\modules\Ben.Demystifier\src\**\*.cs">
<Link>%(RecursiveDir)\%(Filename)%(Extension)</Link>
</Compile>
<Compile Remove="..\..\modules\Ben.Demystifier\**\obj\**" />
</ItemGroup>
<Target Name="IncludeBenDemystifier" Condition="'$(IsTrimmable)' != 'true'">
<!--
Ben.Demystifier is compiled directly into Sentry.
Note: It uses Microsoft.Bcl.AsyncInterfaces, which we get transitively from System.Text.Json.
-->
<ItemGroup>
<Compile Include="..\..\modules\Ben.Demystifier\src\**\*.cs">
<Link>%(RecursiveDir)\%(Filename)%(Extension)</Link>
</Compile>
<Compile Remove="..\..\modules\Ben.Demystifier\**\obj\**" />
</ItemGroup>

<!-- Ben.Demystifier also needs System.Reflection.Metadata 5.0.0 or higher on all platforms. -->
<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard')) or $(TargetFramework.StartsWith('net4')) or $(TargetFramework.StartsWith('netcoreapp'))">
<PackageReference Include="System.Reflection.Metadata" Version="5.0.0" />
</ItemGroup>
<!-- Ben.Demystifier also needs System.Reflection.Metadata 5.0.0 or higher on all platforms. -->
<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard')) or $(TargetFramework.StartsWith('net4')) or $(TargetFramework.StartsWith('netcoreapp'))">
<PackageReference Include="System.Reflection.Metadata" Version="5.0.0" />
</ItemGroup>
</Target>

<!-- Sentry.DiagnosticSource is compiled directly into Sentry for .NET Core and .NET targets only. -->
<PropertyGroup Condition="!$(TargetFramework.StartsWith('netstandard')) and !$(TargetFramework.StartsWith('net4'))">
Expand Down
4 changes: 4 additions & 0 deletions src/Sentry/SentryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ public void CaptureTransaction(Transaction transaction, Hint? hint)
}
catch (Exception e)
{
#if !IsTrimmable
// Attempt to demystify exceptions before adding them as breadcrumbs.
e.Demystify();
#endif

_options.LogError("The BeforeSendTransaction callback threw an exception. It will be added as breadcrumb and continue.", e);

Expand Down Expand Up @@ -369,8 +371,10 @@ private bool CaptureEnvelope(Envelope envelope)
}
catch (Exception e)
{
#if !IsTrimmable
// Attempt to demystify exceptions before adding them as breadcrumbs.
e.Demystify();
#endif

_options.LogError("The BeforeSend callback threw an exception. It will be added as breadcrumb and continue.", e);
var data = new Dictionary<string, string>
Expand Down