@grafana/faro-web-sdk 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/faro-web-sdk.iife.js +1 -1
- package/dist/bundle/types/instrumentations/console/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/errors/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/session/instrumentation.d.ts +2 -1
- package/dist/bundle/types/instrumentations/session/sessionManager/index.d.ts +1 -0
- package/dist/bundle/types/instrumentations/session/sessionManager/sessionConstants.d.ts +11 -0
- package/dist/bundle/types/instrumentations/session/sessionManager/sessionManagerUtils.d.ts +0 -6
- package/dist/bundle/types/instrumentations/view/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/webVitals/instrumentation.d.ts +1 -1
- package/dist/bundle/types/transports/console/transport.d.ts +1 -1
- package/dist/bundle/types/transports/fetch/transport.d.ts +1 -1
- package/dist/cjs/config/makeCoreConfig.js +6 -41
- package/dist/cjs/config/makeCoreConfig.js.map +1 -1
- package/dist/cjs/instrumentations/session/instrumentation.js +52 -8
- package/dist/cjs/instrumentations/session/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/PersistentSessionsManager.js +6 -5
- package/dist/cjs/instrumentations/session/sessionManager/PersistentSessionsManager.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/VolatileSessionManager.js +5 -4
- package/dist/cjs/instrumentations/session/sessionManager/VolatileSessionManager.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/index.js +15 -0
- package/dist/cjs/instrumentations/session/sessionManager/index.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/sessionConstants.js +15 -0
- package/dist/cjs/instrumentations/session/sessionManager/sessionConstants.js.map +1 -0
- package/dist/cjs/instrumentations/session/sessionManager/sessionManagerUtils.js +4 -10
- package/dist/cjs/instrumentations/session/sessionManager/sessionManagerUtils.js.map +1 -1
- package/dist/cjs/instrumentations/view/instrumentation.js +1 -1
- package/dist/cjs/instrumentations/view/instrumentation.js.map +1 -1
- package/dist/cjs/transports/fetch/transport.js +8 -7
- package/dist/cjs/transports/fetch/transport.js.map +1 -1
- package/dist/esm/config/makeCoreConfig.js +7 -42
- package/dist/esm/config/makeCoreConfig.js.map +1 -1
- package/dist/esm/instrumentations/session/instrumentation.js +53 -9
- package/dist/esm/instrumentations/session/instrumentation.js.map +1 -1
- package/dist/esm/instrumentations/session/sessionManager/PersistentSessionsManager.js +2 -1
- package/dist/esm/instrumentations/session/sessionManager/PersistentSessionsManager.js.map +1 -1
- package/dist/esm/instrumentations/session/sessionManager/VolatileSessionManager.js +2 -1
- package/dist/esm/instrumentations/session/sessionManager/VolatileSessionManager.js.map +1 -1
- package/dist/esm/instrumentations/session/sessionManager/index.js +1 -0
- package/dist/esm/instrumentations/session/sessionManager/index.js.map +1 -1
- package/dist/esm/instrumentations/session/sessionManager/sessionConstants.js +12 -0
- package/dist/esm/instrumentations/session/sessionManager/sessionConstants.js.map +1 -0
- package/dist/esm/instrumentations/session/sessionManager/sessionManagerUtils.js +1 -7
- package/dist/esm/instrumentations/session/sessionManager/sessionManagerUtils.js.map +1 -1
- package/dist/esm/instrumentations/view/instrumentation.js +2 -2
- package/dist/esm/instrumentations/view/instrumentation.js.map +1 -1
- package/dist/esm/transports/fetch/transport.js +7 -6
- package/dist/esm/transports/fetch/transport.js.map +1 -1
- package/dist/types/instrumentations/console/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/errors/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/session/instrumentation.d.ts +2 -1
- package/dist/types/instrumentations/session/sessionManager/index.d.ts +1 -0
- package/dist/types/instrumentations/session/sessionManager/sessionConstants.d.ts +11 -0
- package/dist/types/instrumentations/session/sessionManager/sessionManagerUtils.d.ts +0 -6
- package/dist/types/instrumentations/view/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/webVitals/instrumentation.d.ts +1 -1
- package/dist/types/transports/console/transport.d.ts +1 -1
- package/dist/types/transports/fetch/transport.d.ts +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { BaseInstrumentation,
|
|
1
|
+
import { BaseInstrumentation, dateNow, EVENT_SESSION_EXTEND, EVENT_SESSION_RESUME, EVENT_SESSION_START, VERSION, } from '@grafana/faro-core';
|
|
2
|
+
import { createSession } from '../../metas';
|
|
2
3
|
import { isLocalStorageAvailable, isSessionStorageAvailable } from '../../utils/webStorage';
|
|
3
4
|
import { PersistentSessionsManager } from './sessionManager/PersistentSessionsManager';
|
|
5
|
+
import { isUserSessionValid } from './sessionManager/sessionManagerUtils';
|
|
4
6
|
import { VolatileSessionsManager } from './sessionManager/VolatileSessionManager';
|
|
5
7
|
export class SessionInstrumentation extends BaseInstrumentation {
|
|
6
8
|
constructor() {
|
|
@@ -9,13 +11,18 @@ export class SessionInstrumentation extends BaseInstrumentation {
|
|
|
9
11
|
this.version = VERSION;
|
|
10
12
|
}
|
|
11
13
|
sendSessionStartEvent(meta) {
|
|
12
|
-
var _a;
|
|
14
|
+
var _a, _b;
|
|
13
15
|
const session = meta.session;
|
|
14
16
|
if (session && session.id !== ((_a = this.notifiedSession) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
17
|
+
if (this.notifiedSession && this.notifiedSession.id === ((_b = session.attributes) === null || _b === void 0 ? void 0 : _b['previousSession'])) {
|
|
18
|
+
this.api.pushEvent(EVENT_SESSION_EXTEND, {}, undefined, { skipDedupe: true });
|
|
19
|
+
this.notifiedSession = session;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
15
22
|
this.notifiedSession = session;
|
|
16
23
|
// no need to add attributes and session id, they are included as part of meta
|
|
17
24
|
// automatically
|
|
18
|
-
this.api.pushEvent(
|
|
25
|
+
this.api.pushEvent(EVENT_SESSION_START, {}, undefined, { skipDedupe: true });
|
|
19
26
|
}
|
|
20
27
|
}
|
|
21
28
|
getSessionManagerInstanceByConfiguredStrategy(initialSessionId) {
|
|
@@ -28,20 +35,57 @@ export class SessionInstrumentation extends BaseInstrumentation {
|
|
|
28
35
|
}
|
|
29
36
|
return null;
|
|
30
37
|
}
|
|
31
|
-
|
|
38
|
+
createInitialSessionMeta(sessionsConfig) {
|
|
32
39
|
var _a, _b, _c;
|
|
40
|
+
const sessionManager = sessionsConfig.persistent ? PersistentSessionsManager : VolatileSessionsManager;
|
|
41
|
+
let userSession = sessionManager.fetchUserSession();
|
|
42
|
+
if (sessionsConfig.persistent && sessionsConfig.maxSessionPersistenceTime && userSession) {
|
|
43
|
+
const now = dateNow();
|
|
44
|
+
const shouldClearPersistentSession = userSession.lastActivity < now - sessionsConfig.maxSessionPersistenceTime;
|
|
45
|
+
if (shouldClearPersistentSession) {
|
|
46
|
+
PersistentSessionsManager.removeUserSession();
|
|
47
|
+
userSession = null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
let sessionId = (_a = sessionsConfig.session) === null || _a === void 0 ? void 0 : _a.id;
|
|
51
|
+
let sessionAttributes = (_b = sessionsConfig.session) === null || _b === void 0 ? void 0 : _b.attributes;
|
|
52
|
+
if (isUserSessionValid(userSession)) {
|
|
53
|
+
sessionId = userSession === null || userSession === void 0 ? void 0 : userSession.sessionId;
|
|
54
|
+
sessionAttributes = (_c = userSession === null || userSession === void 0 ? void 0 : userSession.sessionMeta) === null || _c === void 0 ? void 0 : _c.attributes;
|
|
55
|
+
this.api.pushEvent(EVENT_SESSION_RESUME, {}, undefined, { skipDedupe: true });
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
sessionId = sessionId !== null && sessionId !== void 0 ? sessionId : createSession().id;
|
|
59
|
+
this.api.pushEvent(EVENT_SESSION_START, {}, undefined, { skipDedupe: true });
|
|
60
|
+
}
|
|
61
|
+
const sessionMeta = {
|
|
62
|
+
id: sessionId,
|
|
63
|
+
};
|
|
64
|
+
if (sessionAttributes) {
|
|
65
|
+
sessionMeta.attributes = sessionAttributes;
|
|
66
|
+
}
|
|
67
|
+
this.notifiedSession = sessionMeta;
|
|
68
|
+
return sessionMeta;
|
|
69
|
+
}
|
|
70
|
+
initialize() {
|
|
71
|
+
var _a, _b;
|
|
33
72
|
this.logDebug('init session instrumentation');
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
73
|
+
const sessionTracking = this.config.sessionTracking;
|
|
74
|
+
if (sessionTracking === null || sessionTracking === void 0 ? void 0 : sessionTracking.enabled) {
|
|
75
|
+
const initialSessionMeta = this.createInitialSessionMeta(sessionTracking);
|
|
76
|
+
this.api.setSession(initialSessionMeta);
|
|
77
|
+
const sessionManager = this.getSessionManagerInstanceByConfiguredStrategy((_a = this.metas.value.session) === null || _a === void 0 ? void 0 : _a.id);
|
|
38
78
|
if (sessionManager != null) {
|
|
39
|
-
(
|
|
79
|
+
(_b = this.transports) === null || _b === void 0 ? void 0 : _b.addBeforeSendHooks(...this.transports.getBeforeSendHooks(), (item) => {
|
|
40
80
|
sessionManager === null || sessionManager === void 0 ? void 0 : sessionManager.updateSession();
|
|
41
81
|
return item;
|
|
42
82
|
});
|
|
43
83
|
}
|
|
44
84
|
}
|
|
85
|
+
else {
|
|
86
|
+
this.sendSessionStartEvent(this.metas.value);
|
|
87
|
+
}
|
|
88
|
+
this.metas.addListener(this.sendSessionStartEvent.bind(this));
|
|
45
89
|
}
|
|
46
90
|
}
|
|
47
91
|
//# sourceMappingURL=instrumentation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../../../src/instrumentations/session/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../../../src/instrumentations/session/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,OAAO,EACP,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EAGnB,OAAO,GACR,MAAM,oBAAoB,CAAC;A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,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE,CAAC;CACF","sourcesContent":["import {\n BaseInstrumentation,\n dateNow,\n EVENT_SESSION_EXTEND,\n EVENT_SESSION_RESUME,\n EVENT_SESSION_START,\n Meta,\n MetaSession,\n VERSION,\n} from '@grafana/faro-core';\nimport type { Config } from '@grafana/faro-core';\n\nimport { createSession } from '../../metas';\nimport { isLocalStorageAvailable, isSessionStorageAvailable } from '../../utils/webStorage';\n\nimport type { FaroUserSession } from './sessionManager';\nimport { PersistentSessionsManager } from './sessionManager/PersistentSessionsManager';\nimport { isUserSessionValid } from './sessionManager/sessionManagerUtils';\nimport { VolatileSessionsManager } from './sessionManager/VolatileSessionManager';\n\nexport class SessionInstrumentation extends BaseInstrumentation {\n readonly name = '@grafana/faro-web-sdk:instrumentation-session';\n readonly version = VERSION;\n\n // previously notified session, to ensure we don't send session start\n // event twice for the same session\n private notifiedSession: MetaSession | undefined;\n\n private sendSessionStartEvent(meta: Meta): void {\n const session = meta.session;\n\n if (session && session.id !== this.notifiedSession?.id) {\n if (this.notifiedSession && this.notifiedSession.id === session.attributes?.['previousSession']) {\n this.api.pushEvent(EVENT_SESSION_EXTEND, {}, undefined, { skipDedupe: true });\n this.notifiedSession = session;\n return;\n }\n\n this.notifiedSession = session;\n // no need to add attributes and session id, they are included as part of meta\n // automatically\n this.api.pushEvent(EVENT_SESSION_START, {}, undefined, { skipDedupe: true });\n }\n }\n\n private getSessionManagerInstanceByConfiguredStrategy(\n initialSessionId?: string\n ): PersistentSessionsManager | VolatileSessionsManager | null {\n if (this.config.sessionTracking?.persistent && isLocalStorageAvailable) {\n return new PersistentSessionsManager(initialSessionId);\n }\n\n if (isSessionStorageAvailable) {\n return new VolatileSessionsManager(initialSessionId);\n }\n\n return null;\n }\n\n private createInitialSessionMeta(sessionsConfig: Required<Config>['sessionTracking']): MetaSession {\n const sessionManager = sessionsConfig.persistent ? PersistentSessionsManager : VolatileSessionsManager;\n\n let userSession: FaroUserSession | null = sessionManager.fetchUserSession();\n\n if (sessionsConfig.persistent && sessionsConfig.maxSessionPersistenceTime && userSession) {\n const now = dateNow();\n const shouldClearPersistentSession = userSession.lastActivity < now - sessionsConfig.maxSessionPersistenceTime;\n\n if (shouldClearPersistentSession) {\n PersistentSessionsManager.removeUserSession();\n userSession = null;\n }\n }\n\n let sessionId = sessionsConfig.session?.id;\n let sessionAttributes = sessionsConfig.session?.attributes;\n\n if (isUserSessionValid(userSession)) {\n sessionId = userSession?.sessionId;\n sessionAttributes = userSession?.sessionMeta?.attributes;\n this.api.pushEvent(EVENT_SESSION_RESUME, {}, undefined, { skipDedupe: true });\n } else {\n sessionId = sessionId ?? createSession().id;\n this.api.pushEvent(EVENT_SESSION_START, {}, undefined, { skipDedupe: true });\n }\n\n const sessionMeta: MetaSession = {\n id: sessionId,\n };\n\n if (sessionAttributes) {\n sessionMeta.attributes = sessionAttributes;\n }\n\n this.notifiedSession = sessionMeta;\n\n return sessionMeta;\n }\n\n initialize() {\n this.logDebug('init session instrumentation');\n\n const sessionTracking = this.config.sessionTracking;\n\n if (sessionTracking?.enabled) {\n const initialSessionMeta = this.createInitialSessionMeta(sessionTracking);\n this.api.setSession(initialSessionMeta);\n\n const sessionManager = this.getSessionManagerInstanceByConfiguredStrategy(this.metas.value.session?.id);\n\n if (sessionManager != null) {\n this.transports?.addBeforeSendHooks(...this.transports.getBeforeSendHooks(), (item: any) => {\n sessionManager?.updateSession();\n return item;\n });\n }\n } else {\n this.sendSessionStartEvent(this.metas.value);\n }\n\n this.metas.addListener(this.sendSessionStartEvent.bind(this));\n }\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { faro } from '@grafana/faro-core';
|
|
2
2
|
import { throttle } from '../../../utils';
|
|
3
3
|
import { getItem, removeItem, setItem, webStorageType } from '../../../utils/webStorage';
|
|
4
|
-
import {
|
|
4
|
+
import { STORAGE_KEY, STORAGE_UPDATE_DELAY } from './sessionConstants';
|
|
5
|
+
import { addSessionMetadataToNextSession, createUserSessionObject, getUserSessionUpdater } from './sessionManagerUtils';
|
|
5
6
|
export class PersistentSessionsManager {
|
|
6
7
|
constructor(initialSessionId) {
|
|
7
8
|
this.initialSessionId = initialSessionId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersistentSessionsManager.js","sourceRoot":"","sources":["../../../../../src/instrumentations/session/sessionManager/PersistentSessionsManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEzF,OAAO,
|
|
1
|
+
{"version":3,"file":"PersistentSessionsManager.js","sourceRoot":"","sources":["../../../../../src/instrumentations/session/sessionManager/PersistentSessionsManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEzF,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,+BAA+B,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAGxH,MAAM,OAAO,yBAAyB;IAIpC,YAAoB,gBAAyB;QAAzB,qBAAgB,GAAhB,gBAAgB,CAAS;QA2B7C,kBAAa,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,oBAAoB,CAAC,CAAC;QA1B7E,IAAI,CAAC,iBAAiB,GAAG,qBAAqB,CAAC;YAC7C,gBAAgB,EAAE,yBAAyB,CAAC,gBAAgB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AU,CAAC,SAAS,KAAK,eAAe,CAAC,SAAS,EAAE;gBACtD,MAAA,IAAI,CAAC,GAAG,0CAAE,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;aAC9C;QACH,CAAC,CAAC,CAAC;QAEH,iGAAiG;QACjG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,8BAA8B,CAAC,IAAU;YACvE,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;YAC7B,MAAM,uBAAuB,GAAG,yBAAyB,CAAC,gBAAgB,EAAE,CAAC;YAE7E,IAAI,OAAO,IAAI,OAAO,CAAC,EAAE,MAAK,uBAAuB,aAAvB,uBAAuB,uBAAvB,uBAAuB,CAAE,SAAS,CAAA,EAAE;gBAChE,MAAM,WAAW,GAAG,+BAA+B,CACjD,uBAAuB,CAAC,OAAO,CAAC,EAAE,CAAC,EACnC,uBAAuB,CACxB,CAAC;gBAEF,yBAAyB,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;gBACxD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;aAC9C;QACH,CAAC,CAAC,CAAC;IACL,CAAC;;AArEc,0CAAgB,GAAG,cAAc,CAAC,KAAK,CAAC","sourcesContent":["import { faro } from '@grafana/faro-core';\nimport type { Meta } from '@grafana/faro-core';\n\nimport { throttle } from '../../../utils';\nimport { getItem, removeItem, setItem, webStorageType } from '../../../utils/webStorage';\n\nimport { STORAGE_KEY, STORAGE_UPDATE_DELAY } from './sessionConstants';\nimport { addSessionMetadataToNextSession, createUserSessionObject, getUserSessionUpdater } from './sessionManagerUtils';\nimport type { FaroUserSession } from './types';\n\nexport class PersistentSessionsManager {\n private static storageTypeLocal = webStorageType.local;\n private updateUserSession: ReturnType<typeof getUserSessionUpdater>;\n\n constructor(private initialSessionId?: string) {\n this.updateUserSession = getUserSessionUpdater({\n fetchUserSession: PersistentSessionsManager.fetchUserSession,\n storeUserSession: PersistentSessionsManager.storeUserSession,\n });\n\n this.init();\n }\n\n static removeUserSession() {\n removeItem(STORAGE_KEY, PersistentSessionsManager.storageTypeLocal);\n }\n\n static storeUserSession(session: FaroUserSession): void {\n setItem(STORAGE_KEY, JSON.stringify(session), PersistentSessionsManager.storageTypeLocal);\n }\n\n static fetchUserSession(): FaroUserSession | null {\n const storedSession = getItem(STORAGE_KEY, PersistentSessionsManager.storageTypeLocal);\n\n if (storedSession) {\n return JSON.parse(storedSession) as FaroUserSession;\n }\n\n return null;\n }\n\n updateSession = throttle(() => this.updateUserSession(), STORAGE_UPDATE_DELAY);\n\n private init(): void {\n PersistentSessionsManager.storeUserSession(createUserSessionObject(this.initialSessionId));\n\n document.addEventListener('visibilitychange', () => {\n if (document.visibilityState === 'visible') {\n this.updateSession();\n }\n });\n\n window.addEventListener('storage', (event: StorageEvent) => {\n if (event.key !== STORAGE_KEY) {\n return;\n }\n\n const newSession: FaroUserSession = JSON.parse(event.newValue ?? '');\n const previousSession: FaroUserSession = JSON.parse(event.oldValue ?? '');\n\n if (newSession.sessionId !== previousSession.sessionId) {\n faro.api?.setSession(newSession.sessionMeta);\n }\n });\n\n // Users can call the setSession() method, so we need to sync this with the local storage session\n faro.metas.addListener(function syncSessionIfChangedExternally(meta: Meta) {\n const session = meta.session;\n const sessionFromLocalStorage = PersistentSessionsManager.fetchUserSession();\n\n if (session && session.id !== sessionFromLocalStorage?.sessionId) {\n const userSession = addSessionMetadataToNextSession(\n createUserSessionObject(session.id),\n sessionFromLocalStorage\n );\n\n PersistentSessionsManager.storeUserSession(userSession);\n faro.api.setSession(userSession.sessionMeta);\n }\n });\n }\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { faro } from '@grafana/faro-core';
|
|
2
2
|
import { throttle } from '../../../utils';
|
|
3
3
|
import { getItem, removeItem, setItem, webStorageType } from '../../../utils/webStorage';
|
|
4
|
-
import {
|
|
4
|
+
import { STORAGE_KEY, STORAGE_UPDATE_DELAY } from './sessionConstants';
|
|
5
|
+
import { addSessionMetadataToNextSession, createUserSessionObject, getUserSessionUpdater } from './sessionManagerUtils';
|
|
5
6
|
export class VolatileSessionsManager {
|
|
6
7
|
constructor(initialSessionId) {
|
|
7
8
|
this.initialSessionId = initialSessionId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VolatileSessionManager.js","sourceRoot":"","sources":["../../../../../src/instrumentations/session/sessionManager/VolatileSessionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEzF,OAAO,
|
|
1
|
+
{"version":3,"file":"VolatileSessionManager.js","sourceRoot":"","sources":["../../../../../src/instrumentations/session/sessionManager/VolatileSessionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEzF,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,+BAA+B,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAGxH,MAAM,OAAO,uBAAuB;IAIlC,YAAoB,gBAAyB;QAAzB,qBAAgB,GAAhB,gBAAgB,CAAS;QA2B7C,kBAAa,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,oBAAoB,CAAC,CAAC;QA1B7E,IAAI,CAAC,iBAAiB,GAAG,qBAAqB,CAAC;YAC7C,gBAAgB,EAAE,uBAAuB,CAAC,gB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uBAAuB,CAAC,OAAO,CAAC,EAAE,CAAC,EACnC,yBAAyB,CAC1B,CAAC;gBAEF,uBAAuB,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;gBACtD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;aAC9C;QACH,CAAC,CAAC,CAAC;IACL,CAAC;;AAxDc,0CAAkB,GAAG,cAAc,CAAC,OAAO,CAAC","sourcesContent":["import { faro } from '@grafana/faro-core';\nimport type { Meta } from '@grafana/faro-core';\n\nimport { throttle } from '../../../utils';\nimport { getItem, removeItem, setItem, webStorageType } from '../../../utils/webStorage';\n\nimport { STORAGE_KEY, STORAGE_UPDATE_DELAY } from './sessionConstants';\nimport { addSessionMetadataToNextSession, createUserSessionObject, getUserSessionUpdater } from './sessionManagerUtils';\nimport type { FaroUserSession } from './types';\n\nexport class VolatileSessionsManager {\n private static storageTypeSession = webStorageType.session;\n private updateUserSession: ReturnType<typeof getUserSessionUpdater>;\n\n constructor(private initialSessionId?: string) {\n this.updateUserSession = getUserSessionUpdater({\n fetchUserSession: VolatileSessionsManager.fetchUserSession,\n storeUserSession: VolatileSessionsManager.storeUserSession,\n });\n\n this.init();\n }\n\n static removeUserSession() {\n removeItem(STORAGE_KEY, VolatileSessionsManager.storageTypeSession);\n }\n\n static storeUserSession(session: FaroUserSession): void {\n setItem(STORAGE_KEY, JSON.stringify(session), VolatileSessionsManager.storageTypeSession);\n }\n\n static fetchUserSession(): FaroUserSession | null {\n const storedSession = getItem(STORAGE_KEY, VolatileSessionsManager.storageTypeSession);\n\n if (storedSession) {\n return JSON.parse(storedSession) as FaroUserSession;\n }\n\n return null;\n }\n\n updateSession = throttle(() => this.updateUserSession(), STORAGE_UPDATE_DELAY);\n\n private init(): void {\n VolatileSessionsManager.storeUserSession(createUserSessionObject(this.initialSessionId));\n\n document.addEventListener('visibilitychange', () => {\n if (document.visibilityState === 'visible') {\n this.updateSession();\n }\n });\n\n // Users can call the setSession() method, so we need to sync this with the local storage session\n faro.metas.addListener(function syncSessionIfChangedExternally(meta: Meta) {\n const session = meta.session;\n const sessionFromSessionStorage = VolatileSessionsManager.fetchUserSession();\n\n if (session && session.id !== sessionFromSessionStorage?.sessionId) {\n const userSession = addSessionMetadataToNextSession(\n createUserSessionObject(session.id),\n sessionFromSessionStorage\n );\n\n VolatileSessionsManager.storeUserSession(userSession);\n faro.api.setSession(userSession.sessionMeta);\n }\n });\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/instrumentations/session/sessionManager/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["export { PersistentSessionsManager } from './PersistentSessionsManager';\nexport { VolatileSessionsManager } from './VolatileSessionManager';\nexport type { FaroUserSession } from './types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/instrumentations/session/sessionManager/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,cAAc,oBAAoB,CAAC","sourcesContent":["export { PersistentSessionsManager } from './PersistentSessionsManager';\nexport { VolatileSessionsManager } from './VolatileSessionManager';\nexport * from './sessionConstants';\nexport type { FaroUserSession } from './types';\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const STORAGE_KEY = '__FARO_SESSION__';
|
|
2
|
+
export const SESSION_EXPIRATION_TIME = 4 * 60 * 60 * 1000; // hrs
|
|
3
|
+
export const SESSION_INACTIVITY_TIME = 15 * 60 * 1000; // minutes
|
|
4
|
+
export const STORAGE_UPDATE_DELAY = 1 * 1000; // seconds
|
|
5
|
+
export const MAX_SESSION_PERSISTENCE_TIME_BUFFER = 5 * 60 * 1000;
|
|
6
|
+
export const MAX_SESSION_PERSISTENCE_TIME = SESSION_EXPIRATION_TIME + MAX_SESSION_PERSISTENCE_TIME_BUFFER;
|
|
7
|
+
export const defaultSessionTrackingConfig = {
|
|
8
|
+
enabled: false,
|
|
9
|
+
persistent: false,
|
|
10
|
+
maxSessionPersistenceTime: MAX_SESSION_PERSISTENCE_TIME,
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=sessionConstants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionConstants.js","sourceRoot":"","sources":["../../../../../src/instrumentations/session/sessionManager/sessionConstants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC;AAC9C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,MAAM;AACjE,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,UAAU;AACjE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,UAAU;AAExD,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AACjE,MAAM,CAAC,MAAM,4BAA4B,GAAG,uBAAuB,GAAG,mCAAmC,CAAC;AAE1G,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,KAAK;IACjB,yBAAyB,EAAE,4BAA4B;CAC/C,CAAC","sourcesContent":["export const STORAGE_KEY = '__FARO_SESSION__';\nexport const SESSION_EXPIRATION_TIME = 4 * 60 * 60 * 1000; // hrs\nexport const SESSION_INACTIVITY_TIME = 15 * 60 * 1000; // minutes\nexport const STORAGE_UPDATE_DELAY = 1 * 1000; // seconds\n\nexport const MAX_SESSION_PERSISTENCE_TIME_BUFFER = 5 * 60 * 1000;\nexport const MAX_SESSION_PERSISTENCE_TIME = SESSION_EXPIRATION_TIME + MAX_SESSION_PERSISTENCE_TIME_BUFFER;\n\nexport const defaultSessionTrackingConfig = {\n enabled: false,\n persistent: false,\n maxSessionPersistenceTime: MAX_SESSION_PERSISTENCE_TIME,\n} as const;\n"]}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { dateNow, faro, genShortID } from '@grafana/faro-core';
|
|
2
|
-
|
|
3
|
-
export const STORAGE_KEY = '__FARO_SESSION__';
|
|
4
|
-
export const SESSION_EXPIRATION_TIME = 4 * 60 * 60 * 1000; // hrs
|
|
5
|
-
export const SESSION_INACTIVITY_TIME = 15 * 60 * 1000; // minutes
|
|
6
|
-
export const STORAGE_UPDATE_DELAY = 1 * 1000; // seconds
|
|
7
|
-
export const MAX_SESSION_PERSISTENCE_TIME_BUFFER = 5 * 60 * 1000;
|
|
8
|
-
export const MAX_SESSION_PERSISTENCE_TIME = SESSION_EXPIRATION_TIME + MAX_SESSION_PERSISTENCE_TIME_BUFFER;
|
|
2
|
+
import { SESSION_EXPIRATION_TIME, SESSION_INACTIVITY_TIME } from './sessionConstants';
|
|
9
3
|
export function createUserSessionObject(sessionId) {
|
|
10
4
|
const now = dateNow();
|
|
11
5
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionManagerUtils.js","sourceRoot":"","sources":["../../../../../src/instrumentations/session/sessionManager/sessionManagerUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"sessionManagerUtils.js","sourceRoot":"","sources":["../../../../../src/instrumentations/session/sessionManager/sessionManagerUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,uBAAuB,EAAE,uBAAuB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AM,CAAC,eAAe,0CAAE,eAAe,mDAAG,MAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,WAAW,mCAAI,IAAI,EAAE,UAAU,CAAC,WAAY,CAAC,CAAC;SAClH;IACH,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,+BAA+B,CAAC,UAA2B,EAAE,eAAuC;;IAClH,MAAM,eAAe,mCAChB,UAAU,KACb,WAAW,EAAE;YACX,EAAE,EAAE,UAAU,CAAC,SAAS;SACzB,GACF,CAAC;IAEF,MAAM,cAAc,GAAG,MAAA,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,0CAAE,UAAU,CAAC;IAC5D,IAAI,cAAc,IAAI,eAAe,IAAI,IAAI,EAAE;QAC7C,eAAe,CAAC,WAAW,CAAC,UAAU,mCACjC,CAAC,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,EAAE,CAAC,GACtB,CAAC,eAAe,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,eAAe,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACnF,CAAC;KACH;IAED,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import { dateNow, faro, genShortID } from '@grafana/faro-core';\n\nimport { SESSION_EXPIRATION_TIME, SESSION_INACTIVITY_TIME } from './sessionConstants';\nimport type { FaroUserSession } from './types';\n\nexport function createUserSessionObject(sessionId?: string): FaroUserSession {\n const now = dateNow();\n\n return {\n sessionId: sessionId ?? genShortID(),\n lastActivity: now,\n started: now,\n };\n}\n\nexport function isUserSessionValid(session: FaroUserSession | null): boolean {\n if (session == null) {\n return false;\n }\n\n const now = dateNow();\n const lifetimeValid = now - session.started < SESSION_EXPIRATION_TIME;\n\n if (!lifetimeValid) {\n return false;\n }\n\n const inactivityPeriodValid = now - session.lastActivity < SESSION_INACTIVITY_TIME;\n return inactivityPeriodValid;\n}\n\ntype GetUserSessionUpdaterParams = {\n storeUserSession: (session: FaroUserSession) => void;\n fetchUserSession: () => FaroUserSession | null;\n};\n\nexport function getUserSessionUpdater({ fetchUserSession, storeUserSession }: GetUserSessionUpdaterParams): () => void {\n return function updateSession(): void {\n if (!fetchUserSession || !storeUserSession) {\n return;\n }\n\n const sessionFromStorage = fetchUserSession();\n\n if (isUserSessionValid(sessionFromStorage)) {\n storeUserSession({ ...sessionFromStorage!, lastActivity: dateNow() });\n } else {\n let newSession = addSessionMetadataToNextSession(createUserSessionObject(), sessionFromStorage);\n\n storeUserSession(newSession);\n\n faro.api?.setSession(newSession.sessionMeta);\n faro.config.sessionTracking?.onSessionChange?.(sessionFromStorage?.sessionMeta ?? null, newSession.sessionMeta!);\n }\n };\n}\n\nexport function addSessionMetadataToNextSession(newSession: FaroUserSession, previousSession: FaroUserSession | null) {\n const sessionWithMeta: Required<FaroUserSession> = {\n ...newSession,\n sessionMeta: {\n id: newSession.sessionId,\n },\n };\n\n const metaAttributes = faro.metas.value.session?.attributes;\n if (metaAttributes || previousSession != null) {\n sessionWithMeta.sessionMeta.attributes = {\n ...(metaAttributes ?? {}),\n ...(previousSession != null ? { previousSession: previousSession.sessionId } : {}),\n };\n }\n\n return sessionWithMeta;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseInstrumentation,
|
|
1
|
+
import { BaseInstrumentation, EVENT_VIEW_CHANGED, VERSION } from '@grafana/faro-core';
|
|
2
2
|
// all this does is send VIEW_CHANGED event
|
|
3
3
|
export class ViewInstrumentation extends BaseInstrumentation {
|
|
4
4
|
constructor() {
|
|
@@ -10,7 +10,7 @@ export class ViewInstrumentation extends BaseInstrumentation {
|
|
|
10
10
|
const view = meta.view;
|
|
11
11
|
if (view && view !== this.notifiedView) {
|
|
12
12
|
this.notifiedView = view;
|
|
13
|
-
this.api.pushEvent(
|
|
13
|
+
this.api.pushEvent(EVENT_VIEW_CHANGED, {}, undefined, { skipDedupe: true });
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
initialize() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../../../src/instrumentations/view/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../../../src/instrumentations/view/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAkB,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEtG,2CAA2C;AAC3C,MAAM,OAAO,mBAAoB,SAAQ,mBAAmB;IAA5D;;QACW,SAAI,GAAG,4CAA4C,CAAC;QACpD,YAAO,GAAG,OAAO,CAAC;IAqB7B,CAAC;IAfS,oBAAoB,CAAC,IAAU;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAEvB,IAAI,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC,YAAY,EAAE;YACtC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YAEzB,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,kBAAkB,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;SAC7E;IACH,CAAC;IAED,UAAU;QACR,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAE5C,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/D,CAAC;CACF","sourcesContent":["import { BaseInstrumentation, EVENT_VIEW_CHANGED, Meta, MetaView, VERSION } from '@grafana/faro-core';\n\n// all this does is send VIEW_CHANGED event\nexport class ViewInstrumentation extends BaseInstrumentation {\n readonly name = '@grafana/faro-web-sdk:instrumentation-view';\n readonly version = VERSION;\n\n // previously notified view, to ensure we don't send view changed\n // event twice for the same view\n private notifiedView: MetaView | undefined;\n\n private sendViewChangedEvent(meta: Meta): void {\n const view = meta.view;\n\n if (view && view !== this.notifiedView) {\n this.notifiedView = view;\n\n this.api.pushEvent(EVENT_VIEW_CHANGED, {}, undefined, { skipDedupe: true });\n }\n }\n\n initialize() {\n this.sendViewChangedEvent(this.metas.value);\n\n this.metas.addListener(this.sendViewChangedEvent.bind(this));\n }\n}\n"]}
|
|
@@ -22,6 +22,8 @@ import { BaseTransport, createPromiseBuffer, getTransportBody, noop, VERSION } f
|
|
|
22
22
|
const DEFAULT_BUFFER_SIZE = 30;
|
|
23
23
|
const DEFAULT_CONCURRENCY = 5; // chrome supports 10 total, firefox 17
|
|
24
24
|
const DEFAULT_RATE_LIMIT_BACKOFF_MS = 5000;
|
|
25
|
+
const BEACON_BODY_SIZE_LIMIT = 60000;
|
|
26
|
+
const TOO_MANY_REQUESTS = 429;
|
|
25
27
|
export class FetchTransport extends BaseTransport {
|
|
26
28
|
constructor(options) {
|
|
27
29
|
var _a, _b, _c, _d;
|
|
@@ -45,15 +47,14 @@ export class FetchTransport extends BaseTransport {
|
|
|
45
47
|
return Promise.resolve();
|
|
46
48
|
}
|
|
47
49
|
yield this.promiseBuffer.add(() => {
|
|
48
|
-
var _a
|
|
50
|
+
var _a;
|
|
49
51
|
const body = JSON.stringify(getTransportBody(items));
|
|
50
52
|
const { url, requestOptions, apiKey } = this.options;
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
: {})), body, keepalive: body.length <= 60000 }, (restOfRequestOptions !== null && restOfRequestOptions !== void 0 ? restOfRequestOptions : {})))
|
|
53
|
+
const _b = requestOptions !== null && requestOptions !== void 0 ? requestOptions : {}, { headers } = _b, restOfRequestOptions = __rest(_b, ["headers"]);
|
|
54
|
+
const sessionId = (_a = this.metas.value.session) === null || _a === void 0 ? void 0 : _a.id;
|
|
55
|
+
return fetch(url, Object.assign({ method: 'POST', headers: Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, (headers !== null && headers !== void 0 ? headers : {})), (apiKey ? { 'x-api-key': apiKey } : {})), (sessionId ? { 'x-faro-session-id': sessionId } : {})), body, keepalive: body.length <= BEACON_BODY_SIZE_LIMIT }, (restOfRequestOptions !== null && restOfRequestOptions !== void 0 ? restOfRequestOptions : {})))
|
|
55
56
|
.then((response) => {
|
|
56
|
-
if (response.status ===
|
|
57
|
+
if (response.status === TOO_MANY_REQUESTS) {
|
|
57
58
|
this.disabledUntil = this.getRetryAfterDate(response);
|
|
58
59
|
this.logWarn(`Too many requests, backing off until ${this.disabledUntil}`);
|
|
59
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../../src/transports/fetch/transport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,IAAI,EAAiB,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAKxH,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,mBAAmB,GAAG,CAAC,CAAC,CAAC,uCAAuC;AACtE,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAE3C,MAAM,OAAO,cAAe,SAAQ,aAAa;IAU/C,YAAoB,OAA8B;;QAChD,KAAK,EAAE,CAAC;QADU,YAAO,GAAP,OAAO,CAAuB;QATzC,SAAI,GAAG,uCAAuC,CAAC;QAC/C,YAAO,GAAG,OAAO,CAAC;QAMnB,kBAAa,GAAS,IAAI,IAAI,EAAE,CAAC;QAKvC,IAAI,CAAC,kBAAkB,GAAG,MAAA,OAAO,CAAC,yBAAyB,mCAAI,6BAA6B,CAAC;QAC7F,IAAI,CAAC,MAAM,GAAG,MAAA,OAAO,CAAC,MAAM,mCAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAEnD,IAAI,CAAC,aAAa,GAAG,mBAAmB,CAAC;YACvC,IAAI,EAAE,MAAA,OAAO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AC,QAAQ,CAAC,0CAA0C,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;oBACnF,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC,CAAC;aACJ;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;aACpB;QACH,CAAC;KAAA;IAEQ,aAAa;QACpB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAEQ,SAAS;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,iBAAiB,CAAC,QAAkB;QAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAE7D,IAAI,gBAAgB,EAAE;YACpB,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;YAEvC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;gBACjB,OAAO,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC;aACrC;YAED,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;YAE1C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;gBAChB,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;aACvB;SACF;QAED,OAAO,IAAI,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACjD,CAAC;CACF","sourcesContent":["import { BaseTransport, createPromiseBuffer, getTransportBody, noop, PromiseBuffer, VERSION } from '@grafana/faro-core';\nimport type { TransportItem } from '@grafana/faro-core';\n\nimport type { FetchTransportOptions } from './types';\n\nconst DEFAULT_BUFFER_SIZE = 30;\nconst DEFAULT_CONCURRENCY = 5; // chrome supports 10 total, firefox 17\nconst DEFAULT_RATE_LIMIT_BACKOFF_MS = 5000;\n\nconst BEACON_BODY_SIZE_LIMIT = 60000;\nconst TOO_MANY_REQUESTS = 429;\n\nexport class FetchTransport extends BaseTransport {\n readonly name = '@grafana/faro-web-sdk:transport-fetch';\n readonly version = VERSION;\n\n promiseBuffer: PromiseBuffer<Response | void>;\n\n private readonly rateLimitBackoffMs: number;\n private readonly getNow: () => number;\n private disabledUntil: Date = new Date();\n\n constructor(private options: FetchTransportOptions) {\n super();\n\n this.rateLimitBackoffMs = options.defaultRateLimitBackoffMs ?? DEFAULT_RATE_LIMIT_BACKOFF_MS;\n this.getNow = options.getNow ?? (() => Date.now());\n\n this.promiseBuffer = createPromiseBuffer({\n size: options.bufferSize ?? DEFAULT_BUFFER_SIZE,\n concurrency: options.concurrency ?? DEFAULT_CONCURRENCY,\n });\n }\n\n async send(items: TransportItem[]): Promise<void> {\n try {\n if (this.disabledUntil > new Date(this.getNow())) {\n this.logWarn(`Dropping transport item due to too many requests. Backoff until ${this.disabledUntil}`);\n\n return Promise.resolve();\n }\n\n await this.promiseBuffer.add(() => {\n const body = JSON.stringify(getTransportBody(items));\n\n const { url, requestOptions, apiKey } = this.options;\n\n const { headers, ...restOfRequestOptions } = requestOptions ?? {};\n\n const sessionId = this.metas.value.session?.id;\n\n return fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...(headers ?? {}),\n ...(apiKey ? { 'x-api-key': apiKey } : {}),\n ...(sessionId ? { 'x-faro-session-id': sessionId } : {}),\n },\n body,\n keepalive: body.length <= BEACON_BODY_SIZE_LIMIT,\n ...(restOfRequestOptions ?? {}),\n })\n .then((response) => {\n if (response.status === TOO_MANY_REQUESTS) {\n this.disabledUntil = this.getRetryAfterDate(response);\n this.logWarn(`Too many requests, backing off until ${this.disabledUntil}`);\n }\n // read the body so the connection can be closed\n response.text().catch(noop);\n\n return response;\n })\n .catch((err) => {\n this.logError('Failed sending payload to the receiver\\n', JSON.parse(body), err);\n });\n });\n } catch (err) {\n this.logError(err);\n }\n }\n\n override getIgnoreUrls(): Array<string | RegExp> {\n return [this.options.url];\n }\n\n override isBatched(): boolean {\n return true;\n }\n\n private getRetryAfterDate(response: Response): Date {\n const now = this.getNow();\n const retryAfterHeader = response.headers.get('Retry-After');\n\n if (retryAfterHeader) {\n const delay = Number(retryAfterHeader);\n\n if (!isNaN(delay)) {\n return new Date(delay * 1000 + now);\n }\n\n const date = Date.parse(retryAfterHeader);\n\n if (!isNaN(date)) {\n return new Date(date);\n }\n }\n\n return new Date(now + this.rateLimitBackoffMs);\n }\n}\n"]}
|
|
@@ -3,7 +3,7 @@ import type { ConsoleInstrumentationOptions } from './types';
|
|
|
3
3
|
export declare class ConsoleInstrumentation extends BaseInstrumentation {
|
|
4
4
|
private options;
|
|
5
5
|
readonly name = "@grafana/faro-web-sdk:instrumentation-console";
|
|
6
|
-
readonly version = "1.2.
|
|
6
|
+
readonly version = "1.2.6";
|
|
7
7
|
static defaultDisabledLevels: LogLevel[];
|
|
8
8
|
constructor(options?: ConsoleInstrumentationOptions);
|
|
9
9
|
initialize(): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseInstrumentation } from '@grafana/faro-core';
|
|
2
2
|
export declare class ErrorsInstrumentation extends BaseInstrumentation {
|
|
3
3
|
readonly name = "@grafana/faro-web-sdk:instrumentation-errors";
|
|
4
|
-
readonly version = "1.2.
|
|
4
|
+
readonly version = "1.2.6";
|
|
5
5
|
initialize(): void;
|
|
6
6
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { BaseInstrumentation } from '@grafana/faro-core';
|
|
2
2
|
export declare class SessionInstrumentation extends BaseInstrumentation {
|
|
3
3
|
readonly name = "@grafana/faro-web-sdk:instrumentation-session";
|
|
4
|
-
readonly version = "1.2.
|
|
4
|
+
readonly version = "1.2.6";
|
|
5
5
|
private notifiedSession;
|
|
6
6
|
private sendSessionStartEvent;
|
|
7
7
|
private getSessionManagerInstanceByConfiguredStrategy;
|
|
8
|
+
private createInitialSessionMeta;
|
|
8
9
|
initialize(): void;
|
|
9
10
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const STORAGE_KEY = "__FARO_SESSION__";
|
|
2
|
+
export declare const SESSION_EXPIRATION_TIME: number;
|
|
3
|
+
export declare const SESSION_INACTIVITY_TIME: number;
|
|
4
|
+
export declare const STORAGE_UPDATE_DELAY: number;
|
|
5
|
+
export declare const MAX_SESSION_PERSISTENCE_TIME_BUFFER: number;
|
|
6
|
+
export declare const MAX_SESSION_PERSISTENCE_TIME: number;
|
|
7
|
+
export declare const defaultSessionTrackingConfig: {
|
|
8
|
+
readonly enabled: false;
|
|
9
|
+
readonly persistent: false;
|
|
10
|
+
readonly maxSessionPersistenceTime: number;
|
|
11
|
+
};
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import type { FaroUserSession } from './types';
|
|
2
|
-
export declare const STORAGE_KEY = "__FARO_SESSION__";
|
|
3
|
-
export declare const SESSION_EXPIRATION_TIME: number;
|
|
4
|
-
export declare const SESSION_INACTIVITY_TIME: number;
|
|
5
|
-
export declare const STORAGE_UPDATE_DELAY: number;
|
|
6
|
-
export declare const MAX_SESSION_PERSISTENCE_TIME_BUFFER: number;
|
|
7
|
-
export declare const MAX_SESSION_PERSISTENCE_TIME: number;
|
|
8
2
|
export declare function createUserSessionObject(sessionId?: string): FaroUserSession;
|
|
9
3
|
export declare function isUserSessionValid(session: FaroUserSession | null): boolean;
|
|
10
4
|
type GetUserSessionUpdaterParams = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseInstrumentation } from '@grafana/faro-core';
|
|
2
2
|
export declare class ViewInstrumentation extends BaseInstrumentation {
|
|
3
3
|
readonly name = "@grafana/faro-web-sdk:instrumentation-view";
|
|
4
|
-
readonly version = "1.2.
|
|
4
|
+
readonly version = "1.2.6";
|
|
5
5
|
private notifiedView;
|
|
6
6
|
private sendViewChangedEvent;
|
|
7
7
|
initialize(): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseInstrumentation } from '@grafana/faro-core';
|
|
2
2
|
export declare class WebVitalsInstrumentation extends BaseInstrumentation {
|
|
3
3
|
readonly name = "@grafana/faro-web-sdk:instrumentation-web-vitals";
|
|
4
|
-
readonly version = "1.2.
|
|
4
|
+
readonly version = "1.2.6";
|
|
5
5
|
static mapping: {
|
|
6
6
|
cls: (onReport: import("web-vitals").CLSReportCallback, opts?: import("web-vitals").ReportOpts | undefined) => void;
|
|
7
7
|
fcp: (onReport: import("web-vitals").FCPReportCallback, opts?: import("web-vitals").ReportOpts | undefined) => void;
|
|
@@ -4,7 +4,7 @@ import type { ConsoleTransportOptions } from './types';
|
|
|
4
4
|
export declare class ConsoleTransport extends BaseTransport {
|
|
5
5
|
private options;
|
|
6
6
|
readonly name = "@grafana/faro-web-sdk:transport-console";
|
|
7
|
-
readonly version = "1.2.
|
|
7
|
+
readonly version = "1.2.6";
|
|
8
8
|
constructor(options?: ConsoleTransportOptions);
|
|
9
9
|
send(item: TransportItem): void;
|
|
10
10
|
}
|
|
@@ -4,7 +4,7 @@ import type { FetchTransportOptions } from './types';
|
|
|
4
4
|
export declare class FetchTransport extends BaseTransport {
|
|
5
5
|
private options;
|
|
6
6
|
readonly name = "@grafana/faro-web-sdk:transport-fetch";
|
|
7
|
-
readonly version = "1.2.
|
|
7
|
+
readonly version = "1.2.6";
|
|
8
8
|
promiseBuffer: PromiseBuffer<Response | void>;
|
|
9
9
|
private readonly rateLimitBackoffMs;
|
|
10
10
|
private readonly getNow;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/faro-web-sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "Faro instrumentations, metas, transports for web.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"observability",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"quality:circular-deps": "madge --circular ."
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@grafana/faro-core": "^1.2.
|
|
55
|
+
"@grafana/faro-core": "^1.2.6",
|
|
56
56
|
"ua-parser-js": "^1.0.32",
|
|
57
57
|
"web-vitals": "^3.1.1"
|
|
58
58
|
},
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "9eb32b34a9b1a3153c9686337c7b5d0963389c54"
|
|
67
67
|
}
|