Commit 861bed8 1 parent 35fe31c commit 861bed8 Copy full SHA for 861bed8
File tree 3 files changed +19
-10
lines changed
3 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -434,10 +434,13 @@ export const SplunkRum: SplunkOtelWebType = {
434
434
// Splunk specific attributes
435
435
'splunk.rumVersion': VERSION,
436
436
'splunk.scriptInstance': instanceId,
437
- 'browser.instance.id': BrowserInstanceService.id,
438
437
'app': applicationName,
439
438
};
440
439
440
+ if(BrowserInstanceService.id) {
441
+ resourceAttrs['browser.instance.id'] = BrowserInstanceService.id
442
+ }
443
+
441
444
const syntheticsRunId = getSyntheticsRunId();
442
445
if (syntheticsRunId) {
443
446
resourceAttrs[SYNTHETICS_RUN_ID_ATTRIBUTE] = syntheticsRunId;
Original file line number Diff line number Diff line change @@ -31,22 +31,29 @@ const BROWSER_INSTANCE_ID_KEY = 'browser_instance_id';
31
31
* This is not implemented yet as requires bigger refactoring.
32
32
*/
33
33
export class BrowserInstanceService {
34
- static _id: string | undefined = undefined;
34
+ // `undefined` represents the case when the storage is inaccessible.
35
+ static _id: string | undefined | null = null;
35
36
36
- static get id(): string {
37
- if(this._id) {
37
+ static get id(): string | undefined {
38
+ if(this._id !== null ) {
38
39
return this._id;
39
40
}
40
41
41
42
42
43
// Check if the ID is already stored in the session storage. It might be generated by another frame/context.
43
44
let browserInstanceId = safelyGetSessionStorage(BROWSER_INSTANCE_ID_KEY);
44
- if(!browserInstanceId) {
45
+ if(browserInstanceId) {
46
+ this._id = browserInstanceId;
47
+ } else if(browserInstanceId === null) {
48
+ // Storage is accessible but the ID is not stored yet.
45
49
browserInstanceId = generateId(64);
50
+ this._id = browserInstanceId;
46
51
safelySetSessionStorage(BROWSER_INSTANCE_ID_KEY, browserInstanceId);
52
+ } else {
53
+ // Storage is not accessible.
54
+ this._id = undefined;
47
55
}
48
56
49
- this._id = browserInstanceId;
50
57
51
58
return this._id;
52
59
}
Original file line number Diff line number Diff line change @@ -14,15 +14,14 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- export const safelyGetSessionStorage = (key: string): string | null => {
18
- let value = null;
17
+ export const safelyGetSessionStorage = (key: string): string | null | undefined => {
19
18
try {
20
- value = window.sessionStorage.getItem(key);
19
+ return window.sessionStorage.getItem(key);
21
20
} catch {
21
+ return undefined
22
22
// sessionStorage not accessible probably user is in incognito-mode
23
23
// or set "Block third-party cookies" option in browser settings
24
24
}
25
- return value;
26
25
};
27
26
28
27
export const safelySetSessionStorage = (key: string, value: string): boolean => {
You can’t perform that action at this time.
0 commit comments