Skip to content

Add LogCat integration to Android via an EventProcessor - #2926

Merged
bruno-garcia merged 28 commits into
getsentry:mainfrom
kanadaj:main
Dec 2, 2023
Merged

bruno-garcia merged 28 commits into
getsentry:mainfrom
kanadaj:main

Conversation

@kanadaj

@kanadaj kanadaj commented Nov 29, 2023

Copy link
Copy Markdown
Contributor

It is possible to fetch LogCat logs using Runtime.Exec() per the following comment: getsentry/sentry-java#1620 (comment)

This SentryEventProcessor automatically grabs the LogCat logs on error (configurable to only log on unhandled errors, all errors or all events) and attaches it to the SentryEvent as a file attachment.

@bruno-garcia bruno-garcia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for adding this!

Comment thread CHANGELOG.md Resolved

@bruno-garcia bruno-garcia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks great!

Could you add this to the sample, please?
We at least should get some manual testing done there and then integration tests (no point in unit testing this I guess?)

Comment thread CHANGELOG.md Resolved
process.InputStream.CopyTo(output);
process.WaitFor();

hint.AddAttachment(filesDir!.Path + "/sentry_logcat.txt", AttachmentType.Default, "text/logcat");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matejminar we're making up a new mime/type here, is that OK? The goal is to have a customer preview in Sentry that understand logcat and is able to filter by the different columns or highlight stuff etc, wdty?

@romtsn would we want that on Android in general?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bruno-garcia yes, you'll need to add logcat into this switch to map it to an existing viewer:
https://github.com/getsentry/sentry/blob/d4f5584da02f71f4c2a1a00792b9558c22df61db/static/app/components/events/eventAttachments.tsx#L38-L56

if you want a fancy logcat-specific viewer, you can take an inspo from one of the existing ones there

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bruno-garcia yeah, so far we opted for bytecode manipulation and sending breadcrumbs - this works for the app and libraries logcat calls, but not the system ones. Also it supports all Android versions, while this approach is from API 23 and above.

But generally, I think this would be nice to have, especially when we bump min sdk to 21 or 24 in the future. Should probably be opt-in by default though

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome folks! thanks a lot

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kanadaj

kanadaj commented Dec 1, 2023

Copy link
Copy Markdown
Contributor Author

I think it looks great!

Could you add this to the sample, please? We at least should get some manual testing done there and then integration tests (no point in unit testing this I guess?)

Yeah there is really nothing to unit test, you need a running Android device or emulator with logcat to test this one.

@bruno-garcia bruno-garcia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Thanks Daniel!

Comment thread CHANGELOG.md Resolved
@bruno-garcia

Copy link
Copy Markdown
Member

PR adding it to Android: getsentry/sentry-java#2620

@kanadaj

kanadaj commented Dec 1, 2023

Copy link
Copy Markdown
Contributor Author

PR adding it to Android: getsentry/sentry-java#2620

That one uses breadcrumbs though... And while that's possible, imho logcat outputs way too much noise for breadcrumbs to be particularly useful (sometimes you need several hundred log messages from logcat to find what you need).

Afaik it also relies on using Gradle to replace Log.{} calls with Sentry's own thing, and we don't have Gradle here...

@bitsandfoxes

bitsandfoxes commented Dec 1, 2023 •

Copy link
Copy Markdown
Contributor

Thanks again for adding this! Lemme figure out what's up with the device tests..

@bruno-garcia

Copy link
Copy Markdown
Member

PR adding it to Android: getsentry/sentry-java#2620

That one uses breadcrumbs though... And while that's possible, imho logcat outputs way too much noise for breadcrumbs to be particularly useful (sometimes you need several hundred log messages from logcat to find what you need).

Afaik it also relies on using Gradle to replace Log.{} calls with Sentry's own thing, and we don't have Gradle here...

Some internal chatter came to the conclusion we should:

  1. Have this feature be opt-in
    a. potential PII leakage due to apps dumping private stuff
    b. potential overhead
    c. logcat isn't popular in prod for 'reasons' and that's why Timber became popular, it can be disabled anyway in prod
  2. I think that's all actually, lets have 'false' as default and we should be good to go!

@kanadaj

kanadaj commented Dec 1, 2023 •

Copy link
Copy Markdown
Contributor Author

Sure, lemme do that. Test should also work now. Or not. What the heck?

E1201 19:46:03.030494    3881 FrameBuffer.cpp:3765] Failed to find ColorBuffer:62

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants