-
Notifications
You must be signed in to change notification settings - Fork 616
Implement a SessionSubscriber for Firebase Performance #6683
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
Changes from 3 commits
134398c
99a541e
09a9dec
f37408d
7654251
a0e9493
b3ba68d
5e5caf5
eb9856e
8efea1b
8e510b1
3145a71
afb0804
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.google.firebase.perf.session | ||
|
||
import com.google.firebase.perf.session.gauges.GaugeManager | ||
import com.google.firebase.perf.v1.ApplicationProcessState | ||
import com.google.firebase.sessions.api.SessionSubscriber | ||
import java.util.UUID | ||
|
||
class FirebasePerformanceSessionSubscriber(private val dataCollectionEnabled: Boolean) : | ||
SessionSubscriber { | ||
override val isDataCollectionEnabled: Boolean | ||
get() = dataCollectionEnabled | ||
|
||
override val sessionSubscriberName: SessionSubscriber.Name | ||
get() = SessionSubscriber.Name.PERFORMANCE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need the explicit getter. Can you just say something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you copied this from Crashlytics, it's likely a result of Java Kotlin interop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
override fun onSessionChanged(sessionDetails: SessionSubscriber.SessionDetails) { | ||
tejasd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val currentPerfSession = SessionManager.getInstance().perfSession() | ||
|
||
// A [PerfSession] was created before a session was started. | ||
if (currentPerfSession.aqsSessionId() == null) { | ||
currentPerfSession.setAQSId(sessionDetails) | ||
GaugeManager.getInstance() | ||
.logGaugeMetadata(currentPerfSession.aqsSessionId(), ApplicationProcessState.FOREGROUND) | ||
return | ||
} | ||
|
||
val updatedSession = PerfSession.createWithId(UUID.randomUUID().toString()) | ||
updatedSession.setAQSId(sessionDetails) | ||
SessionManager.getInstance().updatePerfSession(updatedSession) | ||
GaugeManager.getInstance() | ||
.logGaugeMetadata(updatedSession.aqsSessionId(), ApplicationProcessState.FOREGROUND) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import com.google.firebase.perf.util.Clock; | ||
import com.google.firebase.perf.util.Timer; | ||
import com.google.firebase.perf.v1.SessionVerbosity; | ||
import com.google.firebase.sessions.api.SessionSubscriber; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
|
@@ -31,6 +32,7 @@ public class PerfSession implements Parcelable { | |
|
||
private final String sessionId; | ||
private final Timer creationTime; | ||
@Nullable private String aqsSessionId; | ||
|
||
private boolean isGaugeAndEventCollectionEnabled = false; | ||
|
||
|
@@ -59,11 +61,23 @@ private PerfSession(@NonNull Parcel in) { | |
creationTime = in.readParcelable(Timer.class.getClassLoader()); | ||
} | ||
|
||
/** Returns the sessionId of the object. */ | ||
/** Returns the sessionId of the session. */ | ||
public String sessionId() { | ||
return sessionId; | ||
} | ||
|
||
/** Returns the AQS sessionId for the given session. */ | ||
public String aqsSessionId() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
return aqsSessionId; | ||
} | ||
|
||
/** Returns the AQS sessionId for the given session. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
public void setAQSId(SessionSubscriber.SessionDetails aqs) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want the Perf session to have the id of the current AQS session when the Perf session starts, but then allow AQS to have different sessions due to background foreground etc? Because Crashlytics will have the current AQS session id at crash time added to the report. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AQS knows the "first session id" and the current session id. If that is your concern, I think it's better to have the current aqs session id as the perf session id, and then if we need to do lookups we can join it to aqs data and know the first session id. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the behaviour a little compared to #6665. This retains the PerfSession ID as is, which is used to identify sessions for gauge collection. However, my plan is to use the AQS session ID to log the gauges. Whenever there is an AQS change, it will also result in a new PerfSession. |
||
if (aqsSessionId == null) { | ||
aqsSessionId = aqs.getSessionId(); | ||
} | ||
} | ||
|
||
/** | ||
* Returns a timer object that has been seeded with the system time at which the session began. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just put
override val isDataCollectionEnabled: Boolean
in the ctor?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.