Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

automatic breadcrumbs for app, activity and sessions lifecycles and system events #348

Merged
merged 21 commits into from
Apr 30, 2020

Conversation

marandaneto
Copy link
Contributor

@marandaneto marandaneto commented Apr 8, 2020

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

automatic breadcrumbs for app, activity and sessions lifecycles and system events

💡 Motivation and Context

we'd like to collect automatic breadcrumbs
fixes #210

💚 How did you test it?

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • All tests passing

🔮 Next steps

@mrmitew
Copy link

mrmitew commented Apr 16, 2020

@marandaneto Did you take into account that if android build has been obfuscated (e.g. with ProGuard or DexGuard), activity names in the breadcrumb messages will look like gibberish and won't be retraced?

Also, is there a way to disable the integration once this is merged?

@marandaneto
Copy link
Contributor Author

marandaneto commented Apr 16, 2020

@marandaneto Did you take into account that if android build has been obfuscated (e.g. with ProGuard or DexGuard), activity names in the breadcrumb messages will look like gibberish and won't be retraced?

Also, is there a way to disable the integration once this is merged?

we are gonna probably extract this module as a new maven package (android aar) and ship it with a proguard rule for that, keeping Activity names.
the other way would be just to add breadcrumbs yourselves with your own activity identifies.

not sure if we are gonna demangle the breadcrumbs as well, I'll check this internally.

@mrmitew
Copy link

mrmitew commented Apr 16, 2020

It would be nice if you could demangle the class names in the breadcrumbs as a general feature.

Putting a rule for keeping activity names could be a nasty surprise for some people though. In my opinion it will be better as an opt-in feature, so having it as a separate artifact makes sense indeed.

@marandaneto
Copy link
Contributor Author

It would be nice if you could demangle the class names in the breadcrumbs as a general feature.

Putting a rule for keeping activity names could be a nasty surprise for some people though. In my opinion it will be better as an opt-in feature, so having it as a separate artifact makes sense indeed.

yes, I agree, as I said, it's gonna be a separated maven package, so generally opt-in, I'll update you on that, thanks for the tip.

@codecov-io
Copy link

codecov-io commented Apr 20, 2020

Codecov Report

Merging #348 into master will decrease coverage by 0.04%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #348      +/-   ##
============================================
- Coverage     58.89%   58.84%   -0.05%     
  Complexity      758      758              
============================================
  Files            87       87              
  Lines          3540     3543       +3     
  Branches        341      341              
============================================
  Hits           2085     2085              
- Misses         1302     1305       +3     
  Partials        153      153              
Impacted Files Coverage Δ Complexity Δ
.../src/main/java/io/sentry/core/protocol/Device.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bcec4d1...7811042. Read the comment docs.

Comment on lines 178 to 191
// TODO: should we log the params? sometimes its necessary eg
// ACTION_AIRPLANE_MODE_CHANGED
// its a single action with 2 states that differs on extras
final Bundle extras = intent.getExtras();
final Map<String, String> newExtras = new HashMap<>();
if (extras != null && !extras.isEmpty()) {
for (String item : extras.keySet()) {
try {
newExtras.put(item, extras.get(item).toString());
} catch (Exception ignored) {
}
}
}
breadcrumb.setData("extras", newExtras);
Copy link
Contributor Author

@marandaneto marandaneto Apr 21, 2020

Choose a reason for hiding this comment

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

this is trick, each broadcast has its own extras, we could send them all as I do now, but there are a lot of garbage too.
the other way would be to only send the useful extras for each broadcast.
the thing is, docs for extras are not great and it'd take some time to find the right keys.

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave it as you did and see the feedback. If we only add stuff manually we could be missing things and there's the extra work/maintenance

@marandaneto
Copy link
Contributor Author

It would be nice if you could demangle the class names in the breadcrumbs as a general feature.

Putting a rule for keeping activity names could be a nasty surprise for some people though. In my opinion it will be better as an opt-in feature, so having it as a separate artifact makes sense indeed.

so it seems that proguard-android-optimize.txt already does it by default, Activity names are never minified as far as I can see

@marandaneto marandaneto marked this pull request as ready for review April 22, 2020 14:11
@marandaneto marandaneto changed the title automatic breadcrumbs automatic breadcrumbs for app, activity and sessions lifecycles and system events Apr 22, 2020
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 left suggestions and some nits -> :shipit: !

Comment on lines +73 to 74
addSessionBreadcrumb("end");
hub.endSession();
Copy link
Member

Choose a reason for hiding this comment

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

We could pass here the session duration:

Suggested change
addSessionBreadcrumb("end");
hub.endSession();
hub.endSession();
addSessionBreadcrumb("end", hub.getDuration());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there's no API for that right now, but yeah we could enrich these breadcrumbs later on

Comment on lines 178 to 191
// TODO: should we log the params? sometimes its necessary eg
// ACTION_AIRPLANE_MODE_CHANGED
// its a single action with 2 states that differs on extras
final Bundle extras = intent.getExtras();
final Map<String, String> newExtras = new HashMap<>();
if (extras != null && !extras.isEmpty()) {
for (String item : extras.keySet()) {
try {
newExtras.put(item, extras.get(item).toString());
} catch (Exception ignored) {
}
}
}
breadcrumb.setData("extras", newExtras);
Copy link
Member

Choose a reason for hiding this comment

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

Let's leave it as you did and see the feedback. If we only add stuff manually we could be missing things and there's the extra work/maintenance

@ninniuz
Copy link

ninniuz commented Apr 23, 2020

@marandaneto Did you take into account that if android build has been obfuscated (e.g. with ProGuard or DexGuard), activity names in the breadcrumb messages will look like gibberish and won't be retraced?
Also, is there a way to disable the integration once this is merged?

we are gonna probably extract this module as a new maven package (android aar) and ship it with a proguard rule for that, keeping Activity names.
the other way would be just to add breadcrumbs yourselves with your own activity identifies.

not sure if we are gonna demangle the breadcrumbs as well, I'll check this internally.

AFAIK Activity names are kept if they are found in the AndroidManifest.xml file (AAPT generates rules for this in intermediates/aapt_proguard_file), together with Services and BroadcastReceivers, as otherwise the OS would not be able to even launch any of those components. WDYT?

@marandaneto
Copy link
Contributor Author

@marandaneto Did you take into account that if android build has been obfuscated (e.g. with ProGuard or DexGuard), activity names in the breadcrumb messages will look like gibberish and won't be retraced?
Also, is there a way to disable the integration once this is merged?

we are gonna probably extract this module as a new maven package (android aar) and ship it with a proguard rule for that, keeping Activity names.
the other way would be just to add breadcrumbs yourselves with your own activity identifies.
not sure if we are gonna demangle the breadcrumbs as well, I'll check this internally.

AFAIK Activity names are kept if they are found in the AndroidManifest.xml file (AAPT generates rules for this in intermediates/aapt_proguard_file), together with Services and BroadcastReceivers, as otherwise the OS would not be able to even launch any of those components. WDYT?

yes,

@marandaneto Did you take into account that if android build has been obfuscated (e.g. with ProGuard or DexGuard), activity names in the breadcrumb messages will look like gibberish and won't be retraced?
Also, is there a way to disable the integration once this is merged?

we are gonna probably extract this module as a new maven package (android aar) and ship it with a proguard rule for that, keeping Activity names.
the other way would be just to add breadcrumbs yourselves with your own activity identifies.
not sure if we are gonna demangle the breadcrumbs as well, I'll check this internally.

AFAIK Activity names are kept if they are found in the AndroidManifest.xml file (AAPT generates rules for this in intermediates/aapt_proguard_file), together with Services and BroadcastReceivers, as otherwise the OS would not be able to even launch any of those components. WDYT?

can confirm, I was suspecting because of either proguard-android-optimize.txt or just Proguard/R8 by default, but it's aapt, TIL :D thanks.

@marandaneto marandaneto merged commit 4665894 into master Apr 30, 2020
@marandaneto marandaneto deleted the enha/automatic_breadcrumbs branch April 30, 2020 11:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No default breadcrumbs recorded.
6 participants