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 LogCat integration to Android via an EventProcessor #2926

Merged
merged 28 commits into from
Dec 2, 2023

Conversation

kanadaj
Copy link
Contributor

@kanadaj kanadaj commented Nov 29, 2023

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.

Copy link
Member

@bruno-garcia bruno-garcia left a comment

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!

CHANGELOG.md Outdated Show resolved Hide resolved
src/Sentry/Platforms/Android/SentrySdk.cs Outdated Show resolved Hide resolved
kanadaj and others added 6 commits November 30, 2023 18:28
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
Copy link
Member

@bruno-garcia bruno-garcia left a comment

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?)

CHANGELOG.md Outdated Show resolved Hide resolved
process.InputStream.CopyTo(output);
process.WaitFor();

hint.AddAttachment(filesDir!.Path + "/sentry_logcat.txt", AttachmentType.Default, "text/logcat");
Copy link
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
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
Member

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
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
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

kanadaj and others added 6 commits December 1, 2023 00:43
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
… the FilesDir, generate the file name dynamically
@kanadaj
Copy link
Contributor Author

kanadaj commented Dec 1, 2023

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.

Copy link
Member

@bruno-garcia bruno-garcia left a comment

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!

CHANGELOG.md Outdated Show resolved Hide resolved
src/Sentry/Platforms/Android/SentryOptions.cs Show resolved Hide resolved
src/Sentry/Platforms/Android/SentryOptions.cs Outdated Show resolved Hide resolved
kanadaj and others added 2 commits December 1, 2023 01:11
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
@bruno-garcia
Copy link
Member

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

@kanadaj
Copy link
Contributor Author

kanadaj commented Dec 1, 2023

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
Copy link
Contributor

bitsandfoxes commented Dec 1, 2023

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

@bruno-garcia
Copy link
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
Copy link
Contributor Author

kanadaj commented Dec 1, 2023

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

@bruno-garcia bruno-garcia merged commit 88bfc29 into getsentry:main Dec 2, 2023
18 checks passed
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