Skip to content

Commit

Permalink
feat: add persistence flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Joozty committed Dec 9, 2024
1 parent 8484616 commit 6e5c1fd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
16 changes: 14 additions & 2 deletions packages/web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ export const SplunkRum: SplunkOtelWebType = {
},
)

if (['localStorage', 'cookie', undefined].includes(processedOptions.persistence)) {
diag.error(
'Invalid persistence flag: The value for "persistence" must be either "cookie", "localStorage", or omitted entirely.',
)
return
}

this._processedOptions = processedOptions

if (processedOptions.realm) {
Expand Down Expand Up @@ -359,7 +366,7 @@ export const SplunkRum: SplunkOtelWebType = {
eventTarget,
processedOptions.cookieDomain,
!!options._experimental_allSpansExtendSession,
processedOptions.useLocalStorage,
processedOptions.persistence === 'localStorage',
).deinit

const instrumentations = INSTRUMENTATIONS.map(({ Instrument, confKey, disable }) => {
Expand Down Expand Up @@ -522,7 +529,12 @@ export const SplunkRum: SplunkOtelWebType = {
}

if (this._processedOptions._experimental_allSpansExtendSession) {
updateSessionStatus({ forceStore: false, useLocalStorage: this._processedOptions.useLocalStorage ?? false })
updateSessionStatus({
forceStore: false,
useLocalStorage: this._processedOptions.persistence
? this._processedOptions.persistence === 'localStorage'
: false,
})
}
},
}
Expand Down
15 changes: 12 additions & 3 deletions packages/web/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ export interface SplunkOtelWebConfig {
/** Configuration for instrumentation modules. */
instrumentations?: SplunkOtelWebOptionsInstrumentations

/**
* Specifies where session data should be stored.
*
* Available options:
* - `'cookie'` (default): Session data will be stored in a browser cookie.
*
* - `'localStorage'`: Session data will be stored in the browser's localStorage.
*
* If not specified, `'cookie'` will be used as the default storage method.
*/
persistence?: 'cookie' | 'localStorage'

/**
* The name of your organization’s realm. Automatically configures beaconUrl with correct URL
*/
Expand All @@ -150,9 +162,6 @@ export interface SplunkOtelWebConfig {
*/
tracer?: WebTracerConfig

/** Use local storage to save session ID instead of cookie */
useLocalStorage?: boolean

/**
* Sets a value for the 'app.version' attribute
*/
Expand Down

0 comments on commit 6e5c1fd

Please sign in to comment.