-
-
Notifications
You must be signed in to change notification settings - Fork 22
Description
It should be as easy as possible to get started with session start/end and heartbeats. I think we should try to achieve one of these situations
- All I need to do is call
setUserIdentityanduseSessions(opt-in for session usage) - All I need to do is call
setUserIdentity(handle everyting automatically
Right now when useSessions is called, the session only really starts when another event comes in. For users that don't do full feature logging, or submit logging in common cases, this might cause the heartbeat plugin to start its interval later than the actual session start; and might event cause sessions to be missed altogether (when no exceptions occur, and nothing else gets logged).
I'm currently working around this by storing the user identity in sessionStorage. Whenever it changes I call submitSessionStart, whenever it changes from a non-null value to another value, I call submitSessionEnd on the old identity.
I also manually schedule heartbeats.
Sample code / workaround
function submitHeartbeat() {
var client = exceptionless.ExceptionlessClient.default;
var user = client.config.defaultData['@user'];
if (user && user.identity) {
var cachedId = sessionStorage.exceptionlessUserId;
if (cachedId !== user.identity) {
sessionStorage.exceptionlessUserId = user.identity;
// TODO: maybe check this also when user.identity is null
if (cachedId) {
// user changed from one value to another, call end with the old id
client.submitSessionEnd(cachedId)
}
// user changed. call start to create a new sessions
client.submitSessionStart();
} else {
// user didn't change -> heartbeat
client.submitSessionHeartbeat(user.identity);
}
}
}
setInterval(submitHeartbeat, 30000); // heartbeat every 30 seconds
submitHeartBeat(); // submit the start event right away