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

Use onCreate invocation to denote Activity init start time #820

Merged
merged 3 commits into from
May 13, 2024

Conversation

bidetofevil
Copy link
Collaborator

@bidetofevil bidetofevil commented May 7, 2024

Goal

In production, we are seeing a small minority of cases where there is a big gap between when onActivityPreCreated was invoked and when onActivityStart() was invoked. This could be a case of these being two separate activities or instances, or there are cases when the activity creation and starting stage can be paused.

In order to improve the trace and diagnose what's really going on, I changed the trace to use the onCreate time rather than the preCreate time, which is how it works on Android 9 or earlier, as preCreate is not a thing on those API versions. We also explicitly log the pre-create and post-create times as attributes for further debugging if this doesn't end up addressing the problem.

As well as the fix, I tweaked the implementation of the trace logging component (AppStartupTraceEmitter) so it's more streamlined, logs the name of the activity being displayed, removed the emb- prefix on attributes, and extracted the public interface into an interface so i can more easily test the StartupTracker by faking that.

In additional, I added more tests to verify the startup trace being logged properly as well as the StartupTracker consuming lifecycle events properly. I couldn't add test to verify the render due to the limitations of Roboletric, so I've left that alone for now. I've spent way too much time on this already....

Testing

Updated Roboletric to the latest stable version so I can test with U as well as added the modified the appropriate tests.

Copy link
Collaborator Author

bidetofevil commented May 7, 2024

Copy link

codecov bot commented May 7, 2024

Codecov Report

Attention: Patch coverage is 89.36170% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 81.03%. Comparing base (4ad54a8) to head (b15618f).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #820      +/-   ##
==========================================
+ Coverage   80.99%   81.03%   +0.04%     
==========================================
  Files         426      427       +1     
  Lines       11414    11434      +20     
  Branches     1690     1698       +8     
==========================================
+ Hits         9245     9266      +21     
  Misses       1458     1458              
+ Partials      711      710       -1     
Files Coverage Δ
...racesdk/capture/startup/AppStartupDataCollector.kt 100.00% <100.00%> (ø)
...d/embracesdk/injection/DataCaptureServiceModule.kt 98.07% <100.00%> (ø)
...droid/embracesdk/capture/startup/StartupTracker.kt 45.71% <94.73%> (+18.59%) ⬆️
...bracesdk/capture/startup/AppStartupTraceEmitter.kt 71.75% <77.77%> (-1.55%) ⬇️

... and 1 file with indirect coverage changes

@bidetofevil bidetofevil marked this pull request as ready for review May 9, 2024 22:26
@bidetofevil bidetofevil requested a review from a team as a code owner May 9, 2024 22:26
Copy link
Contributor

@fractalwrench fractalwrench left a comment

Choose a reason for hiding this comment

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

LGTM

@bidetofevil bidetofevil merged commit 087ac14 into master May 13, 2024
6 checks passed
@bidetofevil bidetofevil deleted the hho/improve-startup branch May 13, 2024 15:42
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

2 participants