Repository navigation
Description
Environment
How do you use Sentry? Sentry SaaS (sentry.io)
Which version of the SDK? 0.10.1
Which version of Unity? 2020.3.23f1
Is this happening in Unity (editor) or on a player like Android, iOS, Windows? On WebGL player
Background
I'm running Sentry on WebGL. Thanks to the new support for IBackgroundWorker to handle the sending of Envelopes, it was easy enough to make Sentry report error events on WebGL. My BackgroundWorker is very simple, it holds a queue and when flushed, it serializes each envelope and sends it using UnityWebRequest. The flushing happens in a coroutine. However, I noticed that user error reports did not work. I found a work around to this, but it may point to some issue in how attachments are handled (or it's just something that would be naturally solved when this SDK gets official WebGL support).
Steps to Reproduce
I have made a repro repo. In short, it's an empty project with Sentry installed. Two keys trigger two different functions in TestCase.cs for attaching a screenshot that is generated (for the user report).
A key triggers code that adds attachment simply with scope.AddAttachment(filePath) which causes Envelope.SerializeAsync to later silently fail.
B key triggers an otherwise identical function that instead attaches the screenshot like this:
using Stream fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var data = new byte[fileStream.Length];
fileStream.Read(data, 0, data.Length);
fileStream.Seek(0, SeekOrigin.Begin);
scope.AddAttachment(data, filename);
Clone the repo, go to Assets/TestCase.cs and enter a correct DSN in the code. If you then run this in Editor, it makes no difference whether i press A or B, both works as expected. If I build and run in WebGL, A silently fails but B works.
Here's a sample browser console log that first shows A version, then B version: https://bitbucket.org/fictivr/repro-sentry-unity-attach/src/master/test-case-error-log.txt
No error is seen in the log, two envelopes are queued up in both, but in A, one of the envelopes (the event with attachment) is never sent (SerializeAsync fails such that the web request never gets sent, but I haven't been able to catch any exception - but in WebGL that often doesn't work due to IL2CPP).
What puzzles me is that just opening the file myself and giving the raw data works, while adding the file path fails.
Activity
bitsandfoxes commentedon Mar 1, 2022
Hey @ripperdoc, thanks a lot for the detailed repro repo! That's curious because 0.10.1 contained the fix in the .NET SDK specifically for an attachment-related issue: https://github.com/getsentry/sentry-dotnet/pull/1489/files.
We'll definitely take another look.
vaind commentedon Apr 1, 2022
Shouldn't this code:
wait until the file is created?
The docs say "The CaptureScreenshot returns immediately on Android. The screen capture continues in the background. The resulting screen shot is saved in the file system after a few seconds."
edit: seems to work (or NOT work in case of the first function) with either
iforwhilevaind commentedon Apr 1, 2022
FYI there's automatic screenshot capture incoming: #670
and WebGL support with a custom HTTP transport as well: #657
vaind commentedon Apr 1, 2022
I can confirm I'm getting an error with the current WebGL implementation and the first button. This error is also reported to Sentry.io while the original message is missing.
Chrome console log
The second approach of reading the file and adding a stream works as expected (same as for the OP).
vaind commentedon Apr 1, 2022
OK, so the issue is with the
useAsyncargument to theFileStreamconstructor that's used when you add an attachment by a filename:I'd argue that's a Unity issue (should ignore the arg if it can't handle it, or throw right away when
true), but maybe we can do something to circumvent it.vaind commentedon Apr 1, 2022
I've created a Unity issue, though I'm not having much hope - I haven't received any feedback on any of my past issues (am I doing something wrong?)
vaind commentedon Apr 4, 2022
A fix is ready in #657 - setting a new option
UseAsyncFileIO = falseripperdoc commentedon Apr 4, 2022
Yeah, it really should be a while there and it was earlier in my code, no idea how that changed :) But thanks for working on the underlying issue, much appreciated!