Skip to content

Add managed attachments to native Android events #3545

Open

Description

@TimBurik

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

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Aug 20, 2024
  2. TimBurik commented on Aug 20, 2024

    @TimBurik
    Author

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

  3. jamescrosswell commented on Aug 23, 2024

    @jamescrosswell
    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.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Aug 23, 2024
  5. jamescrosswell commented on Aug 25, 2024

    @jamescrosswell
    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?
  6. jamescrosswell commented on Aug 25, 2024

    @jamescrosswell
    Collaborator

    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()));

  7. added this to the 5.0.0 milestone on Aug 29, 2024
  8. bitsandfoxes commented on Sep 4, 2024

    @bitsandfoxes
    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.

  9. jamescrosswell commented on Sep 4, 2024

    @jamescrosswell
    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.

  10. 48 remaining items

  11. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Sep 3, 2025
  12. jamescrosswell commented on Sep 3, 2025

    @jamescrosswell
    Collaborator

    OK thanks @TimBurik, that makes sense. And you're right, this hasn't yet been implemented in the hint extensions and the attachment extensions.

    @Angelodaniel are you doing something similar or would this solve a different problem for you?

  13. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Sep 3, 2025
  14. added
    .NET
    and removed on Mar 24, 2026
  15. dalux-era commented on Jul 10, 2026

    @dalux-era

    Hi,
    I know this has been stale for a bit, but we also would like to request this feature. Our app works a lot with unmanaged code which runs closely to mobile device firmware. Whenever we receive a native crash it is very hard to deduct where it originates from. So we have created out own log file with different states of different processes. It would benefit us very much to be able to attach it to the native reports.

  16. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 10, 2026
  17. jamescrosswell commented on Nov 26, 2026

    @jamescrosswell
    Collaborator

    Adding the logcat details from #4845, now closed as a duplicate:

    This is now a sub-issue of #5052, which covers attachment sync on every platform.

  18. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETAttachmentsFeature

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions