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

fix: Android - make sure logcat.log is attached to unhandled event (SIGSEGV Segfault) #3694

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2efc4bb
Sentry SDK - Android Bindings | upgrade the JavaSDK to 7.15.0-alpha.1
bricefriha Oct 17, 2024
1c12ffa
#1027 - Sentry Android | implement NDKhandlerStrategy
bricefriha Oct 17, 2024
7cc7951
Android Bindings - NDKHandler | fix enum conversion
bricefriha Oct 17, 2024
455c1d8
NdkHandlerStrategy | fix a oopsi : some code I removed by mistake
bricefriha Oct 17, 2024
2160ab6
unit test - MAUI | handler strategy
bricefriha Oct 18, 2024
6d0dc19
Change logs - handler strategy
bricefriha Oct 18, 2024
bfdf2f1
Update CHANGELOG.md
bricefriha Oct 18, 2024
f59d990
Unit tests - Maui | indentation
bricefriha Oct 18, 2024
a9c9f88
Update src/Sentry/Platforms/Android/SentrySdk.cs
bricefriha Oct 19, 2024
46f2d26
Android - Handler Strategy | add ToJava() extension
bricefriha Oct 19, 2024
8699f7a
Android - Handler Strategy | simplify the `HandlerStrategy` property …
bricefriha Oct 19, 2024
bc74c42
Android bindings - `7.15.0-alpha.1` config | clean up the auto indent…
bricefriha Oct 19, 2024
c4d75ce
Android - Handler Strategy | Values() can't ever be null
bricefriha Oct 19, 2024
d711700
Sentry.Bindings.Android - config | restore file
bricefriha Oct 19, 2024
72eb9ff
Android - Handler Strategy Android/SentrySdk.cs | Restore `SentryAndr…
bricefriha Oct 19, 2024
e9ca2d8
Android - Handler Strategy Android/SentrySdk.cs | remove useless cast
bricefriha Oct 19, 2024
80221e9
Android - Handler Strategy | move NdkHandlerStrategy.cs to the Androi…
bricefriha Oct 19, 2024
d29c2b8
Android - Handler Strategy | document HandlerStrategy better
bricefriha Oct 19, 2024
57aeb47
Android - binding config | restore to edd0be4
bricefriha Oct 19, 2024
03da282
Android - Handler Strategy | HandlerStrategy improve documentation
bricefriha Oct 19, 2024
f803f9b
cleanup - Android Bindings - NdkHandlerStrategy.cs | opt for a File-s…
bricefriha Oct 21, 2024
0141fe6
Android - NDK handler | set default handler to SENTRY_HANDLER_STRATEG…
bricefriha Oct 21, 2024
62816a6
Unit tests - MAUI Android - NDK handler | remove them - as the user d…
bricefriha Oct 21, 2024
4b24ba6
Merge branch 'main' into fix/#3461
jamescrosswell Oct 21, 2024
e977797
Bindings Android - | change version to 7.15.0-alpha.1 to make CI happy
bricefriha Oct 23, 2024
a2f8368
Device Tests - MAUI android logcats | create tests for the most commo…
bricefriha Oct 23, 2024
164e096
Device tests - logcats attchment + fix CI | remove global android ref…
bricefriha Oct 23, 2024
185172a
Device tests - logcat | fix CI: encapsulate Android `options.Android.…
bricefriha Oct 23, 2024
8c6eaae
Device Test - MAUI Logcats | Remove Android block
bricefriha Oct 24, 2024
28f16f0
Device Test - MAUI Logcats | Test unhandled exceptions
bricefriha Oct 24, 2024
03c23c4
Device Test - MAUI Logcats | Test handled exceptions
bricefriha Oct 24, 2024
7870b79
Device Test - MAUI Logcats | restore android blocks to prevent the CI…
bricefriha Oct 24, 2024
7023620
Unit tests - Android LogCatIntegration options | test HandlerStrategy…
bricefriha Oct 24, 2024
cc574d5
Merge branch 'main' into fix/#3461
bricefriha Oct 24, 2024
abfa306
Unit tests - Android LogCatIntegration | fix `#if Android` block
bricefriha Oct 24, 2024
068983e
Update CHANGELOG.md
bricefriha Oct 30, 2024
3b97c61
Update CHANGELOG.md entry
bricefriha Oct 30, 2024
ed094f9
Merge branch 'main' into fix/#3461
bricefriha Nov 4, 2024
cff630b
Format code
getsentry-bot Nov 4, 2024
151f967
Device tests - SentryMauiLogcatsTests | fix syntax issue after merge
bricefriha Nov 4, 2024
42e4ab3
merge SentryMauiLogcatsTests
bricefriha Nov 4, 2024
eac7596
CHANGELOG.md | switch the #3694 entry back to unreleased
bricefriha Nov 4, 2024
d9516bf
Merge branch 'main' into fix/#3461
jamescrosswell Nov 14, 2024
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

### Fixes

- Android: Fix for SIGSEGV reported by Sentry when a NullReferenceException is thrown in Release mode ([#3694](https://github.com/getsentry/sentry-dotnet/pull/3694))
bricefriha marked this conversation as resolved.
Show resolved Hide resolved
- To turn it on, set: `options.HandlerStrategy = NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_CHAIN_AT_START;`
bricefriha marked this conversation as resolved.
Show resolved Hide resolved

## 4.12.1

### Fixes
Expand Down
6 changes: 3 additions & 3 deletions src/Sentry.Bindings.Android/Sentry.Bindings.Android.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
bricefriha marked this conversation as resolved.
Show resolved Hide resolved
<PropertyGroup>
<TargetFramework>net7.0-android</TargetFramework>
<!-- BG8605 and BG8606 happen because there's a missing androidx.lifecycle dependency, but we don't need it here. (The native Android Sentry SDK will use it if it exists.) -->
<NoWarn>$(NoWarn);BG8605;BG8606</NoWarn>
<SentryAndroidSdkVersion>7.14.0</SentryAndroidSdkVersion>
<SentryAndroidSdkVersion>7.15.0-alpha.1</SentryAndroidSdkVersion>
bricefriha marked this conversation as resolved.
Show resolved Hide resolved
bruno-garcia marked this conversation as resolved.
Show resolved Hide resolved
<SentryAndroidSdkDirectory>$(BaseIntermediateOutputPath)sdks\Sentry\Android\$(SentryAndroidSdkVersion)\</SentryAndroidSdkDirectory>
<Description>.NET Bindings for the Sentry Android SDK</Description>
</PropertyGroup>
Expand Down Expand Up @@ -57,4 +57,4 @@
/>
</Target>

</Project>
</Project>
bricefriha marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 32 additions & 0 deletions src/Sentry/NdkHandlerStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Sentry
{
/// <summary>
/// Handler strategy
/// </summary>
///
public enum NdkHandlerStrategy
bricefriha marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// default handler strategy -> value 0
/// </summary>
SENTRY_HANDLER_STRATEGY_DEFAULT,
/// <summary>
/// Handle strategy chain at start -> value 1
/// </summary>
SENTRY_HANDLER_STRATEGY_CHAIN_AT_START,


}
/// <summary>
/// Extension class of strategy containing relevant its actions
/// </summary>
public static class HandlerStrategyExtension
{
#if ANDROID
bricefriha marked this conversation as resolved.
Show resolved Hide resolved
internal static JavaSdk.Android.Core.NdkHandlerStrategy ToJava(this NdkHandlerStrategy strategy)
{
return JavaSdk.Android.Core.NdkHandlerStrategy.Values()?[(int)strategy] ?? JavaSdk.Android.Core.NdkHandlerStrategy.SentryHandlerStrategyDefault;
}
#endif
}
}
8 changes: 6 additions & 2 deletions src/Sentry/Platforms/Android/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ private static void InitSentryAndroidSdk(SentryOptions options)

// Define the configuration for the Android SDK
SentryAndroidOptions? nativeOptions = null;

var handlerStrategy = options.HandlerStrategy.ToJava();

var configuration = new OptionsConfigurationCallback(o =>
{
// Capture the android options reference on the outer scope
Expand Down Expand Up @@ -87,6 +90,7 @@ private static void InitSentryAndroidSdk(SentryOptions options)
o.ServerName = options.ServerName;
o.SessionTrackingIntervalMillis = (long)options.AutoSessionTrackingInterval.TotalMilliseconds;
o.ShutdownTimeoutMillis = (long)options.ShutdownTimeout.TotalMilliseconds;
o.SetNativeHandlerStrategy(handlerStrategy ?? JavaSdk.Android.Core.NdkHandlerStrategy.SentryHandlerStrategyDefault);
bricefriha marked this conversation as resolved.
Show resolved Hide resolved

if (options.CacheDirectoryPath is { } cacheDirectoryPath)
{
Expand Down Expand Up @@ -185,11 +189,11 @@ private static void InitSentryAndroidSdk(SentryOptions options)
}
else
{
SentryAndroid.Init(AppContext, configuration);
SentryAndroid.Init(AppContext);
bricefriha marked this conversation as resolved.
Show resolved Hide resolved
}

// Set options for the managed SDK that depend on the Android SDK. (The user will not be able to modify these.)
options.AddEventProcessor(new AndroidEventProcessor(nativeOptions!));
options.AddEventProcessor(new AndroidEventProcessor((SentryAndroidOptions)nativeOptions!));
bricefriha marked this conversation as resolved.
Show resolved Hide resolved
if (options.Android.LogCatIntegration != LogCatIntegrationType.None)
{
options.AddEventProcessor(new LogCatAttachmentEventProcessor(options.DiagnosticLogger, options.Android.LogCatIntegration, options.Android.LogCatMaxLines));
Expand Down
4 changes: 4 additions & 0 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public bool IsGlobalModeEnabled
set => _isGlobalModeEnabled = value;
}
#endif
/// <summary>
/// Handler Strategy
bricefriha marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public NdkHandlerStrategy HandlerStrategy { get; set; } = NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_DEFAULT;
bricefriha marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// A scope set outside of Sentry SDK. If set, the global parameters from the SDK's scope will be sent to the observed scope.<br/>
Expand Down
27 changes: 27 additions & 0 deletions test/Sentry.Maui.Tests/SentryMauiOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,31 @@ public void AttachScreenshots_Default()
var options = new SentryMauiOptions();
Assert.False(options.AttachScreenshot);
}

[Fact]
bricefriha marked this conversation as resolved.
Show resolved Hide resolved
public void HandlerStrategy_Default()
{
// Arrange
var options = new SentryMauiOptions();
var expected = NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_DEFAULT;

// Assert
// testing default state here so nothing to assert

// Act
Assert.Equal(expected, options.HandlerStrategy);
}
[Fact]
public void HandlerStrategy_set()
bricefriha marked this conversation as resolved.
Show resolved Hide resolved
{
// Arrange
var options = new SentryMauiOptions();
var notExpected = NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_DEFAULT;

// Assert
options.HandlerStrategy = NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_CHAIN_AT_START;

// Act
Assert.NotEqual(notExpected, options.HandlerStrategy);
}
}