-
-
Notifications
You must be signed in to change notification settings - Fork 56
fix: Screenshot Capture #2240
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
Merged
Merged
fix: Screenshot Capture #2240
Changes from 42 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
7c90568
initial idea
bitsandfoxes 98a7988
Format code
getsentry-bot a3a70a4
Merge branch 'main' into fix/screenshot-capture
bitsandfoxes f204618
Merge branch 'fix/screenshot-capture' of https://github.com/getsentry…
bitsandfoxes 8f74147
capture and send screenshot
bitsandfoxes 8f852e0
merged main
bitsandfoxes 35a172d
bumped implementation in .NET
bitsandfoxes 11548fe
updated to make it work with tests
bitsandfoxes 91aa77f
Format code
getsentry-bot 113e40e
moved screenshot capture logic back into the processor
bitsandfoxes 271ef13
cleanup
bitsandfoxes c4c5a96
Updated CHANGELOG.md
bitsandfoxes 7e183a1
added delay in tests to fix flake
bitsandfoxes 41d69fc
updated the smoketester to handle the delayed screenshot capture
bitsandfoxes 521298d
updated success/fail checks
bitsandfoxes 8dfd665
more CI work
bitsandfoxes e2e83a8
bumped .NET SDK
bitsandfoxes 072d2d3
.
bitsandfoxes 176de44
cleaned up the smoketester
bitsandfoxes 778e03d
.
bitsandfoxes 34b03bd
increased smoke test run timeout
bitsandfoxes f4ed1fa
waitforseconds for smoketester instead
bitsandfoxes 38d2738
debug logs
bitsandfoxes 9015cd5
no coroutine for smoketesting no more
bitsandfoxes 4e634d1
increase http request interception timeout
bitsandfoxes a9dfcb1
it needs to be a coroutine
bitsandfoxes e05a579
if waitfor does not work what about yield null?
bitsandfoxes 26be76b
force opengl on linux
bitsandfoxes 1cd0c2c
keep focus
bitsandfoxes b8fdb41
smoke tester cleanup
bitsandfoxes 2e24049
is it the focus thing?
bitsandfoxes 8043f3c
one more time. does it really require the sentrymonobehaviour?
bitsandfoxes 6c9b8c8
going with buildtime settings here
bitsandfoxes c0f38f0
final pass
bitsandfoxes 73d3589
chore: Added Unity `6.1` to CI (#2130)
bitsandfoxes 8d675e7
Update src/Sentry.Unity/ScreenshotEventProcessor.cs
bitsandfoxes 3a704c1
Update src/Sentry.Unity/SentryUnitySdk.cs
bitsandfoxes 172e8ae
Update src/Sentry.Unity/ScreenshotEventProcessor.cs
bitsandfoxes bb18109
Format code
getsentry-bot e0856f6
fixed broken commits & added editor check before adding integration
bitsandfoxes 65516a1
fixed broken merge
bitsandfoxes a2fe576
Format code
getsentry-bot 240d0ba
Merge branch 'main' into fix/screenshot-capture
bitsandfoxes 7910b8c
merged main
bitsandfoxes 060c3c5
Updated the processor to have virtual functions for testing
bitsandfoxes d3615e7
builder cleanup
bitsandfoxes e132867
Fixed name
bitsandfoxes 12e4315
Handle empty byte array
bitsandfoxes 6c7695a
Fix processname
bitsandfoxes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,75 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Threading; | ||
using Sentry.Extensibility; | ||
using Sentry.Unity.Integrations; | ||
using Sentry.Internal; | ||
using UnityEngine; | ||
|
||
namespace Sentry.Unity; | ||
|
||
public class ScreenshotEventProcessor : ISentryEventProcessorWithHint | ||
public class ScreenshotEventProcessor : ISentryEventProcessor | ||
{ | ||
private readonly SentryUnityOptions _options; | ||
private readonly IApplication _application; | ||
public ScreenshotEventProcessor(SentryUnityOptions sentryOptions) : this(sentryOptions, null) { } | ||
private readonly ISentryMonoBehaviour _sentryMonoBehaviour; | ||
private volatile int _isCapturingScreenshot; | ||
|
||
internal ScreenshotEventProcessor(SentryUnityOptions sentryOptions, IApplication? application) | ||
internal Func<SentryUnityOptions, byte[]> ScreenshotCaptureFunction = SentryScreenshot.Capture; | ||
internal Action<SentryId, SentryAttachment> AttachmentCaptureFunction = (eventId, attachment) => | ||
(Sentry.SentrySdk.CurrentHub as Hub)?.CaptureAttachment(eventId, attachment); | ||
internal Func<YieldInstruction> WaitForEndOfFrameFunction = () => new WaitForEndOfFrame(); | ||
|
||
public ScreenshotEventProcessor(SentryUnityOptions sentryOptions) : this(sentryOptions, SentryMonoBehaviour.Instance) { } | ||
|
||
internal ScreenshotEventProcessor(SentryUnityOptions sentryOptions, ISentryMonoBehaviour sentryMonoBehaviour) | ||
{ | ||
_options = sentryOptions; | ||
_application = application ?? ApplicationAdapter.Instance; | ||
_sentryMonoBehaviour = sentryMonoBehaviour; | ||
} | ||
|
||
public SentryEvent? Process(SentryEvent @event) | ||
public SentryEvent Process(SentryEvent @event) | ||
{ | ||
// Only ever capture one screenshot per frame | ||
if (Interlocked.CompareExchange(ref _isCapturingScreenshot, 1, 0) == 0) | ||
{ | ||
_sentryMonoBehaviour.StartCoroutine(CaptureScreenshotCoroutine(@event.EventId)); | ||
bitsandfoxes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return @event; | ||
} | ||
|
||
public SentryEvent? Process(SentryEvent @event, SentryHint hint) | ||
internal IEnumerator CaptureScreenshotCoroutine(SentryId eventId) | ||
{ | ||
// save event id | ||
// wait for end of frame | ||
// check if last id is event it | ||
// send screenshot | ||
_options.LogDebug("Screenshot capture triggered. Waiting for End of Frame."); | ||
|
||
bitsandfoxes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// add workitem: screentshot for ID xxx | ||
// sdk integration checking for work: if ID got sent, follow up with screenshot | ||
// WaitForEndOfFrame does not work in headless mode so we're making it configurable for CI. | ||
// See https://docs.unity3d.com/6000.1/Documentation/ScriptReference/WaitForEndOfFrame.html | ||
yield return WaitForEndOfFrameFunction(); | ||
|
||
if (!MainThreadData.IsMainThread()) | ||
try | ||
{ | ||
_options.DiagnosticLogger?.LogDebug("Screenshot capture skipped. Can't capture screenshots on other than the main thread."); | ||
return @event; | ||
} | ||
|
||
if (_options.BeforeCaptureScreenshotInternal?.Invoke() is not false) | ||
{ | ||
if (_application.IsEditor) | ||
if (_options.BeforeCaptureScreenshotInternal?.Invoke() is false) | ||
{ | ||
_options.DiagnosticLogger?.LogInfo("Screenshot capture skipped. Capturing screenshots it not supported in the Editor"); | ||
return @event; | ||
yield break; | ||
} | ||
|
||
if (Screen.width == 0 || Screen.height == 0) | ||
{ | ||
_options.DiagnosticLogger?.LogWarning("Can't capture screenshots on a screen with a resolution of '{0}x{1}'.", Screen.width, Screen.height); | ||
} | ||
else | ||
{ | ||
hint.AddAttachment(SentryScreenshot.Capture(_options), "screenshot.jpg", contentType: "image/jpeg"); | ||
} | ||
var screenshotBytes = ScreenshotCaptureFunction(_options); | ||
var attachment = new SentryAttachment( | ||
AttachmentType.Default, | ||
bitsandfoxes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
new ByteAttachmentContent(screenshotBytes), | ||
"screenshot.jpg", | ||
"image/jpeg"); | ||
|
||
_options.LogDebug("Screenshot captured for event {0}", eventId); | ||
|
||
AttachmentCaptureFunction(eventId, attachment); | ||
} | ||
else | ||
catch (Exception e) | ||
{ | ||
_options.DiagnosticLogger?.LogInfo("Screenshot capture skipped by BeforeAttachScreenshot callback."); | ||
_options.LogError(e, "Failed to capture screenshot."); | ||
} | ||
finally | ||
{ | ||
Interlocked.Exchange(ref _isCapturingScreenshot, 0); | ||
} | ||
|
||
return @event; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule sentry-dotnet
updated
18 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ public static void BuildIl2CPPPlayer(BuildTarget target, BuildTargetGroup group, | |
EditorUserBuildSettings.selectedBuildTargetGroup = group; | ||
EditorUserBuildSettings.allowDebugging = false; | ||
PlayerSettings.SetScriptingBackend(group, ScriptingImplementation.IL2CPP); | ||
// Making sure that the app keeps on running in the background. Linux CI is very unhappy with coroutines otherwise. | ||
PlayerSettings.runInBackground = true; | ||
|
||
DisableUnityAudio(); | ||
DisableProgressiveLightMapper(); | ||
|
@@ -41,14 +43,6 @@ public static void BuildIl2CPPPlayer(BuildTarget target, BuildTargetGroup group, | |
PlayerSettings.SetManagedStrippingLevel(group, ManagedStrippingLevel.Low); | ||
#endif | ||
|
||
|
||
// This is a workaround for build issues with Unity 2022.3. and newer. | ||
// https://discussions.unity.com/t/gradle-build-issues-for-android-api-sdk-35-in-unity-2022-3lts/1502187/10 | ||
#if UNITY_2022_3_OR_NEWER | ||
Debug.Log("Builder: Setting Android target API level to 33"); | ||
PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevel33; | ||
#endif | ||
|
||
Comment on lines
-44
to
-51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Workaround that is no longer needed. |
||
Debug.Log("Builder: Updating BuildPlayerOptions"); | ||
var buildPlayerOptions = new BuildPlayerOptions | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.