-
Notifications
You must be signed in to change notification settings - Fork 31
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
fix: do not extend session from discarded session replay spans #939
Conversation
4da363c
to
420bd23
Compare
@@ -206,6 +204,13 @@ const SplunkRumRecorder = { | |||
return | |||
} | |||
|
|||
// We need to call it here before another getSessionID call. This will create a new session | |||
// if the previous one was expired | |||
if (SplunkRum._internalOnExternalSpanCreated) { |
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.
The hook is called only when we are sure the session recorder chunk is not discarded.
if (hasNativeSessionId()) { | ||
return window['SplunkRumNative'].getNativeSessionId() | ||
} | ||
|
||
return rumSessionId | ||
return getCurrentSessionState({ useLocalStorage, forceStoreRead: true })?.id |
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.
When calling getRumSessionId
we always read the fresh value from storage. Explained in the PR descriptions.
@@ -45,7 +45,6 @@ import { context } from '@opentelemetry/api' | |||
with setting cookies, checking for inactivity, etc. | |||
*/ | |||
|
|||
let rumSessionId: SessionId | undefined |
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.
we no longer have this global variable
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.
👍
Description
This update resolves issues with the
_experimental_allSpansExtendSession
flag, which did not work correctly with the session recorder. Spans created via the session recorder improperly extended sessions in a backgrounded tab.Issue:
SplunkRum._internalOnExternalSpanCreated()
, which results in either starting a new session or artificially extending the previous session.The changes in this update ensure that the callback is invoked only after confirming that the events will not be discarded.
Possible Breaking Changes
The
SplunkRum.getSessionID()
method can return undefined between sessions. It is already typed that way (string
|undefined
) but the previous implementation would always return string unless agent is not initialized.Previously, it would always return a string, even if the session was no longer active, by incorrectly referencing the previous session. With this change, if there is no activity and no active session, it will return
undefined
.Spans initiate sessions, so if you call
getSessionID()
between sessions and there is no activity, it will correctly returnundefined
.Type of change
Delete options that are not relevant.
How has this been tested?
Delete options that are not relevant.