Skip to content

Commit

Permalink
Session Replay: Recording on Android (#3552)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
  • Loading branch information
bruno-garcia and jamescrosswell authored Nov 4, 2024
1 parent 3bcab16 commit ad80795
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 1 deletion.
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

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

### Fixes

- When using OTel and ASP.NET Core the SDK could try to process OTel spans after the SDK had been closed ([#3726](https://github.com/getsentry/sentry-dotnet/pull/3726))
Expand Down
9 changes: 8 additions & 1 deletion 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 All @@ -33,7 +41,6 @@ public static MauiApp CreateMauiApp()
return true;
});
})

.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
Expand Down
7 changes: 7 additions & 0 deletions src/Sentry.Bindings.Android/Sentry.Bindings.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<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" />
<AndroidLibrary Include="..\..\lib\sentry-android-supplemental\bin\sentry-android-supplemental.jar" />
<AndroidNativeLibrary Include="..\..\lib\sentrysupplemental\bin\arm64-v8a\libsentrysupplemental.so" Abi="arm64-v8a" />
<AndroidNativeLibrary Include="..\..\lib\sentrysupplemental\bin\armeabi-v7a\libsentrysupplemental.so" Abi="armeabi-v7a" />
Expand All @@ -49,6 +50,12 @@
Condition="!Exists('$(SentryAndroidSdkDirectory)sentry-android-ndk-$(SentryAndroidSdkVersion).aar')"
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')"
Retries="3"
/>
<DownloadFile
SourceUrl="https://repo1.maven.org/maven2/io/sentry/sentry/$(SentryAndroidSdkVersion)/sentry-$(SentryAndroidSdkVersion).jar"
DestinationFolder="$(SentryAndroidSdkDirectory)"
Expand Down
2 changes: 2 additions & 0 deletions src/Sentry.Bindings.Android/Transforms/Metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
<remove-node path="/api/package[@name='io.sentry.android.core']/class[@name='TempSensorBreadcrumbsIntegration']" />
<remove-node path="/api/package[@name='io.sentry.android.core.internal.gestures']" />
<remove-node path="/api/package[@name='io.sentry.android.core.performance']" />
<remove-node path="/api/package[@name='io.sentry.android.replay.viewhierarchy']" />
<remove-node path="/api/package[@name='io.sentry.android.replay.util']" />

<remove-node path="/api/package[starts-with(@name,'io.sentry')]/*/method[@name='clone' and count(parameter)=0]" />
<remove-node path="/api/package[starts-with(@name,'io.sentry')]/class/implements[@name='io.sentry.JsonDeserializer']" />
Expand Down
29 changes: 29 additions & 0 deletions src/Sentry/Platforms/Android/BindableNativeSentryOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ReSharper disable once CheckNamespace

namespace Sentry;

internal partial class BindableSentryOptions
Expand Down Expand Up @@ -34,7 +35,20 @@ public class NativeOptions
public TimeSpan? ReadTimeout { get; set; }
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 +75,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;
}
}
}
17 changes: 17 additions & 0 deletions src/Sentry/Platforms/Android/NativeOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ReSharper disable once CheckNamespace

namespace Sentry;

public partial class SentryOptions
Expand Down Expand Up @@ -260,5 +261,21 @@ 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 @@ -163,6 +163,13 @@ private static void InitSentryAndroidSdk(SentryOptions options)
options.Native.InAppExcludes?.ForEach(o.AddInAppExclude);
options.Native.InAppIncludes?.ForEach(o.AddInAppInclude);
o.Experimental.SessionReplay.OnErrorSampleRate =
(JavaDouble?)options.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate;
o.Experimental.SessionReplay.SessionSampleRate =
(JavaDouble?)options.Native.ExperimentalOptions.SessionReplay.SessionSampleRate;
o.Experimental.SessionReplay.SetMaskAllImages(options.Native.ExperimentalOptions.SessionReplay.MaskAllImages);
o.Experimental.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

0 comments on commit ad80795

Please sign in to comment.