Skip to content

Fix encoding for Session Events #4870

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 4 commits into from
Apr 11, 2023
Merged

Fix encoding for Session Events #4870

merged 4 commits into from
Apr 11, 2023

Conversation

samedson
Copy link
Contributor

@samedson samedson commented Apr 6, 2023

  • Also updates logging to log the Encoded Session Event instead of the data object (only in debug mode) so that we can catch encoding issues

TODO (in a follow up)

  • Make sure we're setting the time correctly
  • Fill in Device Name

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 6, 2023

Coverage Report 1

Affected Products

  • firebase-sessions

    Overall coverage changed from ? (f7fff6b) to 55.14% (a47e519) by ?.

    12 individual files with coverage change

    FilenameBase (f7fff6b)Merge (a47e519)Diff
    ApplicationInfo.kt?100.00%?
    EventGDTLogger.kt?75.00%?
    FirebaseSessions.kt?0.00%?
    FirebaseSessionsEarly.kt?0.00%?
    FirebaseSessionsRegistrar.kt?0.00%?
    SessionCoordinator.kt?76.47%?
    SessionEvent.kt?100.00%?
    SessionEvents.kt?97.06%?
    SessionGenerator.kt?22.73%?
    SessionInitiator.kt?0.00%?
    SessionsSettings.kt?0.00%?
    WallClock.kt?0.00%?

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/ofHKRumnQd.html

@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2023

Unit Test Results

16 files  16 suites   25s ⏱️
17 tests 17 ✔️ 0 💤 0
34 runs  34 ✔️ 0 💤 0

Results for commit 482c401.

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 6, 2023

Size Report 1

Affected Products

  • base

    TypeBase (f7fff6b)Merge (a47e519)Diff
    apk (aggressive)?8.39 kB? (?)
    apk (release)?8.65 kB? (?)
  • firebase-datatransport

    TypeBase (f7fff6b)Merge (a47e519)Diff
    aar?4.94 kB? (?)
    apk (aggressive)?161 kB? (?)
    apk (release)?1.35 MB? (?)
  • firebase-sessions

    TypeBase (f7fff6b)Merge (a47e519)Diff
    aar?44.2 kB? (?)
    apk (aggressive)?251 kB? (?)
    apk (release)?1.77 MB? (?)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/HVQpsMEJ62.html

@firebase firebase deleted a comment from google-oss-bot Apr 10, 2023
@samedson samedson requested review from mrober and visumickey April 10, 2023 19:25
@samedson samedson changed the title Fix encoding for other fields Fix encoding for Session Events Apr 10, 2023
@visumickey
Copy link
Contributor

Are these TODOs still to be done or are they verified?

@@ -53,11 +54,14 @@ internal class EventGDTLogger(private val transportFactoryProvider: Provider<Tra
}

private fun encode(value: SessionEvent): ByteArray {
return SessionEvents.SESSION_EVENT_ENCODER.encode(value).toByteArray()
val jsonEvent = SessionEvents.SESSION_EVENT_ENCODER.encode(value)
Log.d(TAG, "Encoded Session Start event $jsonEvent")
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious if you want to leave this as Debug or Verbose?

Copy link
Contributor Author

@samedson samedson Apr 10, 2023

Choose a reason for hiding this comment

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

I'm down for Verbose - I wasn't sure when we use debug vs verbose

}

companion object {
// TODO What do we put for the AQS Log Source
private const val TAG = "EventGDTLogger"
Copy link
Contributor

Choose a reason for hiding this comment

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

How would the log message look with this TAG? Would it contain FirebaseSessions anywhere? If not, I would recommend prefixing the tag with the library name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like: V/EventGDTLogger: Encoded Session Start event {"event_type":1...

We've been doing it like this so I'll update this file and others

internal data class DataCollectionStatus(
val performance: DataCollectionState = DataCollectionState.COLLECTION_ENABLED,
val crashlytics: DataCollectionState = DataCollectionState.COLLECTION_ENABLED,
val sessionSamplingRate: Double = 1.0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting to have sessionSamplingRate inside the DataCollectionStatus. I was thinking DataCollectionStatus is for external dependencies and used sessionSamplingRate as a remote config. But this looks a bit different from that intention. Curious to hear your rationale to have session sampling rate inside DataCollectionStatus.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +74 to +75
val performance: DataCollectionState = DataCollectionState.COLLECTION_ENABLED,
val crashlytics: DataCollectionState = DataCollectionState.COLLECTION_ENABLED,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the default COLLECTION_ENABLED (for now?)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm putting it like this so it looks right in our data but we'll need to change this when we integrate with the product SDKs

@@ -32,7 +32,8 @@ class SessionEventTest {
val sessionEvent =
SessionEvents.startSession(
FakeFirebaseApp.fakeFirebaseApp(),
TestSessionEventData.TEST_SESSION_DETAILS
TestSessionEventData.TEST_SESSION_DETAILS,
TestSessionEventData.TEST_SESSION_TIMESTAMP_US,
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why the event timestamp is configurable? Can we leave it as a constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

startSession is also used by the SDK. When it leaves off the parameter it uses the current time. Since we can't have the time be different for every test I made it optional to just set the time

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine for now, but we need a proper time solution at some point. We can't just use go/javatime because it requires Android API level 26+. Maybe we can add another function in WallClock and try to abstract this away?

@samedson
Copy link
Contributor Author

Are these TODOs still to be done or are they verified?

I'm doing the TODOs in a follow up PR

@samedson samedson merged commit 229d597 into firebase-sessions Apr 11, 2023
@samedson samedson deleted the fix-encoding branch April 11, 2023 14:12
@firebase firebase locked and limited conversation to collaborators May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants