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

Add SessionEvent data class #4763

Merged
merged 6 commits into from
Mar 13, 2023
Merged

Add SessionEvent data class #4763

merged 6 commits into from
Mar 13, 2023

Conversation

mrober
Copy link
Contributor

@mrober mrober commented Mar 9, 2023

Add SessionEvent data class and start populating some of the fields.

Renamed the internal class to SessionState to keep it separated from the data classes to be serialized.

#no-changelog

@google-oss-bot
Copy link
Contributor

1 Warning
⚠️ Did you forget to add a changelog entry? (Add the 'no-changelog' label to the PR to silence this warning.)

Generated by 🚫 Danger

@mrober mrober requested a review from davidmotson March 9, 2023 20:10
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 9, 2023

Coverage Report 1

Affected Products

  • firebase-sessions

    Overall coverage changed from ? (47dcc85) to 0.00% (5473f98) by ?.

    FilenameBase (47dcc85)Merge (5473f98)Diff
    FirebaseSessions.kt?0.00%?
    FirebaseSessionsRegistrar.kt?0.00%?
    SessionEvent.kt?0.00%?
    SessionGenerator.kt?0.00%?
    SessionInitiator.kt?0.00%?
    WallClock.kt?0.00%?

Test Logs

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2023

Unit Test Results

  6 files    6 suites   0s ⏱️
  9 tests   9 ✔️ 0 💤 0
18 runs  18 ✔️ 0 💤 0

Results for commit b3fe273.

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 9, 2023

Size Report 1

Affected Products

  • base

    TypeBase (47dcc85)Merge (5473f98)Diff
    apk (aggressive)?8.39 kB? (?)
    apk (release)?8.65 kB? (?)
  • firebase-annotations

    TypeBase (47dcc85)Merge (5473f98)Diff
    apk (aggressive)?8.39 kB? (?)
    apk (release)?9.46 kB? (?)
  • firebase-common

    TypeBase (47dcc85)Merge (5473f98)Diff
    aar?75.3 kB? (?)
    apk (aggressive)?111 kB? (?)
    apk (release)?1.26 MB? (?)
  • firebase-common-ktx

    TypeBase (47dcc85)Merge (5473f98)Diff
    aar?13.2 kB? (?)
    apk (aggressive)?123 kB? (?)
    apk (release)?1.64 MB? (?)
  • firebase-components

    TypeBase (47dcc85)Merge (5473f98)Diff
    aar?44.9 kB? (?)
    apk (aggressive)?23.1 kB? (?)
    apk (release)?596 kB? (?)
  • firebase-sessions

    TypeBase (47dcc85)Merge (5473f98)Diff
    aar?21.9 kB? (?)
    apk (aggressive)?136 kB? (?)
    apk (release)?1.65 MB? (?)

Test Logs

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

Log.i(TAG, "Initiate session start")
val sessionState = sessionGenerator.generateNewSession()
val sessionEvent =
SessionEvent(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we encapsulate this in a class or function that generates the event based on the sessionState input? Eventually this will expand a lot once we have different classes to populate the session.

Copy link
Contributor

Choose a reason for hiding this comment

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

This constructor may be a constructor on SessionEvent itself if that's possible for data classes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only for the data class ctor to take it, is to make it a property which seems ugly. So I make a function instead.

@mrober mrober requested a review from visumickey March 10, 2023 16:58
Copy link
Contributor

@visumickey visumickey left a comment

Choose a reason for hiding this comment

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

Let's add no change log hash tag to the description.

Comment on lines +43 to +44
val sessionState = sessionGenerator.generateNewSession()
val sessionEvent = SessionEvent.sessionStart(sessionState)
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 very close to the iOS implementation. Just to confirm, here is how I think the current piece of code would evolve for event dispatch. Please let me know if you think otherwise.

  1. Session Generator is stateful and it returns sessions related information for the current session event. (ID, Index, previous ID, parent ID and likes)
    2.SessionEvent class takes those details to fill in more details
  2. Firebase Sessions later embellishes the event with details like data collection state.
  3. Firebase Sessions will use Firelog services to hand over the event.

Curious as to where would the config layer fit in here and how would sampling be done to either capture or skip an event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, and for sampling we'll handle that when we do Settings. We will pass in something like collectEvents = shouldCollectEvents(...) to the SessionGenerator.

package com.google.firebase.sessions

/**
* Contains the relevant information around an App Quality Session.
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets not call it "App Quality Session" yet. Let's reference it as "Firebase Session Start Event".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Called it "Firebase Session Event"

Comment on lines +27 to +28
/** The type of event being reported. */
val eventType: EventType,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to remember this state? It is already a part of SessionStartEvent, can we use it from there? I'm trying to avoid multiple source of truth here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is there to match the proto 1:1, this data class will be serialized and sent to firelog.

* https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseSessions/ProtoSupport/Protos/sessions.proto
*/
// TODO(mrober): Add and populate all fields from sessions.proto
internal data class SessionEvent(
Copy link
Contributor

Choose a reason for hiding this comment

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

Just confirming that this class will eventually do more things than what it is today: Add more App related fields to the session event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup this will eventually have all the fields from the proto.

*
* @hide
*/
internal class SessionGenerator(collectEvents: Boolean) {
internal class SessionGenerator(private var collectEvents: Boolean) {
Copy link
Contributor

Choose a reason for hiding this comment

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

wow! We can call parameters with access protectors? private var is so cool! TIL!

Copy link
Contributor

@samedson samedson left a comment

Choose a reason for hiding this comment

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

LGTM

@mrober mrober merged commit 667a902 into firebase-sessions Mar 13, 2023
@mrober mrober deleted the sessions-event branch March 13, 2023 15:27
@firebase firebase locked and limited conversation to collaborators Apr 13, 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