diff --git a/packages/web/src/index.ts b/packages/web/src/index.ts index 7b0a924f..ebd162f8 100644 --- a/packages/web/src/index.ts +++ b/packages/web/src/index.ts @@ -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) { @@ -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 }) => { @@ -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, + }) } }, } diff --git a/packages/web/src/types/config.ts b/packages/web/src/types/config.ts index d855be89..21215bb7 100644 --- a/packages/web/src/types/config.ts +++ b/packages/web/src/types/config.ts @@ -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 */ @@ -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 */