Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
46 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
4be3abb
Ability to suppress native errors
aritchie Feb 24, 2025
fc85bce
Update CHANGELOG.md
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
b7f28d9
Merge branch '2102-ios_beforesend_oncrashedlastrun' into 3944-ios_nat…
aritchie Feb 26, 2025
9270d50
Add unit tests for suppress segfaults and beforesend
aritchie Feb 26, 2025
941e671
Merge branch 'main' into 3944-ios_native_error_suppression
aritchie Feb 26, 2025
92d38b6
Format code
getsentry-bot Feb 26, 2025
30b3bd3
Update SentrySdkTests.cs
aritchie Feb 26, 2025
8903a56
Merge branch 'main' into 3944-ios_native_error_suppression
aritchie Mar 3, 2025
de9afa5
Update CHANGELOG.md
aritchie Mar 3, 2025
599185f
Update SentrySdkTests.cs
aritchie Mar 4, 2025
3da967a
Updating additional changes requested from code review
aritchie Mar 4, 2025
0f159b7
Test fixes
aritchie Mar 4, 2025
dd37709
Update SentrySdkTests.cs
aritchie Mar 4, 2025
925a632
Merge branch 'main' into 3944-ios_native_error_suppression
aritchie Mar 4, 2025
a4ba982
Update CHANGELOG.md
aritchie Mar 4, 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