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

feat: logcat integration #2620

Merged
merged 16 commits into from
Mar 28, 2023
Merged

feat: logcat integration #2620

merged 16 commits into from
Mar 28, 2023

Conversation

buenaflor
Copy link
Contributor

📜 Description

Implements a SentryLogcatAdapter that will replace Log calls via bytecode manipulation in the Sentry AGP.

💡 Motivation and Context

Ref: #1620

This adapter is needed by the AGP. See: getsentry/sentry-android-gradle-plugin#455

💚 How did you test it?

  • Manual testing
  • Jadx

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@github-actions
Copy link
Contributor

github-actions bot commented Mar 23, 2023

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 97d1157

@github-actions
Copy link
Contributor

github-actions bot commented Mar 23, 2023

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 341.85 ms 377.19 ms 35.34 ms
Size 1.73 MiB 2.34 MiB 626.85 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
d81684e 235.73 ms 328.76 ms 93.03 ms

App size

Revision Plain With Sentry Diff
d81684e 1.73 MiB 2.26 MiB 547.78 KiB

Previous results on branch: feat/logcat-integration

Startup times

Revision Plain With Sentry Diff
6dbe27a 277.26 ms 294.76 ms 17.50 ms
8a1a524 366.12 ms 388.69 ms 22.57 ms
8feb38e 311.12 ms 376.45 ms 65.32 ms
3372342 345.15 ms 379.94 ms 34.79 ms
174b08b 363.30 ms 403.38 ms 40.08 ms
3abf17c 448.04 ms 479.16 ms 31.12 ms

App size

Revision Plain With Sentry Diff
6dbe27a 1.73 MiB 2.26 MiB 548.10 KiB
8a1a524 1.73 MiB 2.26 MiB 547.78 KiB
8feb38e 1.73 MiB 2.26 MiB 547.63 KiB
3372342 1.73 MiB 2.26 MiB 548.10 KiB
174b08b 1.73 MiB 2.26 MiB 548.04 KiB
3abf17c 1.73 MiB 2.26 MiB 547.63 KiB

@codecov
Copy link

codecov bot commented Mar 23, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (2ec7569) 81.34% compared to head (97d1157) 81.34%.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #2620   +/-   ##
=========================================
  Coverage     81.34%   81.34%           
  Complexity     4211     4211           
=========================================
  Files           337      337           
  Lines         15575    15575           
  Branches       2034     2034           
=========================================
  Hits          12670    12670           
  Misses         2110     2110           
  Partials        795      795           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@markushi markushi left a comment

Choose a reason for hiding this comment

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

Looking good, please check my comments

Comment on lines 28 to 29
@NotNull String tag, @NotNull SentryLevel level, String msg, Throwable tr) {
Breadcrumb breadcrumb = new Breadcrumb();
Copy link
Member

Choose a reason for hiding this comment

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

We usually like to use the final keyword to indicate that objects will not be re-assigned.

Suggested change
@NotNull String tag, @NotNull SentryLevel level, String msg, Throwable tr) {
Breadcrumb breadcrumb = new Breadcrumb();
@NotNull final String tag, @NotNull final SentryLevel level, final String msg, final Throwable tr) {
final Breadcrumb breadcrumb = new Breadcrumb();

Sentry.addBreadcrumb(breadcrumb);
}

public static int v(String tag, @NotNull String msg) {
Copy link
Member

@markushi markushi Mar 24, 2023

Choose a reason for hiding this comment

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

I think it probably makes sense to have tag, msg and throwable marked as @Nullable everywhere
image

breadcrumb.setLevel(level);
breadcrumb.setData("tag", tag);
if (tr != null) {
breadcrumb.setData("throwable", tr.getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

I think in the first version it's fine to just have the throwable message inside the breadcrumb, @romtsn what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

yeah, I think that's fine

@markushi
Copy link
Member

I think it could make sense to add an integration test here as well.

Given an initialized Sentry SDK
When SentryLogcatAdapter.x is called with params y,z
Then a breadcrumb should be captured with y,z

* io.sentry.Breadcrumb} for each log. It only replaces log functions that meet a minimum level set
* by the user on the Sentry Android Gradle Plugin.
*/
@ApiStatus.Internal
Copy link
Member

Choose a reason for hiding this comment

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

Dunno if it makes sense to make it public, people might want to still use it instead of android.util.Log, but without the gradle plugin, what do you think @markushi @buenaflor ?

Copy link
Member

Choose a reason for hiding this comment

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

IMHO I wouldn't 😅 Since the config for minLogLevel lives within the gradle plugin, people calling the SentryLogcatAdapter will always generate breadcrumbs, even for e.g. verbose logging

@buenaflor buenaflor marked this pull request as ready for review March 27, 2023 09:42
@buenaflor buenaflor requested a review from markushi March 27, 2023 10:38
Copy link
Member

@markushi markushi left a comment

Choose a reason for hiding this comment

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

LGTM!

import kotlin.test.assertEquals

@RunWith(AndroidJUnit4::class)
class SentryLogcatAdapterTest {
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@buenaflor buenaflor merged commit 17ab223 into main Mar 28, 2023
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.

None yet

4 participants