Skip to content
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e3cd860
feature - #3353 | Add `BeforeCaptureScreenshot` callback
bricefriha Oct 7, 2024
a134cbe
MAUI sample - options | Add `BeforeCaptureScreenshot` option to the M…
bricefriha Oct 7, 2024
91fa764
unit test - MAUI | Add test for when adding BeforeCaptureScreenshot o…
bricefriha Oct 7, 2024
c453695
feature - change log | for `BeforeCaptureScreenshot`
bricefriha Oct 7, 2024
6372d79
sample - MAUI | uncomment options.BeforeCaptureScreenshot
bricefriha Oct 7, 2024
99bfb1a
Samples - MAUI | enable `deploy`
bricefriha Oct 7, 2024
c45d817
feature - change log | update the chande log entry to make it more de…
bricefriha Oct 7, 2024
e203911
#3661 - update | changes requested to BeforeCaptureScreenshotInternal
bricefriha Oct 7, 2024
7f0b410
MAUI tests - options | update test accordingly to the changes request…
bricefriha Oct 7, 2024
4ccd5ec
cleanup - | removing commented code
bricefriha Oct 7, 2024
fddd5af
changelog - BeforeCaptureScreenshot | fix typos
bricefriha Oct 8, 2024
6e95957
unit test - MAUI | remove BeforeCaptureScreenshot default
bricefriha Oct 8, 2024
4104623
config - Samples - MAUI | roll back changes to enable `deploy`
bricefriha Oct 8, 2024
576d154
Merge branch 'feat/programmatic_sc_attachement' of https://github.com…
bricefriha Oct 8, 2024
6ac5ac0
cleanup - convention | adding brackets to the if statement of the Bef…
bricefriha Oct 8, 2024
273c913
Merge branch 'feat/programmatic_sc_attachement' of https://github.com…
bricefriha Oct 8, 2024
80cd35d
options - MAUI | fix ambiguity _beforeSend -> _beforeCaptureScreenshot
bricefriha Oct 8, 2024
2152253
cleaning - SentryMauiOptions | keep file patern
bricefriha Oct 12, 2024
809567b
Format code
getsentry-bot Oct 12, 2024
9703a34
Unit test - MAUI options beforescreenshot | change True() to IsNotNull()
bricefriha Oct 12, 2024
601e7f6
Update test/Sentry.Maui.Tests/SentryMauiOptionsTests.cs
bruno-garcia Oct 12, 2024
f94fe51
option - Maui BeforeCaptureScreenshot | change null check pattern
bricefriha Oct 12, 2024
1e7b92a
option - Maui BeforeCaptureScreenshot | Change the signiture to do so…
bricefriha Oct 18, 2024
cba76b6
option - Maui BeforeCaptureScreenshot | remove the hint parameter as …
bricefriha Oct 18, 2024
2785afc
option - Maui BeforeCaptureScreenshot | update MAUI sample
bricefriha Oct 18, 2024
8439525
option - Maui BeforeCaptureScreenshot | update unit tests
bricefriha Oct 18, 2024
498e953
option - Maui BeforeCaptureScreenshot | Remove the useless return of …
bricefriha Oct 18, 2024
d53c918
option - Maui BeforeCaptureScreenshot | update sample
bricefriha Oct 19, 2024
c6ddfb7
option - Maui BeforeCaptureScreenshot | correct SetBeforeCapture()
bricefriha Oct 20, 2024
d0a4b35
option - Maui BeforeCapture | rename and documentation
bricefriha Oct 20, 2024
22eba9b
test- Maui BeforeCapture | update tests and sample
bricefriha Oct 20, 2024
da28176
Merge branch 'main' into feat/programmatic_sc_attachement
jamescrosswell Oct 20, 2024
2c1ac57
Format code
getsentry-bot Oct 20, 2024
b939b49
clean up | remove comment on self explanatory code
bricefriha Oct 21, 2024
5d8b520
clean up - Remove comments on self explanatory code
bricefriha Oct 21, 2024
4517762
Unit tests - MAUI | add SetBeforeCapture in the API approvaltestrun v…
bricefriha Oct 21, 2024
94b6e2e
Unit test - maui | update ApiApprovalTests.Run.DotNet7_0.verified.txt
bricefriha Oct 21, 2024
c5a4ba7
MAUI options - option | rename "SetBeforeCapture" -> "SetBeforeScree…
bricefriha Oct 21, 2024
d1d3104
Device tests - MAUI Options | setup tests for all `BeforeCaptureScree…
bricefriha Oct 22, 2024
4ac2276
Unit test - MAUI option | update tests for BeforeCaptureScreenshots
bricefriha Oct 22, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features

- Added a `BeforeCaptureScreenshot` callback to the options: allowing the user to set an action before the screenshot is taken ([#3661](https://github.com/getsentry/sentry-dotnet/pull/3661))
- Make `Sentry.AspNetCore.Blazor.WebAssembly` generally available. ([#3674](https://github.com/getsentry/sentry-dotnet/pull/3674))

### Fixes
Expand Down
10 changes: 10 additions & 0 deletions samples/Sentry.Samples.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics;

namespace Sentry.Samples.Maui;

public static class MauiProgram
Expand All @@ -22,6 +24,14 @@ public static MauiApp CreateMauiApp()

options.Debug = true;
options.SampleRate = 1.0F;

options.SetBeforeCapture((@event, hint) =>
{
Console.WriteLine("screenshot about to be captured.");

// Return true to capture or false to prevent the capture
return true;
});
})

.ConfigureFonts(fonts =>
Expand Down
7 changes: 7 additions & 0 deletions src/Sentry.Maui/Internal/SentryMauiScreenshotProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public SentryMauiScreenshotProcessor(SentryMauiOptions options)

public SentryEvent? Process(SentryEvent @event, SentryHint hint)
{
// Call back before taking the screenshot if the callback is not null
if (!_options.BeforeCaptureInternal?.Invoke(@event, hint) ?? false)
{
// We basically bypass the regular process in favour of the one present in the callback
return @event;
}

hint.Attachments.Add(new ScreenshotAttachment(_options));
return @event;
}
Expand Down
28 changes: 28 additions & 0 deletions src/Sentry.Maui/SentryMauiOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.Extensions.Logging;
using Sentry.Extensions.Logging;
using Sentry.Maui.Internal;

namespace Sentry.Maui;

Expand Down Expand Up @@ -65,4 +67,30 @@ public SentryMauiOptions()
/// Screenshots can be removed from some specific events during BeforeSend through the Hint.
/// </remarks>
public bool AttachScreenshot { get; set; }

private Func<SentryEvent, SentryHint, bool>? _beforeCapture;
/// <summary>
/// Action performed before attaching a screenshot
/// </summary>
internal Func<SentryEvent, SentryHint, bool>? BeforeCaptureInternal => _beforeCapture;

/// <summary>
/// Configures a callback function to be invoked before taking a screenshot
/// </summary>
/// <remarks>
/// if this callback return false the capture will not take place
/// </remarks>
/// <code>
///
///options.SetBeforeCapture((@event, hint) =>
///{
/// // Return true to capture or false to prevent the capture
/// return true;
///});
/// </code>
/// <param name="beforeCapture">Callback to be executed before taking a screenshot</param>
public void SetBeforeCapture(Func<SentryEvent, SentryHint, bool> beforeCapture)
{
_beforeCapture = beforeCapture;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Sentry.Maui
{
public SentryMauiOptions() { }
public bool AttachScreenshot { get; set; }
public System.Action BeforeCaptureScreenshot { get; set; }
public bool CreateElementEventsBreadcrumbs { get; set; }
public bool IncludeBackgroundingStateInBreadcrumbs { get; set; }
public bool IncludeTextInBreadcrumbs { get; set; }
Expand Down
38 changes: 38 additions & 0 deletions test/Sentry.Maui.Tests/SentryMauiOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using NSubstitute.Exceptions;

namespace Sentry.Maui.Tests;

public class SentryMauiOptionsTests
Expand Down Expand Up @@ -56,4 +58,40 @@ public void AttachScreenshots_Default()
var options = new SentryMauiOptions();
Assert.False(options.AttachScreenshot);
}

[Fact]
public void BeforeCaptureScreenshot_Default()
{
// Arrange
var options = new SentryMauiOptions();
options.AttachScreenshot = true;

// Act
options.SetBeforeCapture((@event, hint) =>
{
return true;
});

// Assert
Assert.NotNull(options.BeforeCaptureInternal);

}

[Fact]
public void BeforeCaptureScreenshot_Skip_Screenshot()
{
// Arrange
var options = new SentryMauiOptions();
options.AttachScreenshot = true;

// Act
options.SetBeforeCapture((@event, hint) =>
{
return false;
});

// Assert
Assert.NotNull(options.BeforeCaptureInternal);

}
}
Loading