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

Send events automatically on application onStop #77

Merged
merged 8 commits into from
Oct 16, 2023

Conversation

wzieba
Copy link
Collaborator

@wzieba wzieba commented Oct 11, 2023

Closes: #76

Description

This PR introduces a new behavior of automatically flushing the events queue using ProcessLifecycleOwner. This API is used in e.g. AppLifecycleIntegration.kt from Sentry Android SDK which works similarly to Parse.ly SDK in the sense of observing application lifecycle.

At the same time, this PR deprecates manual queue flushing.

How to test

Before

  1. Checkout main
  2. Install and run example app
  3. Tap "track URL"
  4. Move app to the background (don't kill)
  5. After ~20 seconds, you should see POST Data {"events": log

After

  1. Checkout this branch
  2. Install and run example app
  3. Tap "track URL"
  4. Move app to the background (don't kill)
  5. See that POST Data {"events": log is logged imidiatelly after app is moved to the background

Dependency change report

 \--- androidx.appcompat:appcompat:1.4.2
      +--- androidx.core:core:1.7.0
-     |    +--- androidx.lifecycle:lifecycle-runtime:2.3.1 -> 2.4.0
-     |    |    +--- androidx.arch.core:core-runtime:2.1.0
-     |    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
-     |    |    |    \--- androidx.arch.core:core-common:2.1.0
-     |    |    |         \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
-     |    |    +--- androidx.lifecycle:lifecycle-common:2.4.0
-     |    |    |    \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
-     |    |    +--- androidx.arch.core:core-common:2.1.0 (*)
-     |    |    \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    +--- androidx.lifecycle:lifecycle-runtime:2.3.1 -> 2.6.2
+     |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    |    +--- androidx.arch.core:core-common:2.2.0
+     |    |    |    \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    |    +--- androidx.arch.core:core-runtime:2.2.0
+     |    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    |    |    \--- androidx.arch.core:core-common:2.2.0 (*)
+     |    |    +--- androidx.lifecycle:lifecycle-common:2.6.2
+     |    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10
+     |    |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.10
+     |    |    |    |    \--- org.jetbrains:annotations:13.0
+     |    |    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4
+     |    |    |    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4
+     |    |    |    |    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4
+     |    |    |    |    |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.4
+     |    |    |    |    |         |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4 (c)
+     |    |    |    |    |         |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4 (c)
+     |    |    |    |    |         |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4 (c)
+     |    |    |    |    |         +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21 -> 1.8.10
+     |    |    |    |    |         |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 (*)
+     |    |    |    |    |         |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.10
+     |    |    |    |    |         |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 (*)
+     |    |    |    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.6.21 -> 1.8.10
+     |    |    |    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.4 (*)
+     |    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21 -> 1.8.10 (*)
+     |    |    |    +--- androidx.lifecycle:lifecycle-livedata:2.6.2 (c)
+     |    |    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.6.2 (c)
+     |    |    |    +--- androidx.lifecycle:lifecycle-process:2.6.2 (c)
+     |    |    |    +--- androidx.lifecycle:lifecycle-runtime:2.6.2 (c)
+     |    |    |    +--- androidx.lifecycle:lifecycle-viewmodel:2.6.2 (c)
+     |    |    |    \--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.2 (c)
+     |    |    +--- androidx.profileinstaller:profileinstaller:1.3.0
+     |    |    |    +--- androidx.annotation:annotation:1.2.0 -> 1.3.0
+     |    |    |    +--- androidx.concurrent:concurrent-futures:1.1.0
+     |    |    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    |    |    |    \--- com.google.guava:listenablefuture:1.0
+     |    |    |    +--- androidx.startup:startup-runtime:1.1.1
+     |    |    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    |    |    |    \--- androidx.tracing:tracing:1.0.0
+     |    |    |    |         \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    |    |    \--- com.google.guava:listenablefuture:1.0
+     |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 (*)
+     |    |    +--- androidx.lifecycle:lifecycle-common:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-process:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-viewmodel:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.2 (c)
+     |    |    \--- androidx.lifecycle:lifecycle-livedata:2.6.2 (c)
-     |    \--- androidx.concurrent:concurrent-futures:1.0.0
-     |         +--- com.google.guava:listenablefuture:1.0
-     |         \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    \--- androidx.concurrent:concurrent-futures:1.0.0 -> 1.1.0 (*)
      +--- androidx.activity:activity:1.2.4
-     |    +--- androidx.lifecycle:lifecycle-runtime:2.3.1 -> 2.4.0 (*)
+     |    +--- androidx.lifecycle:lifecycle-runtime:2.3.1 -> 2.6.2 (*)
-     |    +--- androidx.lifecycle:lifecycle-viewmodel:2.3.1
-     |    |    \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    +--- androidx.lifecycle:lifecycle-viewmodel:2.3.1 -> 2.6.2
+     |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 (*)
+     |    |    +--- androidx.lifecycle:lifecycle-common:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-process:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-runtime:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.2 (c)
+     |    |    \--- androidx.lifecycle:lifecycle-livedata:2.6.2 (c)
-     |    +--- androidx.savedstate:savedstate:1.1.0
-     |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
-     |    |    +--- androidx.arch.core:core-common:2.0.1 -> 2.1.0 (*)
-     |    |    \--- androidx.lifecycle:lifecycle-common:2.0.0 -> 2.4.0 (*)
+     |    +--- androidx.savedstate:savedstate:1.1.0 -> 1.2.1
+     |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    |    +--- androidx.arch.core:core-common:2.1.0 -> 2.2.0 (*)
+     |    |    +--- androidx.lifecycle:lifecycle-common:2.6.1 -> 2.6.2 (*)
+     |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 (*)
-     |    +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.1
-     |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
-     |    |    +--- androidx.savedstate:savedstate:1.1.0 (*)
-     |    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.3.1
-     |    |    |    +--- androidx.arch.core:core-common:2.1.0 (*)
-     |    |    |    +--- androidx.arch.core:core-runtime:2.1.0 (*)
-     |    |    |    \--- androidx.lifecycle:lifecycle-common:2.3.1 -> 2.4.0 (*)
-     |    |    \--- androidx.lifecycle:lifecycle-viewmodel:2.3.1 (*)
+     |    +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.1 -> 2.6.2
+     |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
+     |    |    +--- androidx.core:core-ktx:1.2.0
+     |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.41 -> 1.8.10 (*)
+     |    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    |    |    \--- androidx.core:core:1.2.0 -> 1.7.0 (*)
+     |    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.6.2
+     |    |    |    +--- androidx.arch.core:core-common:2.1.0 -> 2.2.0 (*)
+     |    |    |    +--- androidx.arch.core:core-runtime:2.1.0 -> 2.2.0 (*)
+     |    |    |    +--- androidx.lifecycle:lifecycle-common:2.6.2 (*)
+     |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 (*)
+     |    |    |    +--- androidx.lifecycle:lifecycle-common:2.6.2 (c)
+     |    |    |    +--- androidx.lifecycle:lifecycle-livedata:2.6.2 (c)
+     |    |    |    +--- androidx.lifecycle:lifecycle-process:2.6.2 (c)
+     |    |    |    +--- androidx.lifecycle:lifecycle-runtime:2.6.2 (c)
+     |    |    |    +--- androidx.lifecycle:lifecycle-viewmodel:2.6.2 (c)
+     |    |    |    \--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-viewmodel:2.6.2 (*)
+     |    |    +--- androidx.savedstate:savedstate:1.2.1 (*)
+     |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 (*)
+     |    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4 (*)
+     |    |    +--- androidx.lifecycle:lifecycle-common:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-process:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-runtime:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-viewmodel:2.6.2 (c)
+     |    |    \--- androidx.lifecycle:lifecycle-livedata:2.6.2 (c)
-     |    \--- androidx.tracing:tracing:1.0.0
-     |         \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
+     |    \--- androidx.tracing:tracing:1.0.0 (*)
      +--- androidx.fragment:fragment:1.3.6
      |    +--- androidx.loader:loader:1.0.0
-     |    |    +--- androidx.lifecycle:lifecycle-livedata:2.0.0
-     |    |    |    +--- androidx.arch.core:core-runtime:2.0.0 -> 2.1.0 (*)
-     |    |    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.0.0 -> 2.3.1 (*)
-     |    |    |    \--- androidx.arch.core:core-common:2.0.0 -> 2.1.0 (*)
+     |    |    +--- androidx.lifecycle:lifecycle-livedata:2.0.0 -> 2.6.2
+     |    |    |    +--- androidx.arch.core:core-common:2.1.0 -> 2.2.0 (*)
+     |    |    |    +--- androidx.arch.core:core-runtime:2.1.0 -> 2.2.0 (*)
+     |    |    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.6.2 (*)
+     |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 (*)
+     |    |    |    +--- androidx.lifecycle:lifecycle-common:2.6.2 (c)
+     |    |    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.6.2 (c)
+     |    |    |    +--- androidx.lifecycle:lifecycle-process:2.6.2 (c)
+     |    |    |    +--- androidx.lifecycle:lifecycle-runtime:2.6.2 (c)
+     |    |    |    +--- androidx.lifecycle:lifecycle-viewmodel:2.6.2 (c)
+     |    |    |    \--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.2 (c)
-     |    |    \--- androidx.lifecycle:lifecycle-viewmodel:2.0.0 -> 2.3.1 (*)
+     |    |    \--- androidx.lifecycle:lifecycle-viewmodel:2.0.0 -> 2.6.2 (*)
-     |    +--- androidx.lifecycle:lifecycle-livedata-core:2.3.1 (*)
+     |    +--- androidx.lifecycle:lifecycle-livedata-core:2.3.1 -> 2.6.2 (*)
-     |    +--- androidx.lifecycle:lifecycle-viewmodel:2.3.1 (*)
+     |    +--- androidx.lifecycle:lifecycle-viewmodel:2.3.1 -> 2.6.2 (*)
-     |    +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.1 (*)
+     |    +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.1 -> 2.6.2 (*)
-     |    \--- androidx.savedstate:savedstate:1.1.0 (*)
+     |    \--- androidx.savedstate:savedstate:1.1.0 -> 1.2.1 (*)
-     +--- androidx.savedstate:savedstate:1.1.0 (*)
+     +--- androidx.savedstate:savedstate:1.1.0 -> 1.2.1 (*)
      +--- androidx.emoji2:emoji2:1.0.0
-     |    +--- androidx.lifecycle:lifecycle-process:2.4.0
-     |    |    +--- androidx.lifecycle:lifecycle-runtime:2.4.0 (*)
-     |    |    \--- androidx.startup:startup-runtime:1.0.0
-     |    |         +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
-     |    |         \--- androidx.tracing:tracing:1.0.0 (*)
+     |    +--- androidx.lifecycle:lifecycle-process:2.4.0 -> 2.6.2
+     |    |    +--- androidx.annotation:annotation:1.2.0 -> 1.3.0
+     |    |    +--- androidx.lifecycle:lifecycle-runtime:2.6.2 (*)
+     |    |    +--- androidx.startup:startup-runtime:1.1.1 (*)
+     |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 (*)
+     |    |    +--- androidx.lifecycle:lifecycle-runtime:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-viewmodel:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.6.2 (c)
+     |    |    +--- androidx.lifecycle:lifecycle-common:2.6.2 (c)
+     |    |    \--- androidx.lifecycle:lifecycle-livedata:2.6.2 (c)
-     |    \--- androidx.startup:startup-runtime:1.0.0 (*)
+     |    \--- androidx.startup:startup-runtime:1.0.0 -> 1.1.1 (*)
-     +--- androidx.lifecycle:lifecycle-runtime:2.3.1 -> 2.4.0 (*)
+     +--- androidx.lifecycle:lifecycle-runtime:2.3.1 -> 2.6.2 (*)
-     \--- androidx.lifecycle:lifecycle-viewmodel:2.3.1 (*)
+     \--- androidx.lifecycle:lifecycle-viewmodel:2.3.1 -> 2.6.2 (*)
++--- androidx.lifecycle:lifecycle-process:2.6.2 (*)
++--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.10 (c)
+\--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.10 (c)

The added constraint of `kotlin-stdlib-jdk7` and `kotlin-stdlib-jdk8` ensures lack of "duplicated class" conflicts. This is required due to unification of jdk7 and jdk8 libraries by Kotlin. See details: https://kotlinlang.org/docs/gradle-configure-project.html#other-ways-to-align-versions
The lint bundled with AGP 7.2.2 has a bug which reports false-positive errors: https://issuetracker.google.com/issues/185418482#comment31
@wzieba wzieba force-pushed the flush_events_on_app_on_stop branch from 183ecb2 to 605c535 Compare October 11, 2023 13:25
To fix: `LintClient has been compiled by a more recent version of the
Java Runtime (class file version 61.0), this version of the Java Runtime
only recognizes class file versions up to 55.0` on CI.
@wzieba wzieba requested a review from ParaskP7 October 11, 2023 13:33
@wzieba wzieba marked this pull request as ready for review October 11, 2023 13:35
@wzieba wzieba marked this pull request as draft October 11, 2023 18:59
@wzieba
Copy link
Collaborator Author

wzieba commented Oct 11, 2023

Sorry, it's still WIP @ParaskP7 . I'll ping you again when it'll be ready 👍 False alarm, actually it's good to go 👍

@wzieba wzieba marked this pull request as ready for review October 11, 2023 19:05
@ParaskP7 ParaskP7 self-assigned this Oct 12, 2023
@wzieba wzieba mentioned this pull request Oct 12, 2023
Copy link
Collaborator

@ParaskP7 ParaskP7 left a comment

Choose a reason for hiding this comment

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

👋 @wzieba !

I have reviewed and tested this PR as per the instructions, everything works as expected, good job! 🌟


I have left one question (❓), a suggestion (💡) and one minor (🔍) comment for you to consider. I am not going to approve this PR atm and until we discuss on that question (❓) of mine, but at the same time, I don't wan't to request changes as I am not sure about it too, thus I'll be just commenting for now.

.github/workflows/publish.yml Show resolved Hide resolved
parsely/build.gradle Show resolved Hide resolved
@wzieba wzieba requested a review from ParaskP7 October 16, 2023 10:36
@ParaskP7
Copy link
Collaborator

👋 @wzieba !

Took another look at the extra 2 commits added, thanks and everything LGTM, feel free to merge this when you're ready! 🚀

@wzieba wzieba merged commit 7307e21 into main Oct 16, 2023
1 check passed
@wzieba wzieba deleted the flush_events_on_app_on_stop branch October 16, 2023 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attach to application process to flush events when client application goes to background
2 participants