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 attachments to native crash event #1423

Closed
blaugold opened this issue May 7, 2023 · 3 comments
Closed

Add attachments to native crash event #1423

blaugold opened this issue May 7, 2023 · 3 comments

Comments

@blaugold
Copy link
Contributor

blaugold commented May 7, 2023

Problem Statement

I am trying to diagnose a native crash and would like to collect additional information by attaching log files that are continuously written during app execution to the error event.

Since the relevant crash is in native code, it's only detected at the next app start. The attachment should only be included when the stack trace of the crashed thread contains frames from a specific library. The attachment is a zip file of multiple log files and can only be created just before adding the attachment.

I would preferably implement capturing the logs in Dart so that it works on all platforms. For that, there would need to be the ability to process native events in Dart.

I suspect that will not be possible any time soon, if ever. :) So, I've sketched out how to do it with the Sentry Swift SDK:

SentrySDK.start { options in
    options.beforeSend = { event in
        let isCrashInCouchbaseLite = event.exceptions?.first?.stacktrace?.frames
            .contains { frame in frame.package?.contains("CouchbaseLite") ?? false } ?? false
        if isCrashInCouchbaseLite {
            // Can't figure out how to add an attachment to the event,
            // so we capture a new event.
            SentrySDK.capture(exception: NSException(name: NSExceptionName(event.eventId), reason: nil)) { scope in
                // TODO: Zip logs
                // TODO: Add file attachment to logs
            }
        }
        return event
    }
}

What I was unable to figure out is:

  1. how to add attachments in beforeSend in Swift and
  2. how to set up the beforeSend callback without interfering with the Flutter Sentry plugin, which already calls SentrySDK.start.

Solution Brainstorm

No response

Are you willing to submit a PR?

None

@marandaneto
Copy link
Contributor

@blaugold Thanks for raising this.

I suspect that will not be possible any time soon, if ever. :) So, I've sketched out how to do it with the Sentry Swift SDK:

You're correct, probably not, since if it crashes on iOS Native code or Android NDK code, the process just dies, it'd probably be possible to run the beforeSend on a restart on the Dart code, but as of now it's not planned, you can always do the beforeSend on the Native SDKs by following https://docs.sentry.io/platforms/flutter/native-init/
I'll discuss this internally, and open a new issue if needed.

For question 1., you can do scope.addAttachment(...).

SentrySDK.captureMessage(message: "my message", block: { scope in
	scope.addAttachment(fileAttachment)
})

For question 2., you have to init the SDK manually, https://docs.sentry.io/platforms/flutter/native-init/

@blaugold
Copy link
Contributor Author

blaugold commented May 8, 2023

@marandaneto Thanks! I should have read the docs :)

Is it also possible to somehow add an attachment to the event that is passed to beforeSend in the native SDK?

@marandaneto
Copy link
Contributor

@blaugold not yet, getsentry/sentry-cocoa#2325
Thumbs up so it's easier to prioritize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants