Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a1b0cb6
Initial commit for exposing iOS native before send & crashed last run
aritchie Feb 11, 2025
1a8474e
Initial feature set is working
aritchie Feb 11, 2025
c36be94
Format code
getsentry-bot Feb 11, 2025
cd074d4
Update CHANGELOG.md
aritchie Feb 11, 2025
17790c7
Merge branch '2102-ios_beforesend_oncrashedlastrun' of https://github…
aritchie Feb 11, 2025
70a677d
Merge signal abort code before user based BeforeSend
aritchie Feb 12, 2025
4a6462c
Move native BeforeSend & OnCrashedLastRun events to SentryOptions - O…
aritchie Feb 14, 2025
91145ab
Always run NativeOptions.BeforeSend so sig aborts can be filtered
aritchie Feb 14, 2025
fd48026
Update SentrySdk.cs
aritchie Feb 14, 2025
1b3dfdd
Merge branch 'main' into 2102-ios_beforesend_oncrashedlastrun
aritchie Feb 18, 2025
c29a785
Update CHANGELOG.md
aritchie Feb 18, 2025
50a5554
Format code
getsentry-bot Feb 18, 2025
63e3f55
WIP - removing serialization mechanics as they cause a native crash d…
aritchie Feb 18, 2025
5c06eb5
Transferring transformed sentryevent back to original native event in…
aritchie Feb 21, 2025
18a1079
Merge branch 'main' into 2102-ios_beforesend_oncrashedlastrun
aritchie Feb 21, 2025
000b324
Remove unnecessary hacks
aritchie Feb 21, 2025
bdfe3a9
Format code
getsentry-bot Feb 21, 2025
bf4d33d
Add missing bindable option for native iOS sentryoptions
aritchie Feb 21, 2025
52f0699
Update SentrySdk.cs
aritchie Feb 24, 2025
dab118e
Update SentrySdk.cs
aritchie Feb 24, 2025
1f721b8
Update CHANGELOG.md
aritchie Feb 24, 2025
4830f8e
Update CHANGELOG.md
aritchie Feb 24, 2025
b8b08cc
Unit tests mapping checks to/from native iOS
aritchie Feb 24, 2025
a46bd43
Format code
getsentry-bot Feb 24, 2025
5dca9e2
Update NativeSerializationTests.cs
aritchie Feb 24, 2025
00cbc04
Revert "Add missing bindable option for native iOS sentryoptions"
aritchie Feb 24, 2025
d2776e1
Remove iOS native event suppress configuration
aritchie Feb 24, 2025
5e8134a
Update CHANGELOG.md
aritchie Feb 24, 2025
d8ac6ea
Rename tests according to review
aritchie Feb 25, 2025
63326ec
add timestamp for deserialize test
aritchie Feb 25, 2025
d1feffc
Account for fractions of seconds
aritchie Feb 26, 2025
6c10867
Merge branch 'main' into 2102-ios_beforesend_oncrashedlastrun
aritchie Feb 26, 2025
ede88c1
Platforms should not change
aritchie Feb 26, 2025
bbf9da4
Update CocoaExtensionsTests.cs
aritchie Feb 26, 2025
65534f0
Update CocoaExtensionsTests.cs
aritchie Feb 26, 2025
35113e1
Update CocoaExtensionsTests.cs
aritchie Feb 26, 2025
4c6d7a2
Update CocoaExtensionsTests.cs
aritchie Feb 26, 2025
e80ce73
Safety SentryLevel in both directions
aritchie Mar 3, 2025
e97bc47
Update EnumExtensions.cs
aritchie Mar 3, 2025
61665c5
Format code
getsentry-bot Mar 3, 2025
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
Prev Previous commit
Next Next commit
Merge signal abort code before user based BeforeSend
  • Loading branch information
aritchie committed Feb 12, 2025
commit 70a677da85dcd18b61933c27a09fe491f78a1630
71 changes: 34 additions & 37 deletions src/Sentry/Platforms/Cocoa/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,39 @@ private static void InitSentryCocoaSdk(SentryOptions options)
{
nativeOptions.BeforeSend = evt =>
{
// When we have an unhandled managed exception, we send that to Sentry twice - once managed and once native.
// The managed exception is what a .NET developer would expect, and it is sent by the Sentry.NET SDK
// But we also get a native SIGABRT since it crashed the application, which is sent by the Sentry Cocoa SDK.

// There should only be one exception on the event in this case
if (evt.Exceptions?.Length == 1)
{
// It will match the following characteristics
var ex = evt.Exceptions[0];

// Thankfully, sometimes we can see Xamarin's unhandled exception handler on the stack trace, so we can filter
// them out. Here is the function that calls abort(), which we will use as a filter:
// https://github.com/xamarin/xamarin-macios/blob/c55fbdfef95028ba03d0f7a35aebca03bd76f852/runtime/runtime.m#L1114-L1122
if (ex.Type == "SIGABRT" && ex.Value == "Signal 6, Code 0" &&
ex.Stacktrace?.Frames.Any(f => f.Function == "xamarin_unhandled_exception_handler") is true)
{
// Don't send it
options.LogDebug("Discarded {0} error ({1}). Captured as managed exception instead.", ex.Type, ex.Value);
return null!;
}

// Similar workaround for NullReferenceExceptions. We don't have any easy way to know whether the
// exception is managed code (compiled to native) or original native code though.
// See: https://github.com/getsentry/sentry-dotnet/issues/3776
if (ex.Type == "EXC_BAD_ACCESS")
{
// Don't send it
options.LogDebug("Discarded {0} error ({1}). Captured as managed exception instead.", ex.Type, ex.Value);
return null!;
}
}

// we run our SIGABRT checks first before handing over to user events
// because we delegate to user code, we need to protect anything that could happen in this event
try
{
Expand All @@ -115,6 +148,7 @@ private static void InitSentryCocoaSdk(SentryOptions options)
{
nativeOptions.OnCrashedLastRun = evt =>
{

// because we delegate to user code, we need to protect anything that could happen in this event
try
{
Expand Down Expand Up @@ -163,43 +197,6 @@ private static void InitSentryCocoaSdk(SentryOptions options)
// nativeOptions.DefaultIntegrations
// nativeOptions.EnableProfiling (deprecated)

// When we have an unhandled managed exception, we send that to Sentry twice - once managed and once native.
// The managed exception is what a .NET developer would expect, and it is sent by the Sentry.NET SDK
// But we also get a native SIGABRT since it crashed the application, which is sent by the Sentry Cocoa SDK.
nativeOptions.BeforeSend = evt =>
{
// There should only be one exception on the event in this case
if (evt.Exceptions?.Length == 1)
{
// It will match the following characteristics
var ex = evt.Exceptions[0];

// Thankfully, sometimes we can see Xamarin's unhandled exception handler on the stack trace, so we can filter
// them out. Here is the function that calls abort(), which we will use as a filter:
// https://github.com/xamarin/xamarin-macios/blob/c55fbdfef95028ba03d0f7a35aebca03bd76f852/runtime/runtime.m#L1114-L1122
if (ex.Type == "SIGABRT" && ex.Value == "Signal 6, Code 0" &&
ex.Stacktrace?.Frames.Any(f => f.Function == "xamarin_unhandled_exception_handler") is true)
{
// Don't send it
options.LogDebug("Discarded {0} error ({1}). Captured as managed exception instead.", ex.Type, ex.Value);
return null!;
}

// Similar workaround for NullReferenceExceptions. We don't have any easy way to know whether the
// exception is managed code (compiled to native) or original native code though.
// See: https://github.com/getsentry/sentry-dotnet/issues/3776
if (ex.Type == "EXC_BAD_ACCESS")
{
// Don't send it
options.LogDebug("Discarded {0} error ({1}). Captured as managed exception instead.", ex.Type, ex.Value);
return null!;
}
}

// Other event, send as normal
return evt;
};

// Set hybrid SDK name
SentryCocoaHybridSdk.SetSdkName("sentry.cocoa.dotnet");

Expand Down