File tree Expand file tree Collapse file tree 4 files changed +48
-2
lines changed
src/Sentry/Platforms/Android
test/Sentry.Tests/Platforms/Android Expand file tree Collapse file tree 4 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -25,5 +25,21 @@ public class AndroidOptions
2525 /// </summary>
2626 /// <seealso cref="LogCatIntegration" />
2727 public int LogCatMaxLines { get ; set ; } = 1000 ;
28+
29+ /// <summary>
30+ /// <para>
31+ /// Whether to suppress capturing SIGSEGV (Segfault) errors in the Native SDK.
32+ /// </para>
33+ /// <para>
34+ /// When managed code results in a NullReferenceException, this also causes a SIGSEGV (Segfault). Duplicate
35+ /// events (one managed and one native) can be prevented by suppressing native Segfaults, which may be
36+ /// convenient.
37+ /// </para>
38+ /// <para>
39+ /// Enabling this may prevent the capture of Segfault originating from native (not managed) code... so it may
40+ /// prevent the capture of genuine native Segfault errors.
41+ /// </para>
42+ /// </summary>
43+ public bool SuppressSegfaults { get ; set ; } = false ;
2844 }
2945}
Original file line number Diff line number Diff line change @@ -14,11 +14,13 @@ public class AndroidOptions
1414 {
1515 public LogCatIntegrationType ? LogCatIntegration { get ; set ; }
1616 public int ? LogCatMaxLines { get ; set ; }
17+ public bool ? SuppressSegfaults { get ; set ; }
1718
1819 public void ApplyTo ( SentryOptions . AndroidOptions options )
1920 {
2021 options . LogCatIntegration = LogCatIntegration ?? options . LogCatIntegration ;
2122 options . LogCatMaxLines = LogCatMaxLines ?? options . LogCatMaxLines ;
23+ options . SuppressSegfaults = SuppressSegfaults ?? options . SuppressSegfaults ;
2224 }
2325 }
2426}
Original file line number Diff line number Diff line change @@ -176,7 +176,8 @@ private static void InitSentryAndroidSdk(SentryOptions options)
176176 {
177177 // Suppress SIGSEGV errors.
178178 // See: https://github.com/getsentry/sentry-dotnet/pull/3903
179- if ( evt . SentryExceptions ? . FirstOrDefault ( ) is { Type : "SIGSEGV" , Value : "Segfault" } exception )
179+ if ( options . Android . SuppressSegfaults
180+ && evt . SentryExceptions ? . FirstOrDefault ( ) is { Type : "SIGSEGV" , Value : "Segfault" } )
180181 {
181182 options . LogDebug ( "Suppressing SIGSEGV (this will be thrown as a managed exception instead)" ) ;
182183 return null ;
Original file line number Diff line number Diff line change @@ -4,10 +4,11 @@ namespace Sentry.Tests.Platforms.Android;
44public class SentrySdkTests
55{
66 [ Fact ]
7- public void BeforeSendWrapper_SuppressSIGSEGV_ReturnsNull ( )
7+ public void BeforeSendWrapper_Suppress_SIGSEGV_ReturnsNull ( )
88 {
99 // Arrange
1010 var options = new SentryOptions ( ) ;
11+ options . Android . SuppressSegfaults = true ;
1112 var evt = new SentryEvent
1213 {
1314 SentryExceptions = new [ ]
@@ -28,6 +29,32 @@ public void BeforeSendWrapper_SuppressSIGSEGV_ReturnsNull()
2829 result . Should ( ) . BeNull ( ) ;
2930 }
3031
32+ [ Fact ]
33+ public void BeforeSendWrapper_DontSupress_SIGSEGV_ReturnsEvent ( )
34+ {
35+ // Arrange
36+ var options = new SentryOptions ( ) ;
37+ options . Android . SuppressSegfaults = false ;
38+ var evt = new SentryEvent
39+ {
40+ SentryExceptions = new [ ]
41+ {
42+ new SentryException
43+ {
44+ Type = "SIGSEGV" ,
45+ Value = "Segfault"
46+ }
47+ }
48+ } ;
49+ var hint = new SentryHint ( ) ;
50+
51+ // Act
52+ var result = SentrySdk . BeforeSendWrapper ( options ) . Invoke ( evt , hint ) ;
53+
54+ // Assert
55+ result . Should ( ) . Be ( evt ) ;
56+ }
57+
3158 [ Fact ]
3259 public void BeforeSendWrapper_BeforeSendCallbackDefined_CallsBeforeSend ( )
3360 {
You can’t perform that action at this time.
0 commit comments