sentry-unity icon indicating copy to clipboard operation
sentry-unity copied to clipboard

Screenshots and View Hierarchy lost with `ClearAttachment`

Open bitsandfoxes opened this issue 2 years ago • 8 comments

When calling scope.ClearAttachments() it also removes the automated screenshot and view hierarchy integrations.

bitsandfoxes avatar May 12 '22 12:05 bitsandfoxes

depends on https://github.com/getsentry/sentry-dotnet/issues/1469

vaind avatar May 31 '22 09:05 vaind

We could somehow expose a workaround for now - call the following after ClearAttachments():

SentrySdk.ConfigureScope(s =>
                        s.AddAttachment(new ScreenshotAttachment(
                            new ScreenshotAttachmentContent(options, SentryMonoBehaviour.Instance))));

but those are currently internal

vaind avatar May 31 '22 09:05 vaind

Is there any workaround available for this, beyond recompiling new Sentry SDKs to un-mark those those internal classes?

For some wider context: We're clearing and adding attachments because we want to have a [GUID].ext filename, rather than a common filename, which represents our game state. I don't know how to do that without clearing first.

Also, I'd really love the ability to add attachments in the beforeSend callback, which feels like a more natural place to pull game state into an outgoing event. That's mentioned in #663

mwegner avatar Nov 25 '22 15:11 mwegner

a [GUID].ext filename

Are you trying to rename the screenshot or are you referring to your own files you're attaching?

bitsandfoxes avatar Dec 05 '22 09:12 bitsandfoxes

Our own files--we have GUIDs assigned to the block of data that represents the current game state in a turn-based game. Partly this is to make it easier to pick out the right file for issues that end up with multiple events. The combined attachment view for grouped events on the Sentry backend can be a little rough.

I ended up copying the structure of the screenshot attachment class, with a generic filename and the contents being pulled at the time of the event. Would it be possible to add a setter to Attachment.FileName (here), or otherwise allow a mechanism to change the filename from within the IAttachmentContent.GetStream() method? That would also work for this specific case.

mwegner avatar Dec 05 '22 11:12 mwegner

Also, I'd really love the ability to add attachments in the beforeSend callback, which feels like a more natural place to pull game state into an outgoing event. That's mentioned in #663

We agree with the idea to have it be accessible in the beforeSend and it looks like the way forward will be hints. I think this also would properly resolve the issue and I'll try to move that feature forward.

AFAIK the screenshot name is expected by the frontend to be in one of those formats.

bitsandfoxes avatar Dec 09 '22 15:12 bitsandfoxes

The .NET SDK now supports Hints so we no longer need to add attachments directly to the scope. And those integrations no longer get lost on ClearScope.

bitsandfoxes avatar May 23 '23 13:05 bitsandfoxes