Skip to content

Commit 4486918

Browse files
committed
feat: allow configuring native signal handler strategy on Android
1 parent 356f8e9 commit 4486918

File tree

6 files changed

+40
-8
lines changed

6 files changed

+40
-8
lines changed

integration-test/android.Tests.ps1

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,8 @@ Describe 'MAUI app (<tfm>, <configuration>)' -ForEach @(
169169
Dump-ServerErrors -Result $result
170170
$result.HasErrors() | Should -BeFalse
171171
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.NullReferenceException`""
172-
# TODO: fix redundant SIGSEGV in Release (#3954)
173-
if ($configuration -eq "Release") {
174-
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`"" } | Should -Throw
175-
} else {
176-
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`""
177-
$result.Envelopes() | Should -HaveCount 1
178-
}
172+
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`""
173+
$result.Envelopes() | Should -HaveCount 1
179174
}
180175

181176
It 'Delivers battery breadcrumbs in main thread (<configuration>)' {

integration-test/net9-maui/MauiProgram.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static MauiApp CreateMauiApp()
1414
{
1515
#if ANDROID
1616
options.Dsn = "{{SENTRY_DSN}}";
17+
options.Native.SignalHandlerStrategy = Sentry.Android.SignalHandlerStrategy.ChainAtStart;
1718
#endif
1819
options.Debug = false;
1920
options.DiagnosticLevel = SentryLevel.Error;

src/Sentry/Platforms/Android/BindableNativeSentryOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Sentry.Android;
2+
13
// ReSharper disable once CheckNamespace
24
namespace Sentry;
35

@@ -24,6 +26,7 @@ public class NativeOptions
2426
public bool? EnableAutoActivityLifecycleTracing { get; set; }
2527
public bool? EnableActivityLifecycleTracingAutoFinish { get; set; }
2628
public bool? EnableUserInteractionTracing { get; set; }
29+
public SignalHandlerStrategy? SignalHandlerStrategy { get; set; }
2730
public bool? AttachThreads { get; set; }
2831
public TimeSpan? ConnectionTimeout { get; set; }
2932
public bool? EnableNdk { get; set; }
@@ -66,6 +69,7 @@ public void ApplyTo(SentryOptions.NativeOptions options)
6669
options.EnableAutoActivityLifecycleTracing = EnableAutoActivityLifecycleTracing ?? options.EnableAutoActivityLifecycleTracing;
6770
options.EnableActivityLifecycleTracingAutoFinish = EnableActivityLifecycleTracingAutoFinish ?? options.EnableActivityLifecycleTracingAutoFinish;
6871
options.EnableUserInteractionTracing = EnableUserInteractionTracing ?? options.EnableUserInteractionTracing;
72+
options.SignalHandlerStrategy = SignalHandlerStrategy ?? options.SignalHandlerStrategy;
6973
options.AttachThreads = AttachThreads ?? options.AttachThreads;
7074
options.ConnectionTimeout = ConnectionTimeout ?? options.ConnectionTimeout;
7175
options.EnableNdk = EnableNdk ?? options.EnableNdk;

src/Sentry/Platforms/Android/NativeOptions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Sentry.Android;
2+
13
// ReSharper disable once CheckNamespace
24
namespace Sentry;
35

@@ -152,6 +154,13 @@ internal NativeOptions(SentryOptions options)
152154
/// </remarks>
153155
public bool EnableUserInteractionTracing { get; set; } = false;
154156

157+
/// <summary>
158+
/// Gets or sets the strategy for how Sentry Native's signal handler interacts with the CLR/Mono
159+
/// signal handler.
160+
/// The default value is <c>SignalHandlerStrategy.Default</c> (enabled).
161+
/// </summary>
162+
public SignalHandlerStrategy SignalHandlerStrategy { get; set; } = SignalHandlerStrategy.Default;
163+
155164
// ---------- From SentryOptions.java ----------
156165

157166
/// <summary>

src/Sentry/Platforms/Android/SentrySdk.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ private static void InitSentryAndroidSdk(SentryOptions options)
6464
o.ServerName = options.ServerName;
6565
o.SessionTrackingIntervalMillis = (long)options.AutoSessionTrackingInterval.TotalMilliseconds;
6666
o.ShutdownTimeoutMillis = (long)options.ShutdownTimeout.TotalMilliseconds;
67-
o.SetNativeHandlerStrategy(JavaSdk.Android.Core.NdkHandlerStrategy.SentryHandlerStrategyDefault);
67+
o.SetNativeHandlerStrategy(options.Native.SignalHandlerStrategy switch
68+
{
69+
SignalHandlerStrategy.ChainAtStart => NdkHandlerStrategy.SentryHandlerStrategyChainAtStart,
70+
_ => NdkHandlerStrategy.SentryHandlerStrategyDefault
71+
});
6872

6973
if (options.CacheDirectoryPath is { } cacheDirectoryPath)
7074
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Sentry.Android;
2+
3+
/// <summary>
4+
/// Defines how Sentry Native's signal handler interacts with the CLR/Mono
5+
/// signal handler.
6+
/// </summary>
7+
public enum SignalHandlerStrategy
8+
{
9+
/// <summary>
10+
/// Invokes the CLR/Mono signal handler at the end of Sentry Native's signal
11+
/// handler.
12+
/// </summary>
13+
Default,
14+
/// <summary>
15+
/// Invokes the CLR/Mono signal handler at the start of Sentry Native's
16+
/// signal handler.
17+
/// </summary>
18+
ChainAtStart
19+
}

0 commit comments

Comments
 (0)