Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- Reintroduced experimental support for Session Replay on Android ([#4097](https://github.com/getsentry/sentry-dotnet/pull/4097))

### Fixes

- Prevent users from disabling AndroidEnableAssemblyCompression which leads to untrappable crash ([#4089](https://github.com/getsentry/sentry-dotnet/pull/4089))
Expand Down
6 changes: 6 additions & 0 deletions samples/Sentry.Samples.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ protected override void OnCreate(Bundle? savedInstanceState)
// Enable Native Android SDK ANR detection
options.Native.AnrEnabled = true;

// Currently experimental support is only available on Android
options.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate = 1.0;
options.Native.ExperimentalOptions.SessionReplay.SessionSampleRate = 1.0;
options.Native.ExperimentalOptions.SessionReplay.MaskAllImages = false;
options.Native.ExperimentalOptions.SessionReplay.MaskAllText = false;

options.SetBeforeSend(evt =>
{
if (evt.Exception?.Message.Contains("Something you don't care want logged?") ?? false)
Expand Down
8 changes: 8 additions & 0 deletions samples/Sentry.Samples.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public static MauiApp CreateMauiApp()
options.Debug = true;
options.SampleRate = 1.0F;

#if ANDROID
// Currently experimental support is only available on Android
options.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate = 1.0;
options.Native.ExperimentalOptions.SessionReplay.SessionSampleRate = 1.0;
options.Native.ExperimentalOptions.SessionReplay.MaskAllImages = false;
options.Native.ExperimentalOptions.SessionReplay.MaskAllText = false;
#endif

options.SetBeforeScreenshotCapture((@event, hint) =>
{
Console.WriteLine("screenshot about to be captured.");
Expand Down
12 changes: 12 additions & 0 deletions src/Sentry.Bindings.Android/Sentry.Bindings.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Common.Java8" Version="2.6.1.3" />
<!-- MAUI 8 references this version indirectly via Xamarin.AndroidX.SwipeRefreshLayout (>= 1.1.0.14) -->
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.10.1.2" />
<!-- We need 1.9.24 but there's no NuGet package for that version... the lowest version we can use is 2.0.0 -->
<PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8" Version="2.0.0" />
</ItemGroup>

<!-- Dependencies for AndroidMavenLibrary references
Expand All @@ -49,12 +51,15 @@
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Common.Java8" Version="2.8.5.1" />
<!-- MAUI 9 references this version indirectly via Xamarin.AndroidX.SwipeRefreshLayout (>= 1.1.0.24) -->
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.13.1.5" />
<!-- We need 1.9.24 but there's no NuGet package for that version... the lowest version we can use is 2.0.0 -->
<PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8" Version="2.0.0" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net8'))">
<AndroidLibrary Include="$(SentryAndroidSdkDirectory)sentry-$(SentryAndroidSdkVersion).jar" />
<AndroidLibrary Include="$(SentryAndroidSdkDirectory)sentry-android-core-$(SentryAndroidSdkVersion).aar" />
<AndroidLibrary Include="$(SentryAndroidSdkDirectory)sentry-android-ndk-$(SentryAndroidSdkVersion).aar" />
<AndroidLibrary Include="$(SentryAndroidSdkDirectory)sentry-android-replay-$(SentryAndroidSdkVersion).aar" />
</ItemGroup>

<!-- Starting with .NET 9 we can detect Java dependencies using POM files and AndroidMavenLibrary references -->
Expand All @@ -66,6 +71,7 @@
/>
<AndroidMavenLibrary Include="io.sentry:sentry-android-core" Version="$(SentryAndroidSdkVersion)" />
<AndroidMavenLibrary Include="io.sentry:sentry-android-ndk" Version="$(SentryAndroidSdkVersion)" />
<AndroidMavenLibrary Include="io.sentry:sentry-android-replay" Version="$(SentryAndroidSdkVersion)" />
</ItemGroup>

<ItemGroup>
Expand All @@ -89,6 +95,12 @@
Condition="!Exists('$(SentryAndroidSdkDirectory)sentry-android-ndk-$(SentryAndroidSdkVersion).aar') And $(TargetFramework.StartsWith('net8'))"
Retries="3"
/>
<DownloadFile
SourceUrl="https://repo1.maven.org/maven2/io/sentry/sentry-android-replay/$(SentryAndroidSdkVersion)/sentry-android-replay-$(SentryAndroidSdkVersion).aar"
DestinationFolder="$(SentryAndroidSdkDirectory)"
Condition="!Exists('$(SentryAndroidSdkDirectory)sentry-android-replay-$(SentryAndroidSdkVersion).aar') And $(TargetFramework.StartsWith('net8'))"
Retries="3"
/>
<DownloadFile
SourceUrl="https://repo1.maven.org/maven2/io/sentry/sentry/$(SentryAndroidSdkVersion)/sentry-$(SentryAndroidSdkVersion).jar"
DestinationFolder="$(SentryAndroidSdkDirectory)"
Expand Down
30 changes: 30 additions & 0 deletions src/Sentry/Platforms/Android/BindableNativeSentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ public class NativeOptions
public bool? EnableTracing { get; set; }
public bool? EnableBeforeSend { get; set; }

public NativeExperimentalOptions ExperimentalOptions { get; set; } = new();

internal class NativeExperimentalOptions
{
public NativeSentryReplayOptions SessionReplay { get; set; } = new();
}

internal class NativeSentryReplayOptions
{
public double? OnErrorSampleRate { get; set; }
public double? SessionSampleRate { get; set; }
public bool RedactAllImages { get; set; }
public bool RedactAllText { get; set; }
}

public void ApplyTo(SentryOptions.NativeOptions options)
{
options.AnrEnabled = AnrEnabled ?? options.AnrEnabled;
Expand All @@ -61,6 +76,21 @@ public void ApplyTo(SentryOptions.NativeOptions options)
options.ReadTimeout = ReadTimeout ?? options.ReadTimeout;
options.EnableTracing = EnableTracing ?? options.EnableTracing;
options.EnableBeforeSend = EnableBeforeSend ?? options.EnableBeforeSend;

if (ExperimentalOptions.SessionReplay.OnErrorSampleRate is { } errorSampleRate)
{
#pragma warning disable CA1422
options.ExperimentalOptions.SessionReplay.OnErrorSampleRate = errorSampleRate;
#pragma warning restore CA1422
}
if (ExperimentalOptions.SessionReplay.SessionSampleRate is { } sessionSampleRate)
{
#pragma warning disable CA1422
options.ExperimentalOptions.SessionReplay.SessionSampleRate = sessionSampleRate;
#pragma warning restore CA1422
}
ExperimentalOptions.SessionReplay.RedactAllText = options.ExperimentalOptions.SessionReplay.MaskAllText;
ExperimentalOptions.SessionReplay.RedactAllImages = options.ExperimentalOptions.SessionReplay.MaskAllImages;
}
}
}
18 changes: 18 additions & 0 deletions src/Sentry/Platforms/Android/NativeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,23 @@ public void AddInAppInclude(string prefix)
/// be stripped away during the round-tripping between the two SDKs. Use with caution.
/// </remarks>
public bool EnableBeforeSend { get; set; } = false;

public class NativeExperimentalOptions
{
public NativeSentryReplayOptions SessionReplay { get; set; } = new();
}

public class NativeSentryReplayOptions
{
public double? OnErrorSampleRate { get; set; }
public double? SessionSampleRate { get; set; }
public bool MaskAllImages { get; set; } = true;
public bool MaskAllText { get; set; } = true;
}

/// <summary>
/// ExperimentalOptions
/// </summary>
public NativeExperimentalOptions ExperimentalOptions { get; set; } = new();
}
}
7 changes: 7 additions & 0 deletions src/Sentry/Platforms/Android/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ private static void InitSentryAndroidSdk(SentryOptions options)
options.Native.InAppExcludes?.ForEach(o.AddInAppExclude);
options.Native.InAppIncludes?.ForEach(o.AddInAppInclude);

o.SessionReplay.OnErrorSampleRate =
(JavaDouble?)options.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate;
o.SessionReplay.SessionSampleRate =
(JavaDouble?)options.Native.ExperimentalOptions.SessionReplay.SessionSampleRate;
o.SessionReplay.SetMaskAllImages(options.Native.ExperimentalOptions.SessionReplay.MaskAllImages);
o.SessionReplay.SetMaskAllText(options.Native.ExperimentalOptions.SessionReplay.MaskAllText);

// These options are intentionally set and not exposed for modification
o.EnableExternalConfiguration = false;
o.EnableDeduplication = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace Sentry.Tests.Platforms.Android;

public class BindableNativeOptionsTests : BindableTests<SentryOptions.NativeOptions>
{
public BindableNativeOptionsTests()
: base(nameof(BindableSentryOptions.NativeOptions.ExperimentalOptions))
{
}

[Fact]
public void BindableProperties_MatchOptionsProperties()
{
Expand Down
Loading