Skip to content

send session event based on data collection and setting config #6852

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

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import kotlinx.coroutines.launch
internal fun interface SessionFirelogPublisher {

/** Asynchronously logs the session represented by the given [SessionDetails] to Firelog. */
fun logSession(sessionDetails: SessionDetails)
fun mayLogSession(sessionDetails: SessionDetails)

companion object {
val instance: SessionFirelogPublisher
Expand Down Expand Up @@ -64,7 +64,7 @@ constructor(
* This will pull all the necessary information about the device in order to create a full
* [SessionEvent], and then upload that through the Firelog interface.
*/
override fun logSession(sessionDetails: SessionDetails) {
override fun mayLogSession(sessionDetails: SessionDetails) {
CoroutineScope(backgroundDispatcher).launch {
if (shouldLogSession()) {
val installationId = InstallationId.create(firebaseInstallations)
Expand Down Expand Up @@ -94,13 +94,16 @@ constructor(

/** Determines if the SDK should log a session to Firelog. */
private suspend fun shouldLogSession(): Boolean {
Log.d(TAG, "Data Collection is enabled for at least one Subscriber")

val subscribers = FirebaseSessionsDependencies.getRegisteredSubscribers()
if (subscribers.values.none { it.isDataCollectionEnabled }) {
Log.d(TAG, "Sessions SDK disabled through data collection. Events will not be sent.")
return false
}
// This will cause remote settings to be fetched if the cache is expired.
sessionSettings.updateSettings()

if (!sessionSettings.sessionsEnabled) {
Log.d(TAG, "Sessions SDK disabled. Events will not be sent.")
Log.d(TAG, "Sessions SDK disabled through settings API. Events will not be sent.")
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ constructor(
}
}
}

// TODO(mrober): If data collection is enabled for at least one subscriber...
// https://github.com/firebase/firebase-android-sdk/blob/a53ab64150608c2eb3eafb17d81dfe217687d955/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/FirebaseSessions.kt#L110
sessionFirelogPublisher.logSession(sessionDetails = newSessionDetails)
sessionFirelogPublisher.mayLogSession(sessionDetails = newSessionDetails)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class SessionFirelogPublisherTest {
)

// Construct an event with no fid set.
publisher.logSession(TestSessionEventData.TEST_SESSION_DETAILS)
publisher.mayLogSession(TestSessionEventData.TEST_SESSION_DETAILS)

runCurrent()

Expand Down Expand Up @@ -105,7 +105,7 @@ class SessionFirelogPublisherTest {
)

// Construct an event with no fid set.
publisher.logSession(TestSessionEventData.TEST_SESSION_DETAILS)
publisher.mayLogSession(TestSessionEventData.TEST_SESSION_DETAILS)

runCurrent()

Expand Down Expand Up @@ -134,7 +134,7 @@ class SessionFirelogPublisherTest {
)

// Construct an event with no fid set.
publisher.logSession(TestSessionEventData.TEST_SESSION_DETAILS)
publisher.mayLogSession(TestSessionEventData.TEST_SESSION_DETAILS)

runCurrent()

Expand Down
Loading