Skip to content
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

Add managed attachments to native events #3545

Open
TimBurik opened this issue Aug 20, 2024 · 6 comments
Open

Add managed attachments to native events #3545

TimBurik opened this issue Aug 20, 2024 · 6 comments
Labels
Android Feature New feature or request
Milestone

Comments

@TimBurik
Copy link

Package

Sentry

.NET Flavor

.NET

.NET Version

8.0.303

OS

Android

SDK Version

4.10.1

Self-Hosted Sentry Version

No response

Steps to Reproduce

  1. Create an Android app and install Sentry NuGet package;
  2. Configure Sentry so that reported events should have attachments (both logcat and custom attachments are affected by the issue):
SentrySdk.Init(options =>
{
    options.Dsn = "...";
    options.Android.LogCatIntegration = LogCatIntegrationType.All;
});
SentrySdk.ConfigureScope(scope =>
{
    scope.AddAttachment("path/to/existing/file.txt", AttachmentType.Default, MediaTypeNames.Text.Plain);
});
  1. Generate crashes using SentrySdk.CauseCrash() with different parameters

Expected Result

All reported events should have logcat.log attachment with logcat logs and custom file.txt file attachment.

Actual Result

  • Crash generated with parameter CrashType.Native is reported with mechanism signalhandler and contains no attachments;
  • Crash generated with parameter CrashType.JavaBackgroundThread is reported twice: one with mechanism UncaughtExceptionHandler and contains no attachments, and another with mechanism AppDomain.UnhandledException and contains both attachments;
  • All other crash types (CrashType.Managed, CrashType.ManagedBackgroundThread, CrashType.Java) are reported with mechanism AppDomain.UnhandledException and contain both attachments.

This issue might be related to #3461

Reproduction sample: SampleProject.zip

@TimBurik
Copy link
Author

The issue is also reproduced when ApplicationNotResponding is reported, no files are attached despite both logcat and custom attachments are configured.

@jamescrosswell
Copy link
Collaborator

Crash generated with parameter CrashType.Native is reported with mechanism signalhandler and contains no attachments;

I think this is similar to:

In both cases, Native crash reporting essentially skips all the .NET SDK processing.

@jamescrosswell
Copy link
Collaborator

Crash generated with parameter CrashType.JavaBackgroundThread is reported twice: one with mechanism UncaughtExceptionHandler and contains no attachments, and another with mechanism AppDomain.UnhandledException and contains both attachments;

I suspect the UncaughtExceptionHandler is coming from Java and the AppDomain.UnhandledException is coming from .NET.

@bitsandfoxes do you know what the expected behaviour is here?

  • Should the Java SDK be syncing it's scope via a scope action callback and so should it also contain the attachments?
  • Once the exception has been reported by Java, is there any way the .NET SDK could be aware of this and suppress further reporting? Or conversely, is there any way for the Java SDK to know this exception would be reported by the .NET SDK and so could safely ignore it?

@jamescrosswell
Copy link
Collaborator

jamescrosswell commented Aug 25, 2024

Possibly relates to this (so maybe something that hasn't yet been implemented):

public static SentryAttachment ToAttachment(this JavaSdk.Attachment attachment)
{
// TODO: Convert JavaSdk.Attachment to Sentry.Attachment.
// One way to do this might be to serialise the JavaSdk.Attachment as
// JSON and then deserialise it as a Sentry.Attachment. It looks like
// Attachments aren't designed to be serialised directly though (they
// get stuffed into EnvelopeItems instead)... and I'm not sure if we'd
// have access to the JSON serialiser from here or how the data in
// JavaSdk.Attachment.GetBytes() is encoded.
throw new NotImplementedException();
}
public static JavaSdk.Attachment ToJavaAttachment(this SentryAttachment attachment)
{
// TODO: Convert Sentry.Attachment to JavaSdk.Attachment.
// Same problem as ToAttachment() above but in reverse.
throw new NotImplementedException();
}

// TODO: Implement ToAttachment
//dotnetHint.Screenshot = (javaHint.Screenshot is { } screenshot) ? screenshot.ToAttachment() : null;
//dotnetHint.ViewHierarchy = (javaHint.ViewHierarchy is { } viewhierarchy) ? viewhierarchy.ToAttachment() : null;
//dotnetHint.AddAttachments(javaHint.Attachments.Select(x => x.ToAttachment()));

@bitsandfoxes bitsandfoxes added Android Feature New feature or request labels Aug 29, 2024
@bitsandfoxes bitsandfoxes added this to the 5.0.0 milestone Aug 29, 2024
@bitsandfoxes
Copy link
Contributor

Once the exception has been reported by Java, is there any way the .NET SDK could be aware of this and suppress further reporting? Or conversely, is there any way for the Java SDK to know this exception would be reported by the .NET SDK and so could safely ignore it?

I might have gotten that wrong but I was under the impression that the .NET SDK would be responsible for managed code and the Java SDK would provide native support. Having the same exception reported via the UncaughtExceptionHandler in Java and the AppDomain.UnhandledException is not ideal. But the reporting SDK is part of the event details.

@jamescrosswell
Copy link
Collaborator

I was under the impression that the .NET SDK would be responsible for managed code and the Java SDK would provide native support.

That's true, but you can add things to the scope (including attachments) that you want/expect to be sent with both Managed and Native exceptions. This hasn't been implemented for Attachments on Android yet.

@bitsandfoxes bitsandfoxes changed the title [Android] Missing file attachments Add managed attachments to native events Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Feature New feature or request
Projects
Status: No status
Status: No status
Development

No branches or pull requests

3 participants