@kubesense/kubesense-browser-logs 0.0.0-stage → 2.0.0-beta.1
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/LICENSE +201 -0
- package/README.md +90 -2
- package/bundle/kubesense-logs.js +1 -0
- package/cjs/boot/logsPublicApi.d.ts +231 -0
- package/cjs/boot/logsPublicApi.js +75 -0
- package/cjs/boot/logsPublicApi.js.map +1 -0
- package/cjs/boot/preStartLogs.d.ts +8 -0
- package/cjs/boot/preStartLogs.js +105 -0
- package/cjs/boot/preStartLogs.js.map +1 -0
- package/cjs/boot/startLogs.d.ts +35 -0
- package/cjs/boot/startLogs.js +54 -0
- package/cjs/boot/startLogs.js.map +1 -0
- package/cjs/domain/assembly.d.ts +5 -0
- package/cjs/domain/assembly.js +35 -0
- package/cjs/domain/assembly.js.map +1 -0
- package/cjs/domain/configuration.d.ts +306 -0
- package/cjs/domain/configuration.js +86 -0
- package/cjs/domain/configuration.js.map +1 -0
- package/cjs/domain/console/consoleCollection.d.ts +20 -0
- package/cjs/domain/console/consoleCollection.js +37 -0
- package/cjs/domain/console/consoleCollection.js.map +1 -0
- package/cjs/domain/contexts/commonContext.d.ts +2 -0
- package/cjs/domain/contexts/commonContext.js +13 -0
- package/cjs/domain/contexts/commonContext.js.map +1 -0
- package/cjs/domain/contexts/internalContext.d.ts +7 -0
- package/cjs/domain/contexts/internalContext.js +11 -0
- package/cjs/domain/contexts/internalContext.js.map +1 -0
- package/cjs/domain/contexts/rumInternalContext.d.ts +2 -0
- package/cjs/domain/contexts/rumInternalContext.js +32 -0
- package/cjs/domain/contexts/rumInternalContext.js.map +1 -0
- package/cjs/domain/contexts/sessionContext.d.ts +4 -0
- package/cjs/domain/contexts/sessionContext.js +20 -0
- package/cjs/domain/contexts/sessionContext.js.map +1 -0
- package/cjs/domain/contexts/trackingConsentContext.d.ts +3 -0
- package/cjs/domain/contexts/trackingConsentContext.js +14 -0
- package/cjs/domain/contexts/trackingConsentContext.js.map +1 -0
- package/cjs/domain/createErrorFieldFromRawError.d.ts +10 -0
- package/cjs/domain/createErrorFieldFromRawError.js +15 -0
- package/cjs/domain/createErrorFieldFromRawError.js.map +1 -0
- package/cjs/domain/hooks.d.ts +28 -0
- package/cjs/domain/hooks.js +13 -0
- package/cjs/domain/hooks.js.map +1 -0
- package/cjs/domain/lifeCycle.d.ts +24 -0
- package/cjs/domain/lifeCycle.js +6 -0
- package/cjs/domain/lifeCycle.js.map +1 -0
- package/cjs/domain/logger/isAuthorized.d.ts +17 -0
- package/cjs/domain/logger/isAuthorized.js +34 -0
- package/cjs/domain/logger/isAuthorized.js.map +1 -0
- package/cjs/domain/logger/loggerCollection.d.ts +7 -0
- package/cjs/domain/logger/loggerCollection.js +47 -0
- package/cjs/domain/logger/loggerCollection.js.map +1 -0
- package/cjs/domain/logger.d.ts +48 -0
- package/cjs/domain/logger.js +112 -0
- package/cjs/domain/logger.js.map +1 -0
- package/cjs/domain/networkError/networkErrorCollection.d.ts +9 -0
- package/cjs/domain/networkError/networkErrorCollection.js +57 -0
- package/cjs/domain/networkError/networkErrorCollection.js.map +1 -0
- package/cjs/domain/plugins.d.ts +49 -0
- package/cjs/domain/plugins.js +12 -0
- package/cjs/domain/plugins.js.map +1 -0
- package/cjs/domain/remoteSdkConfiguration.d.ts +26 -0
- package/cjs/domain/remoteSdkConfiguration.js +67 -0
- package/cjs/domain/remoteSdkConfiguration.js.map +1 -0
- package/cjs/domain/report/reportCollection.d.ts +13 -0
- package/cjs/domain/report/reportCollection.js +30 -0
- package/cjs/domain/report/reportCollection.js.map +1 -0
- package/cjs/domain/reportError.d.ts +2 -0
- package/cjs/domain/reportError.js +20 -0
- package/cjs/domain/reportError.js.map +1 -0
- package/cjs/domain/runtimeError/runtimeErrorCollection.d.ts +14 -0
- package/cjs/domain/runtimeError/runtimeErrorCollection.js +29 -0
- package/cjs/domain/runtimeError/runtimeErrorCollection.js.map +1 -0
- package/cjs/domainContext.types.d.ts +11 -0
- package/cjs/entries/main.d.ts +33 -0
- package/cjs/entries/main.js +31 -0
- package/cjs/entries/main.js.map +1 -0
- package/cjs/logsEvent.types.d.ts +192 -0
- package/cjs/rawLogsEvent.types.d.ts +59 -0
- package/cjs/transport/startLogsBatch.d.ts +4 -0
- package/cjs/transport/startLogsBatch.js +22 -0
- package/cjs/transport/startLogsBatch.js.map +1 -0
- package/cjs/transport/startLogsBridge.d.ts +2 -0
- package/cjs/transport/startLogsBridge.js +13 -0
- package/cjs/transport/startLogsBridge.js.map +1 -0
- package/esm/boot/logsPublicApi.mjs +75 -0
- package/esm/boot/logsPublicApi.mjs.map +1 -0
- package/esm/boot/preStartLogs.mjs +105 -0
- package/esm/boot/preStartLogs.mjs.map +1 -0
- package/esm/boot/startLogs.mjs +54 -0
- package/esm/boot/startLogs.mjs.map +1 -0
- package/esm/domain/assembly.mjs +35 -0
- package/esm/domain/assembly.mjs.map +1 -0
- package/esm/domain/configuration.mjs +84 -0
- package/esm/domain/configuration.mjs.map +1 -0
- package/esm/domain/console/consoleCollection.mjs +36 -0
- package/esm/domain/console/consoleCollection.mjs.map +1 -0
- package/esm/domain/contexts/commonContext.mjs +13 -0
- package/esm/domain/contexts/commonContext.mjs.map +1 -0
- package/esm/domain/contexts/internalContext.mjs +11 -0
- package/esm/domain/contexts/internalContext.mjs.map +1 -0
- package/esm/domain/contexts/rumInternalContext.mjs +32 -0
- package/esm/domain/contexts/rumInternalContext.mjs.map +1 -0
- package/esm/domain/contexts/sessionContext.mjs +20 -0
- package/esm/domain/contexts/sessionContext.mjs.map +1 -0
- package/esm/domain/contexts/trackingConsentContext.mjs +14 -0
- package/esm/domain/contexts/trackingConsentContext.mjs.map +1 -0
- package/esm/domain/createErrorFieldFromRawError.mjs +15 -0
- package/esm/domain/createErrorFieldFromRawError.mjs.map +1 -0
- package/esm/domain/hooks.mjs +13 -0
- package/esm/domain/hooks.mjs.map +1 -0
- package/esm/domain/lifeCycle.mjs +7 -0
- package/esm/domain/lifeCycle.mjs.map +1 -0
- package/esm/domain/logger/isAuthorized.mjs +32 -0
- package/esm/domain/logger/isAuthorized.mjs.map +1 -0
- package/esm/domain/logger/loggerCollection.mjs +47 -0
- package/esm/domain/logger/loggerCollection.mjs.map +1 -0
- package/esm/domain/logger.mjs +110 -0
- package/esm/domain/logger.mjs.map +1 -0
- package/esm/domain/networkError/networkErrorCollection.mjs +56 -0
- package/esm/domain/networkError/networkErrorCollection.mjs.map +1 -0
- package/esm/domain/plugins.mjs +12 -0
- package/esm/domain/plugins.mjs.map +1 -0
- package/esm/domain/remoteSdkConfiguration.mjs +65 -0
- package/esm/domain/remoteSdkConfiguration.mjs.map +1 -0
- package/esm/domain/report/reportCollection.mjs +30 -0
- package/esm/domain/report/reportCollection.mjs.map +1 -0
- package/esm/domain/reportError.mjs +20 -0
- package/esm/domain/reportError.mjs.map +1 -0
- package/esm/domain/runtimeError/runtimeErrorCollection.mjs +29 -0
- package/esm/domain/runtimeError/runtimeErrorCollection.mjs.map +1 -0
- package/esm/entries/main.mjs +27 -0
- package/esm/entries/main.mjs.map +1 -0
- package/esm/transport/startLogsBatch.mjs +22 -0
- package/esm/transport/startLogsBatch.mjs.map +1 -0
- package/esm/transport/startLogsBridge.mjs +13 -0
- package/esm/transport/startLogsBridge.mjs.map +1 -0
- package/package.json +53 -3
- package/src/boot/logsPublicApi.ts +427 -0
- package/src/boot/preStartLogs.ts +192 -0
- package/src/boot/startLogs.ts +83 -0
- package/src/domain/assembly.ts +73 -0
- package/src/domain/configuration.ts +176 -0
- package/src/domain/console/consoleCollection.ts +58 -0
- package/src/domain/contexts/commonContext.ts +15 -0
- package/src/domain/contexts/internalContext.ts +19 -0
- package/src/domain/contexts/rumInternalContext.ts +60 -0
- package/src/domain/contexts/sessionContext.ts +34 -0
- package/src/domain/contexts/trackingConsentContext.ts +18 -0
- package/src/domain/createErrorFieldFromRawError.ts +22 -0
- package/src/domain/hooks.ts +40 -0
- package/src/domain/lifeCycle.ts +25 -0
- package/src/domain/logger/isAuthorized.ts +33 -0
- package/src/domain/logger/loggerCollection.ts +69 -0
- package/src/domain/logger.ts +202 -0
- package/src/domain/networkError/networkErrorCollection.ts +104 -0
- package/src/domain/plugins.ts +72 -0
- package/src/domain/remoteSdkConfiguration.ts +105 -0
- package/src/domain/report/reportCollection.ts +47 -0
- package/src/domain/reportError.ts +20 -0
- package/src/domain/runtimeError/runtimeErrorCollection.ts +51 -0
- package/src/domainContext.types.ts +21 -0
- package/src/entries/main.ts +65 -0
- package/src/logsEvent.types.ts +198 -0
- package/src/rawLogsEvent.types.ts +74 -0
- package/src/transport/startLogsBatch.ts +29 -0
- package/src/transport/startLogsBridge.ts +13 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Logger } from "../domain/logger.mjs";
|
|
2
|
+
import { buildCommonContext } from "../domain/contexts/commonContext.mjs";
|
|
3
|
+
import { callPluginsMethod } from "../domain/plugins.mjs";
|
|
4
|
+
import { startLogs } from "./startLogs.mjs";
|
|
5
|
+
import { createPreStartStrategy } from "./preStartLogs.mjs";
|
|
6
|
+
import { deepClone } from "@kubesense/kubesense-js-core/util";
|
|
7
|
+
import { ContextManagerMethod, CustomerContextKey, addTelemetryUsage, createTrackingConsentState, defineContextMethod, displayAlreadyInitializedError, makePublicApi, mockable, sanitize, startBufferingData } from "@kubesense/kubesense-browser-core";
|
|
8
|
+
import { callMonitored, monitor } from "@kubesense/kubesense-js-core/monitor";
|
|
9
|
+
//#region src/boot/logsPublicApi.ts
|
|
10
|
+
function makeLogsPublicApi(options = {}) {
|
|
11
|
+
const trackingConsentState = createTrackingConsentState();
|
|
12
|
+
const bufferedDataObservable = startBufferingData().observable;
|
|
13
|
+
let strategy = createPreStartStrategy(buildCommonContext, trackingConsentState, (configuration, logsSessionManager, hooks) => {
|
|
14
|
+
const startLogsResult = mockable(startLogs)(configuration, logsSessionManager, buildCommonContext, bufferedDataObservable, hooks);
|
|
15
|
+
strategy = createPostStartStrategy(strategy, startLogsResult);
|
|
16
|
+
callPluginsMethod(configuration.plugins, "onLogsStart", { handleLog: startLogsResult.handleLog });
|
|
17
|
+
return startLogsResult;
|
|
18
|
+
}, options.sdkName);
|
|
19
|
+
const getStrategy = () => strategy;
|
|
20
|
+
const customLoggers = {};
|
|
21
|
+
const mainLogger = new Logger((...params) => strategy.handleLog(...params));
|
|
22
|
+
const logsPublicApi = makePublicApi({
|
|
23
|
+
logger: mainLogger,
|
|
24
|
+
init: (initConfiguration) => {
|
|
25
|
+
const errorStack = (/* @__PURE__ */ new Error()).stack;
|
|
26
|
+
callMonitored(() => strategy.init(initConfiguration, logsPublicApi, errorStack));
|
|
27
|
+
},
|
|
28
|
+
setTrackingConsent: monitor((trackingConsent) => {
|
|
29
|
+
trackingConsentState.update(trackingConsent);
|
|
30
|
+
addTelemetryUsage({
|
|
31
|
+
feature: "set-tracking-consent",
|
|
32
|
+
tracking_consent: trackingConsent
|
|
33
|
+
});
|
|
34
|
+
}),
|
|
35
|
+
getGlobalContext: defineContextMethod(getStrategy, CustomerContextKey.globalContext, ContextManagerMethod.getContext),
|
|
36
|
+
setGlobalContext: defineContextMethod(getStrategy, CustomerContextKey.globalContext, ContextManagerMethod.setContext),
|
|
37
|
+
setGlobalContextProperty: defineContextMethod(getStrategy, CustomerContextKey.globalContext, ContextManagerMethod.setContextProperty),
|
|
38
|
+
removeGlobalContextProperty: defineContextMethod(getStrategy, CustomerContextKey.globalContext, ContextManagerMethod.removeContextProperty),
|
|
39
|
+
clearGlobalContext: defineContextMethod(getStrategy, CustomerContextKey.globalContext, ContextManagerMethod.clearContext),
|
|
40
|
+
createLogger: monitor((name, conf = {}) => {
|
|
41
|
+
customLoggers[name] = new Logger((...params) => strategy.handleLog(...params), sanitize(name), conf.handler, conf.level, sanitize(conf.context));
|
|
42
|
+
return customLoggers[name];
|
|
43
|
+
}),
|
|
44
|
+
getLogger: monitor((name) => customLoggers[name]),
|
|
45
|
+
getInitConfiguration: monitor(() => deepClone(strategy.initConfiguration)),
|
|
46
|
+
getInternalContext: monitor((startTime) => strategy.getInternalContext(startTime)),
|
|
47
|
+
setUser: defineContextMethod(getStrategy, CustomerContextKey.userContext, ContextManagerMethod.setContext),
|
|
48
|
+
getUser: defineContextMethod(getStrategy, CustomerContextKey.userContext, ContextManagerMethod.getContext),
|
|
49
|
+
setUserProperty: defineContextMethod(getStrategy, CustomerContextKey.userContext, ContextManagerMethod.setContextProperty),
|
|
50
|
+
removeUserProperty: defineContextMethod(getStrategy, CustomerContextKey.userContext, ContextManagerMethod.removeContextProperty),
|
|
51
|
+
clearUser: defineContextMethod(getStrategy, CustomerContextKey.userContext, ContextManagerMethod.clearContext),
|
|
52
|
+
setAccount: defineContextMethod(getStrategy, CustomerContextKey.accountContext, ContextManagerMethod.setContext),
|
|
53
|
+
getAccount: defineContextMethod(getStrategy, CustomerContextKey.accountContext, ContextManagerMethod.getContext),
|
|
54
|
+
setAccountProperty: defineContextMethod(getStrategy, CustomerContextKey.accountContext, ContextManagerMethod.setContextProperty),
|
|
55
|
+
removeAccountProperty: defineContextMethod(getStrategy, CustomerContextKey.accountContext, ContextManagerMethod.removeContextProperty),
|
|
56
|
+
clearAccount: defineContextMethod(getStrategy, CustomerContextKey.accountContext, ContextManagerMethod.clearContext)
|
|
57
|
+
});
|
|
58
|
+
return logsPublicApi;
|
|
59
|
+
}
|
|
60
|
+
function createPostStartStrategy(preStartStrategy, startLogsResult) {
|
|
61
|
+
return {
|
|
62
|
+
...preStartStrategy,
|
|
63
|
+
init: (initConfiguration) => {
|
|
64
|
+
displayAlreadyInitializedError("KUBESENSE_LOGS", initConfiguration);
|
|
65
|
+
},
|
|
66
|
+
getInternalContext: startLogsResult.getInternalContext,
|
|
67
|
+
globalContext: startLogsResult.globalContext,
|
|
68
|
+
userContext: startLogsResult.userContext,
|
|
69
|
+
accountContext: startLogsResult.accountContext
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { makeLogsPublicApi };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=logsPublicApi.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logsPublicApi.mjs","names":[],"sources":["../../src/boot/logsPublicApi.ts"],"sourcesContent":["import type {\n TrackingConsent,\n PublicApi,\n ContextManager,\n Account,\n Context,\n User,\n} from '@kubesense/kubesense-browser-core'\nimport {\n ContextManagerMethod,\n CustomerContextKey,\n addTelemetryUsage,\n makePublicApi,\n sanitize,\n displayAlreadyInitializedError,\n createTrackingConsentState,\n defineContextMethod,\n startBufferingData,\n mockable,\n} from '@kubesense/kubesense-browser-core'\nimport { monitor, callMonitored } from '@kubesense/kubesense-js-core/monitor'\nimport { deepClone } from '@kubesense/kubesense-js-core/util'\nimport type { LogsInitConfiguration } from '../domain/configuration'\nimport type { HandlerType } from '../domain/logger'\nimport type { StatusType } from '../domain/logger/isAuthorized'\nimport { Logger } from '../domain/logger'\nimport { buildCommonContext } from '../domain/contexts/commonContext'\nimport { callPluginsMethod } from '../domain/plugins'\nimport type { InternalContext } from '../domain/contexts/internalContext'\nimport type { StartLogsResult } from './startLogs'\nimport { startLogs } from './startLogs'\nimport { createPreStartStrategy } from './preStartLogs'\n\nexport interface LoggerConfiguration {\n level?: StatusType\n handler?: HandlerType | HandlerType[]\n context?: object\n}\n\n/**\n * Public API for the Logs browser SDK.\n *\n * See [Browser Log Collection](https://docs.kubesense.ai/logs/log_collection/javascript) for further information.\n *\n * @category Main\n */\nexport interface LogsPublicApi extends PublicApi {\n /**\n * The default logger\n *\n * @category Logger\n */\n logger: Logger\n\n /**\n * Init the Logs browser SDK.\n *\n * See [Browser Log Collection](https://docs.kubesense.ai/logs/log_collection/javascript) for further information.\n *\n * @category Init\n * @param initConfiguration - Configuration options of the SDK\n */\n init: (initConfiguration: LogsInitConfiguration) => void\n\n /**\n * Set the tracking consent of the current user.\n *\n * Logs will be sent only if it is set to \"granted\". This value won't be stored by the library\n * across page loads: you will need to call this method or set the appropriate `trackingConsent`\n * field in the init() method at each page load.\n *\n * If this method is called before the init() method, the provided value will take precedence\n * over the one provided as initialization parameter.\n *\n * See [User tracking consent](https://docs.kubesense.ai/logs/log_collection/javascript/#user-tracking-consent) for further information.\n *\n * @category Privacy\n * @param trackingConsent - The user tracking consent\n */\n setTrackingConsent: (trackingConsent: TrackingConsent) => void\n\n /**\n * Set the global context information to all events, stored in `@context`\n * See [Global context](https://docs.kubesense.ai/logs/log_collection/javascript/#overwrite-context) for further information.\n *\n * @category Context - Global Context\n * @param context - Global context\n */\n setGlobalContext: (context: any) => void\n\n /**\n * Get the global Context\n *\n * See [Global context](https://docs.kubesense.ai/logs/log_collection/javascript/#overwrite-context) for further information.\n *\n * @category Context - Global Context\n */\n getGlobalContext: () => Context\n\n /**\n * Set or update a global context property, stored in `@context.<key>`\n *\n * See [Global context](https://docs.kubesense.ai/logs/log_collection/javascript/#overwrite-context) for further information.\n *\n * @category Context - Global Context\n * @param key - Key of the property\n * @param value - Value of the property\n */\n setGlobalContextProperty: (key: any, value: any) => void\n\n /**\n * Remove a global context property\n *\n * See [Global context](https://docs.kubesense.ai/logs/log_collection/javascript/#overwrite-context) for further information.\n *\n * @category Context - Global Context\n */\n removeGlobalContextProperty: (key: any) => void\n\n /**\n * Clear the global context\n *\n * See [Global context](https://docs.kubesense.ai/logs/log_collection/javascript/#overwrite-context) for further information.\n *\n * @category Context - Global Context\n */\n clearGlobalContext: () => void\n\n /**\n * Set user information to all events, stored in `@usr`\n *\n * See [User session](https://docs.kubesense.ai/logs/log_collection/javascript/#user-context) for further information.\n *\n * @category Context - User\n * @param newUser - User information\n */\n setUser(newUser: User & { id: string }): void\n\n /**\n * Set user information to all events, stored in `@usr`\n *\n * @category Context - User\n * @deprecated You must specify a user id, favor using {@link setUser} instead\n * @param newUser - User information with optional id\n */\n setUser(newUser: User): void\n\n /**\n * Get user information\n *\n * See [User session](https://docs.kubesense.ai/logs/log_collection/javascript/#user-context) for further information.\n *\n * @category Context - User\n * @returns User information\n */\n getUser: () => Context\n\n /**\n * Set or update the user property, stored in `@usr.<key>`\n *\n * See [User session](https://docs.kubesense.ai/logs/log_collection/javascript/#user-context) for further information.\n *\n * @category Context - User\n * @param key - Key of the property\n * @param property - Value of the property\n */\n setUserProperty: (key: any, property: any) => void\n\n /**\n * Remove a user property\n *\n * @category Context - User\n * @param key - Key of the property to remove\n * @see [User session](https://docs.kubesense.ai/logs/log_collection/javascript/#user-context) for further information.\n */\n removeUserProperty: (key: any) => void\n\n /**\n * Clear all user information\n *\n * See [User session](https://docs.kubesense.ai/logs/log_collection/javascript/#user-context) for further information.\n *\n * @category Context - User\n */\n clearUser: () => void\n\n /**\n * Set account information to all events, stored in `@account`\n *\n * @category Context - Account\n * @param newAccount - Account information\n */\n setAccount: (newAccount: Account) => void\n\n /**\n * Get account information\n *\n * @category Context - Account\n * @returns Account information\n */\n getAccount: () => Context\n\n /**\n * Set or update the account property, stored in `@account.<key>`\n *\n * @category Context - Account\n * @param key - Key of the property\n * @param property - Value of the property\n */\n setAccountProperty: (key: string, property: any) => void\n\n /**\n * Remove an account property\n *\n * @category Context - Account\n * @param key - Key of the property to remove\n */\n removeAccountProperty: (key: string) => void\n\n /**\n * Clear all account information\n *\n * @category Context - Account\n * @returns Clear all account information\n */\n clearAccount: () => void\n\n /**\n * The KubeSense browser logs SDK contains a default logger `KUBESENSE_LOGS.logger`, but this API allows to create different ones.\n *\n * See [Define multiple loggers](https://docs.kubesense.ai/logs/log_collection/javascript/#define-multiple-loggers) for further information.\n *\n * @category Logger\n * @param name - Name of the logger\n * @param conf - Configuration of the logger (level, handler, context)\n */\n createLogger: (name: string, conf?: LoggerConfiguration) => Logger\n\n /**\n * Get a logger\n *\n * See [Define multiple loggers](https://docs.kubesense.ai/logs/log_collection/javascript/#define-multiple-loggers) for further information.\n *\n * @category Logger\n * @param name - Name of the logger\n */\n getLogger: (name: string) => Logger | undefined\n\n /**\n * Get the init configuration\n *\n * @category Init\n * @returns The init configuration\n */\n getInitConfiguration: () => LogsInitConfiguration | undefined\n\n /**\n * [Internal API] Get the internal SDK context\n *\n * See [Access internal context](https://docs.kubesense.ai/logs/log_collection/javascript/#access-internal-context) for further information.\n *\n * @internal\n */\n getInternalContext: (startTime?: number) => InternalContext | undefined\n}\n\nexport interface Strategy {\n init: (initConfiguration: LogsInitConfiguration, publicApi: LogsPublicApi, errorStack?: string) => void\n initConfiguration: LogsInitConfiguration | undefined\n globalContext: ContextManager\n accountContext: ContextManager\n userContext: ContextManager\n getInternalContext: StartLogsResult['getInternalContext']\n handleLog: StartLogsResult['handleLog']\n}\n\nexport interface LogsPublicApiOptions {\n sdkName?: string\n}\n\nexport function makeLogsPublicApi(options: LogsPublicApiOptions = {}): LogsPublicApi {\n const trackingConsentState = createTrackingConsentState()\n const bufferedDataObservable = startBufferingData().observable\n\n let strategy = createPreStartStrategy(\n buildCommonContext,\n trackingConsentState,\n (configuration, logsSessionManager, hooks) => {\n const startLogsResult = mockable(startLogs)(\n configuration,\n logsSessionManager,\n buildCommonContext,\n bufferedDataObservable,\n hooks\n )\n\n strategy = createPostStartStrategy(strategy, startLogsResult)\n callPluginsMethod(configuration.plugins, 'onLogsStart', {\n handleLog: startLogsResult.handleLog,\n })\n return startLogsResult\n },\n options.sdkName\n )\n\n const getStrategy = () => strategy\n\n const customLoggers: { [name: string]: Logger | undefined } = {}\n\n const mainLogger = new Logger((...params) => strategy.handleLog(...params))\n\n const logsPublicApi: LogsPublicApi = makePublicApi<LogsPublicApi>({\n logger: mainLogger,\n\n init: (initConfiguration) => {\n const errorStack = new Error().stack\n callMonitored(() => strategy.init(initConfiguration, logsPublicApi, errorStack))\n },\n\n setTrackingConsent: monitor((trackingConsent) => {\n trackingConsentState.update(trackingConsent)\n addTelemetryUsage({ feature: 'set-tracking-consent', tracking_consent: trackingConsent })\n }),\n\n getGlobalContext: defineContextMethod(\n getStrategy,\n CustomerContextKey.globalContext,\n ContextManagerMethod.getContext\n ),\n setGlobalContext: defineContextMethod(\n getStrategy,\n CustomerContextKey.globalContext,\n ContextManagerMethod.setContext\n ),\n\n setGlobalContextProperty: defineContextMethod(\n getStrategy,\n CustomerContextKey.globalContext,\n ContextManagerMethod.setContextProperty\n ),\n\n removeGlobalContextProperty: defineContextMethod(\n getStrategy,\n CustomerContextKey.globalContext,\n ContextManagerMethod.removeContextProperty\n ),\n\n clearGlobalContext: defineContextMethod(\n getStrategy,\n CustomerContextKey.globalContext,\n ContextManagerMethod.clearContext\n ),\n\n createLogger: monitor((name, conf = {}) => {\n customLoggers[name] = new Logger(\n (...params) => strategy.handleLog(...params),\n sanitize(name),\n conf.handler,\n conf.level,\n sanitize(conf.context) as object\n )\n\n return customLoggers[name]\n }),\n\n getLogger: monitor((name) => customLoggers[name]),\n\n getInitConfiguration: monitor(() => deepClone(strategy.initConfiguration)),\n\n getInternalContext: monitor((startTime) => strategy.getInternalContext(startTime)),\n\n setUser: defineContextMethod(getStrategy, CustomerContextKey.userContext, ContextManagerMethod.setContext),\n\n getUser: defineContextMethod(getStrategy, CustomerContextKey.userContext, ContextManagerMethod.getContext),\n\n setUserProperty: defineContextMethod(\n getStrategy,\n CustomerContextKey.userContext,\n ContextManagerMethod.setContextProperty\n ),\n\n removeUserProperty: defineContextMethod(\n getStrategy,\n CustomerContextKey.userContext,\n ContextManagerMethod.removeContextProperty\n ),\n\n clearUser: defineContextMethod(getStrategy, CustomerContextKey.userContext, ContextManagerMethod.clearContext),\n\n setAccount: defineContextMethod(getStrategy, CustomerContextKey.accountContext, ContextManagerMethod.setContext),\n\n getAccount: defineContextMethod(getStrategy, CustomerContextKey.accountContext, ContextManagerMethod.getContext),\n\n setAccountProperty: defineContextMethod(\n getStrategy,\n CustomerContextKey.accountContext,\n ContextManagerMethod.setContextProperty\n ),\n\n removeAccountProperty: defineContextMethod(\n getStrategy,\n CustomerContextKey.accountContext,\n ContextManagerMethod.removeContextProperty\n ),\n\n clearAccount: defineContextMethod(\n getStrategy,\n CustomerContextKey.accountContext,\n ContextManagerMethod.clearContext\n ),\n })\n\n return logsPublicApi\n}\n\nfunction createPostStartStrategy(preStartStrategy: Strategy, startLogsResult: StartLogsResult): Strategy {\n return {\n ...preStartStrategy,\n init: (initConfiguration: LogsInitConfiguration) => {\n displayAlreadyInitializedError('KUBESENSE_LOGS', initConfiguration)\n },\n getInternalContext: startLogsResult.getInternalContext,\n globalContext: startLogsResult.globalContext,\n userContext: startLogsResult.userContext,\n accountContext: startLogsResult.accountContext,\n }\n}\n"],"mappings":";;;;;;;;;AAwRA,SAAgB,kBAAkB,UAAgC,CAAC,GAAkB;CACnF,MAAM,uBAAuB,2BAA2B;CACxD,MAAM,yBAAyB,mBAAmB,CAAC,CAAC;CAEpD,IAAI,WAAW,uBACb,oBACA,uBACC,eAAe,oBAAoB,UAAU;EAC5C,MAAM,kBAAkB,SAAS,SAAS,CAAC,CACzC,eACA,oBACA,oBACA,wBACA,KACF;EAEA,WAAW,wBAAwB,UAAU,eAAe;EAC5D,kBAAkB,cAAc,SAAS,eAAe,EACtD,WAAW,gBAAgB,UAC7B,CAAC;EACD,OAAO;CACT,GACA,QAAQ,OACV;CAEA,MAAM,oBAAoB;CAE1B,MAAM,gBAAwD,CAAC;CAE/D,MAAM,aAAa,IAAI,QAAQ,GAAG,WAAW,SAAS,UAAU,GAAG,MAAM,CAAC;CAE1E,MAAM,gBAA+B,cAA6B;EAChE,QAAQ;EAER,OAAO,sBAAsB;GAC3B,MAAM,8BAAa,IAAI,MAAM,EAAA,CAAE;GAC/B,oBAAoB,SAAS,KAAK,mBAAmB,eAAe,UAAU,CAAC;EACjF;EAEA,oBAAoB,SAAS,oBAAoB;GAC/C,qBAAqB,OAAO,eAAe;GAC3C,kBAAkB;IAAE,SAAS;IAAwB,kBAAkB;GAAgB,CAAC;EAC1F,CAAC;EAED,kBAAkB,oBAChB,aACA,mBAAmB,eACnB,qBAAqB,UACvB;EACA,kBAAkB,oBAChB,aACA,mBAAmB,eACnB,qBAAqB,UACvB;EAEA,0BAA0B,oBACxB,aACA,mBAAmB,eACnB,qBAAqB,kBACvB;EAEA,6BAA6B,oBAC3B,aACA,mBAAmB,eACnB,qBAAqB,qBACvB;EAEA,oBAAoB,oBAClB,aACA,mBAAmB,eACnB,qBAAqB,YACvB;EAEA,cAAc,SAAS,MAAM,OAAO,CAAC,MAAM;GACzC,cAAc,QAAQ,IAAI,QACvB,GAAG,WAAW,SAAS,UAAU,GAAG,MAAM,GAC3C,SAAS,IAAI,GACb,KAAK,SACL,KAAK,OACL,SAAS,KAAK,OAAO,CACvB;GAEA,OAAO,cAAc;EACvB,CAAC;EAED,WAAW,SAAS,SAAS,cAAc,KAAK;EAEhD,sBAAsB,cAAc,UAAU,SAAS,iBAAiB,CAAC;EAEzE,oBAAoB,SAAS,cAAc,SAAS,mBAAmB,SAAS,CAAC;EAEjF,SAAS,oBAAoB,aAAa,mBAAmB,aAAa,qBAAqB,UAAU;EAEzG,SAAS,oBAAoB,aAAa,mBAAmB,aAAa,qBAAqB,UAAU;EAEzG,iBAAiB,oBACf,aACA,mBAAmB,aACnB,qBAAqB,kBACvB;EAEA,oBAAoB,oBAClB,aACA,mBAAmB,aACnB,qBAAqB,qBACvB;EAEA,WAAW,oBAAoB,aAAa,mBAAmB,aAAa,qBAAqB,YAAY;EAE7G,YAAY,oBAAoB,aAAa,mBAAmB,gBAAgB,qBAAqB,UAAU;EAE/G,YAAY,oBAAoB,aAAa,mBAAmB,gBAAgB,qBAAqB,UAAU;EAE/G,oBAAoB,oBAClB,aACA,mBAAmB,gBACnB,qBAAqB,kBACvB;EAEA,uBAAuB,oBACrB,aACA,mBAAmB,gBACnB,qBAAqB,qBACvB;EAEA,cAAc,oBACZ,aACA,mBAAmB,gBACnB,qBAAqB,YACvB;CACF,CAAC;CAED,OAAO;AACT;AAEA,SAAS,wBAAwB,kBAA4B,iBAA4C;CACvG,OAAO;EACL,GAAG;EACH,OAAO,sBAA6C;GAClD,+BAA+B,kBAAkB,iBAAiB;EACpE;EACA,oBAAoB,gBAAgB;EACpC,eAAe,gBAAgB;EAC/B,aAAa,gBAAgB;EAC7B,gBAAgB,gBAAgB;CAClC;AACF"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { callPluginsMethod } from "../domain/plugins.mjs";
|
|
2
|
+
import { createHooks } from "../domain/hooks.mjs";
|
|
3
|
+
import { serializeLogsConfiguration, validateAndBuildLogsConfiguration } from "../domain/configuration.mjs";
|
|
4
|
+
import { applyCachedLogsSdkConfiguration, scheduleLogsSdkConfigurationRefresh } from "../domain/remoteSdkConfiguration.mjs";
|
|
5
|
+
import { startTrackingConsentContext } from "../domain/contexts/trackingConsentContext.mjs";
|
|
6
|
+
import { BufferedObservable, CustomerContextKey, TelemetryService, addTelemetryConfiguration, addTelemetryDebug, bufferContextCalls, buildAccountContextManager, buildGlobalContextManager, buildUserContextManager, canUseEventBridge, display, displayAlreadyInitializedError, initFeatureFlags, isAllowedTrackingOrigins, mockable, noop, setAllowUntrustedEvents, startSessionManager, startSessionManagerStub, startTelemetry, startTelemetrySessionContext } from "@kubesense/kubesense-browser-core";
|
|
7
|
+
import { monitorError } from "@kubesense/kubesense-js-core/monitor";
|
|
8
|
+
import { timeStampNow } from "@kubesense/kubesense-js-core/time";
|
|
9
|
+
//#region src/boot/preStartLogs.ts
|
|
10
|
+
function createPreStartStrategy(getCommonContext, trackingConsentState, doStartLogs, sdkName) {
|
|
11
|
+
const bufferApiCalls = new BufferedObservable(500, (count) => {
|
|
12
|
+
addTelemetryDebug("preStartLogs buffer data lost", { count });
|
|
13
|
+
});
|
|
14
|
+
const globalContext = buildGlobalContextManager();
|
|
15
|
+
bufferContextCalls(globalContext, CustomerContextKey.globalContext, bufferApiCalls);
|
|
16
|
+
const accountContext = buildAccountContextManager();
|
|
17
|
+
bufferContextCalls(accountContext, CustomerContextKey.accountContext, bufferApiCalls);
|
|
18
|
+
const userContext = buildUserContextManager();
|
|
19
|
+
bufferContextCalls(userContext, CustomerContextKey.userContext, bufferApiCalls);
|
|
20
|
+
let cachedInitConfiguration;
|
|
21
|
+
let cachedConfiguration;
|
|
22
|
+
let sessionManager;
|
|
23
|
+
const hooks = createHooks();
|
|
24
|
+
const trackingConsentStateSubscription = trackingConsentState.observable.subscribe(tryStartLogs);
|
|
25
|
+
function tryStartLogs() {
|
|
26
|
+
if (!cachedConfiguration || !cachedInitConfiguration || !sessionManager) return;
|
|
27
|
+
trackingConsentStateSubscription.unsubscribe();
|
|
28
|
+
const startLogsResult = doStartLogs(cachedConfiguration, sessionManager, hooks);
|
|
29
|
+
bufferApiCalls.subscribe((callback) => callback(startLogsResult));
|
|
30
|
+
bufferApiCalls.unbuffer();
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
init(initConfiguration, publicApi, errorStack) {
|
|
34
|
+
if (!initConfiguration) {
|
|
35
|
+
display.error("Missing configuration");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
initFeatureFlags(initConfiguration.enableExperimentalFeatures);
|
|
39
|
+
setAllowUntrustedEvents(initConfiguration.allowUntrustedEvents);
|
|
40
|
+
if (canUseEventBridge()) initConfiguration = overrideInitConfigurationForBridge(initConfiguration);
|
|
41
|
+
const remoteSdkConfigurationEnabled = !!initConfiguration.enableRemoteSdkConfiguration;
|
|
42
|
+
const refreshRemoteSdkConfiguration = () => {
|
|
43
|
+
if (remoteSdkConfigurationEnabled) scheduleLogsSdkConfigurationRefresh(initConfiguration).catch(noop);
|
|
44
|
+
};
|
|
45
|
+
if (remoteSdkConfigurationEnabled) {
|
|
46
|
+
const cachedSdkConfiguration = applyCachedLogsSdkConfiguration(initConfiguration);
|
|
47
|
+
initConfiguration = cachedSdkConfiguration.initConfiguration;
|
|
48
|
+
if (!cachedSdkConfiguration.logsEnabled) {
|
|
49
|
+
cachedInitConfiguration = initConfiguration;
|
|
50
|
+
refreshRemoteSdkConfiguration();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
cachedInitConfiguration = initConfiguration;
|
|
55
|
+
if (cachedConfiguration) {
|
|
56
|
+
displayAlreadyInitializedError("KUBESENSE_LOGS", initConfiguration);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
callPluginsMethod(initConfiguration.plugins, "onInit", {
|
|
60
|
+
initConfiguration,
|
|
61
|
+
publicApi,
|
|
62
|
+
registerAssembleEventHook: hooks.assembleEvent.register
|
|
63
|
+
});
|
|
64
|
+
const configuration = validateAndBuildLogsConfiguration(initConfiguration);
|
|
65
|
+
if (!configuration || !isAllowedTrackingOrigins(configuration, errorStack ?? "")) {
|
|
66
|
+
refreshRemoteSdkConfiguration();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
cachedConfiguration = configuration;
|
|
70
|
+
trackingConsentState.tryToInit(configuration.trackingConsent);
|
|
71
|
+
trackingConsentState.onGrantedOnce(() => {
|
|
72
|
+
startTrackingConsentContext(hooks, trackingConsentState);
|
|
73
|
+
mockable(startTelemetry)(TelemetryService.LOGS, configuration, hooks.assembleTelemetry, sdkName);
|
|
74
|
+
(canUseEventBridge() ? startSessionManagerStub() : mockable(startSessionManager)(configuration, trackingConsentState)).then((newSessionManager) => {
|
|
75
|
+
if (!newSessionManager) return;
|
|
76
|
+
sessionManager = newSessionManager;
|
|
77
|
+
startTelemetrySessionContext(hooks.assembleTelemetry, sessionManager);
|
|
78
|
+
addTelemetryConfiguration(serializeLogsConfiguration(initConfiguration));
|
|
79
|
+
tryStartLogs();
|
|
80
|
+
refreshRemoteSdkConfiguration();
|
|
81
|
+
}).catch(monitorError);
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
get initConfiguration() {
|
|
85
|
+
return cachedInitConfiguration;
|
|
86
|
+
},
|
|
87
|
+
globalContext,
|
|
88
|
+
accountContext,
|
|
89
|
+
userContext,
|
|
90
|
+
getInternalContext: noop,
|
|
91
|
+
handleLog(message, statusType, handlingStack, context = getCommonContext(), date = timeStampNow()) {
|
|
92
|
+
bufferApiCalls.notify((startLogsResult) => startLogsResult.handleLog(message, statusType, handlingStack, context, date));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function overrideInitConfigurationForBridge(initConfiguration) {
|
|
97
|
+
return {
|
|
98
|
+
...initConfiguration,
|
|
99
|
+
clientToken: "empty"
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { createPreStartStrategy };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=preStartLogs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preStartLogs.mjs","names":[],"sources":["../../src/boot/preStartLogs.ts"],"sourcesContent":["import { timeStampNow } from '@kubesense/kubesense-js-core/time'\nimport { monitorError } from '@kubesense/kubesense-js-core/monitor'\nimport type { TrackingConsentState, SessionManager } from '@kubesense/kubesense-browser-core'\nimport {\n BufferedObservable,\n canUseEventBridge,\n display,\n displayAlreadyInitializedError,\n initFeatureFlags,\n noop,\n buildAccountContextManager,\n CustomerContextKey,\n bufferContextCalls,\n addTelemetryConfiguration,\n addTelemetryDebug,\n buildGlobalContextManager,\n buildUserContextManager,\n startSessionManager,\n startSessionManagerStub,\n startTelemetry,\n TelemetryService,\n mockable,\n startTelemetrySessionContext,\n setAllowUntrustedEvents,\n isAllowedTrackingOrigins,\n} from '@kubesense/kubesense-browser-core'\nimport type { Hooks } from '../domain/hooks'\nimport { createHooks } from '../domain/hooks'\nimport type { LogsConfiguration, LogsInitConfiguration } from '../domain/configuration'\nimport { serializeLogsConfiguration, validateAndBuildLogsConfiguration } from '../domain/configuration'\nimport { applyCachedLogsSdkConfiguration, scheduleLogsSdkConfigurationRefresh } from '../domain/remoteSdkConfiguration'\nimport type { CommonContext } from '../rawLogsEvent.types'\nimport { startTrackingConsentContext } from '../domain/contexts/trackingConsentContext'\nimport { callPluginsMethod } from '../domain/plugins'\nimport type { Strategy } from './logsPublicApi'\nimport type { StartLogsResult } from './startLogs'\n\nexport type DoStartLogs = (\n configuration: LogsConfiguration,\n sessionManager: SessionManager,\n hooks: Hooks\n) => StartLogsResult\n\nexport function createPreStartStrategy(\n getCommonContext: () => CommonContext,\n trackingConsentState: TrackingConsentState,\n doStartLogs: DoStartLogs,\n sdkName?: string\n): Strategy {\n const BUFFER_LIMIT = 500\n const bufferApiCalls = new BufferedObservable<(startLogsResult: StartLogsResult) => void>(BUFFER_LIMIT, (count) => {\n // monitor-until: 2026-10-14\n addTelemetryDebug('preStartLogs buffer data lost', { count })\n })\n\n // TODO next major: remove the globalContext, accountContextManager, userContext from preStartStrategy and use an empty context instead\n const globalContext = buildGlobalContextManager()\n bufferContextCalls(globalContext, CustomerContextKey.globalContext, bufferApiCalls)\n\n const accountContext = buildAccountContextManager()\n bufferContextCalls(accountContext, CustomerContextKey.accountContext, bufferApiCalls)\n\n const userContext = buildUserContextManager()\n bufferContextCalls(userContext, CustomerContextKey.userContext, bufferApiCalls)\n\n let cachedInitConfiguration: LogsInitConfiguration | undefined\n let cachedConfiguration: LogsConfiguration | undefined\n let sessionManager: SessionManager | undefined\n const hooks = createHooks()\n const trackingConsentStateSubscription = trackingConsentState.observable.subscribe(tryStartLogs)\n\n function tryStartLogs() {\n if (!cachedConfiguration || !cachedInitConfiguration || !sessionManager) {\n return\n }\n\n trackingConsentStateSubscription.unsubscribe()\n const startLogsResult = doStartLogs(cachedConfiguration, sessionManager, hooks)\n\n bufferApiCalls.subscribe((callback) => callback(startLogsResult))\n bufferApiCalls.unbuffer()\n }\n\n return {\n init(initConfiguration, publicApi, errorStack) {\n if (!initConfiguration) {\n display.error('Missing configuration')\n return\n }\n // Set the experimental feature flags as early as possible, so we can use them in most places\n initFeatureFlags(initConfiguration.enableExperimentalFeatures)\n setAllowUntrustedEvents(initConfiguration.allowUntrustedEvents)\n\n if (canUseEventBridge()) {\n initConfiguration = overrideInitConfigurationForBridge(initConfiguration)\n }\n\n const remoteSdkConfigurationEnabled = !!initConfiguration.enableRemoteSdkConfiguration\n\n // A cached document that stops Logs from starting must never be a one-way door: without a\n // refresh on those paths the browser replays the same bad document on every load and can\n // never learn about a corrected one.\n const refreshRemoteSdkConfiguration = () => {\n if (remoteSdkConfigurationEnabled) {\n scheduleLogsSdkConfigurationRefresh(initConfiguration).catch(noop)\n }\n }\n\n if (remoteSdkConfigurationEnabled) {\n // Reading the cached document is synchronous and network-free, so it does not delay\n // initialization. The document fetched below only applies from the next page load.\n const cachedSdkConfiguration = applyCachedLogsSdkConfiguration(initConfiguration)\n initConfiguration = cachedSdkConfiguration.initConfiguration\n\n if (!cachedSdkConfiguration.logsEnabled) {\n // Logs is switched off from the dashboard. Still refresh the document, otherwise the\n // switch would be one-way: the SDK could never learn it has been turned back on.\n cachedInitConfiguration = initConfiguration\n refreshRemoteSdkConfiguration()\n return\n }\n }\n\n // Expose the initial configuration regardless of initialization success.\n cachedInitConfiguration = initConfiguration\n\n if (cachedConfiguration) {\n displayAlreadyInitializedError('KUBESENSE_LOGS', initConfiguration)\n return\n }\n\n callPluginsMethod(initConfiguration.plugins, 'onInit', {\n initConfiguration,\n publicApi,\n registerAssembleEventHook: hooks.assembleEvent.register,\n })\n\n const configuration = validateAndBuildLogsConfiguration(initConfiguration)\n if (!configuration || !isAllowedTrackingOrigins(configuration, errorStack ?? '')) {\n refreshRemoteSdkConfiguration()\n return\n }\n\n cachedConfiguration = configuration\n\n trackingConsentState.tryToInit(configuration.trackingConsent)\n\n trackingConsentState.onGrantedOnce(() => {\n startTrackingConsentContext(hooks, trackingConsentState)\n mockable(startTelemetry)(TelemetryService.LOGS, configuration, hooks.assembleTelemetry, sdkName)\n const sessionManagerPromise = canUseEventBridge()\n ? startSessionManagerStub()\n : mockable(startSessionManager)(configuration, trackingConsentState)\n\n void sessionManagerPromise\n .then((newSessionManager) => {\n if (!newSessionManager) {\n return\n }\n sessionManager = newSessionManager\n startTelemetrySessionContext(hooks.assembleTelemetry, sessionManager)\n addTelemetryConfiguration(serializeLogsConfiguration(initConfiguration))\n tryStartLogs()\n\n // Fire-and-forget, after the SDK is running: refreshes the cache for the next page load.\n refreshRemoteSdkConfiguration()\n })\n .catch(monitorError)\n })\n },\n\n get initConfiguration() {\n return cachedInitConfiguration\n },\n\n globalContext,\n accountContext,\n userContext,\n\n getInternalContext: noop as () => undefined,\n\n handleLog(message, statusType, handlingStack, context = getCommonContext(), date = timeStampNow()) {\n bufferApiCalls.notify((startLogsResult) =>\n startLogsResult.handleLog(message, statusType, handlingStack, context, date)\n )\n },\n }\n}\n\nfunction overrideInitConfigurationForBridge(initConfiguration: LogsInitConfiguration): LogsInitConfiguration {\n return { ...initConfiguration, clientToken: 'empty' }\n}\n"],"mappings":";;;;;;;;;AA2CA,SAAgB,uBACd,kBACA,sBACA,aACA,SACU;CAEV,MAAM,iBAAiB,IAAI,mBAA+D,MAAe,UAAU;EAEjH,kBAAkB,iCAAiC,EAAE,MAAM,CAAC;CAC9D,CAAC;CAGD,MAAM,gBAAgB,0BAA0B;CAChD,mBAAmB,eAAe,mBAAmB,eAAe,cAAc;CAElF,MAAM,iBAAiB,2BAA2B;CAClD,mBAAmB,gBAAgB,mBAAmB,gBAAgB,cAAc;CAEpF,MAAM,cAAc,wBAAwB;CAC5C,mBAAmB,aAAa,mBAAmB,aAAa,cAAc;CAE9E,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM,QAAQ,YAAY;CAC1B,MAAM,mCAAmC,qBAAqB,WAAW,UAAU,YAAY;CAE/F,SAAS,eAAe;EACtB,IAAI,CAAC,uBAAuB,CAAC,2BAA2B,CAAC,gBACvD;EAGF,iCAAiC,YAAY;EAC7C,MAAM,kBAAkB,YAAY,qBAAqB,gBAAgB,KAAK;EAE9E,eAAe,WAAW,aAAa,SAAS,eAAe,CAAC;EAChE,eAAe,SAAS;CAC1B;CAEA,OAAO;EACL,KAAK,mBAAmB,WAAW,YAAY;GAC7C,IAAI,CAAC,mBAAmB;IACtB,QAAQ,MAAM,uBAAuB;IACrC;GACF;GAEA,iBAAiB,kBAAkB,0BAA0B;GAC7D,wBAAwB,kBAAkB,oBAAoB;GAE9D,IAAI,kBAAkB,GACpB,oBAAoB,mCAAmC,iBAAiB;GAG1E,MAAM,gCAAgC,CAAC,CAAC,kBAAkB;GAK1D,MAAM,sCAAsC;IAC1C,IAAI,+BACF,oCAAoC,iBAAiB,CAAC,CAAC,MAAM,IAAI;GAErE;GAEA,IAAI,+BAA+B;IAGjC,MAAM,yBAAyB,gCAAgC,iBAAiB;IAChF,oBAAoB,uBAAuB;IAE3C,IAAI,CAAC,uBAAuB,aAAa;KAGvC,0BAA0B;KAC1B,8BAA8B;KAC9B;IACF;GACF;GAGA,0BAA0B;GAE1B,IAAI,qBAAqB;IACvB,+BAA+B,kBAAkB,iBAAiB;IAClE;GACF;GAEA,kBAAkB,kBAAkB,SAAS,UAAU;IACrD;IACA;IACA,2BAA2B,MAAM,cAAc;GACjD,CAAC;GAED,MAAM,gBAAgB,kCAAkC,iBAAiB;GACzE,IAAI,CAAC,iBAAiB,CAAC,yBAAyB,eAAe,cAAc,EAAE,GAAG;IAChF,8BAA8B;IAC9B;GACF;GAEA,sBAAsB;GAEtB,qBAAqB,UAAU,cAAc,eAAe;GAE5D,qBAAqB,oBAAoB;IACvC,4BAA4B,OAAO,oBAAoB;IACvD,SAAS,cAAc,CAAC,CAAC,iBAAiB,MAAM,eAAe,MAAM,mBAAmB,OAAO;IAK/F,CAJ8B,kBAAkB,IAC5C,wBAAwB,IACxB,SAAS,mBAAmB,CAAC,CAAC,eAAe,oBAAoB,EAAA,CAGlE,MAAM,sBAAsB;KAC3B,IAAI,CAAC,mBACH;KAEF,iBAAiB;KACjB,6BAA6B,MAAM,mBAAmB,cAAc;KACpE,0BAA0B,2BAA2B,iBAAiB,CAAC;KACvE,aAAa;KAGb,8BAA8B;IAChC,CAAC,CAAC,CACD,MAAM,YAAY;GACvB,CAAC;EACH;EAEA,IAAI,oBAAoB;GACtB,OAAO;EACT;EAEA;EACA;EACA;EAEA,oBAAoB;EAEpB,UAAU,SAAS,YAAY,eAAe,UAAU,iBAAiB,GAAG,OAAO,aAAa,GAAG;GACjG,eAAe,QAAQ,oBACrB,gBAAgB,UAAU,SAAS,YAAY,eAAe,SAAS,IAAI,CAC7E;EACF;CACF;AACF;AAEA,SAAS,mCAAmC,mBAAiE;CAC3G,OAAO;EAAE,GAAG;EAAmB,aAAa;CAAQ;AACtD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { LifeCycle } from "../domain/lifeCycle.mjs";
|
|
2
|
+
import { startLogsAssembly } from "../domain/assembly.mjs";
|
|
3
|
+
import { startConsoleCollection } from "../domain/console/consoleCollection.mjs";
|
|
4
|
+
import { startReportCollection } from "../domain/report/reportCollection.mjs";
|
|
5
|
+
import { startNetworkErrorCollection } from "../domain/networkError/networkErrorCollection.mjs";
|
|
6
|
+
import { startRuntimeErrorCollection } from "../domain/runtimeError/runtimeErrorCollection.mjs";
|
|
7
|
+
import { startLoggerCollection } from "../domain/logger/loggerCollection.mjs";
|
|
8
|
+
import { startLogsBatch } from "../transport/startLogsBatch.mjs";
|
|
9
|
+
import { startLogsBridge } from "../transport/startLogsBridge.mjs";
|
|
10
|
+
import { startInternalContext } from "../domain/contexts/internalContext.mjs";
|
|
11
|
+
import { startReportError } from "../domain/reportError.mjs";
|
|
12
|
+
import { startRUMInternalContext } from "../domain/contexts/rumInternalContext.mjs";
|
|
13
|
+
import { startSessionContext } from "../domain/contexts/sessionContext.mjs";
|
|
14
|
+
import { canUseEventBridge, sendToExtension, startAccountContext, startGlobalContext, startTabContext, startUserContext } from "@kubesense/kubesense-browser-core";
|
|
15
|
+
//#region src/boot/startLogs.ts
|
|
16
|
+
const LOGS_STORAGE_KEY = "logs";
|
|
17
|
+
function startLogs(configuration, sessionManager, getCommonContext, bufferedDataObservable, hooks) {
|
|
18
|
+
const lifeCycle = new LifeCycle();
|
|
19
|
+
const cleanupTasks = [];
|
|
20
|
+
lifeCycle.subscribe(1, (log) => sendToExtension("logs", log));
|
|
21
|
+
const reportError = startReportError(lifeCycle);
|
|
22
|
+
const { assembleEventDefaults: assembleHook } = hooks;
|
|
23
|
+
startSessionContext(assembleHook, configuration, sessionManager);
|
|
24
|
+
const accountContext = startAccountContext(assembleHook, configuration, LOGS_STORAGE_KEY);
|
|
25
|
+
const userContext = startUserContext(assembleHook, configuration, sessionManager, LOGS_STORAGE_KEY);
|
|
26
|
+
const globalContext = startGlobalContext(assembleHook, configuration, LOGS_STORAGE_KEY, false);
|
|
27
|
+
startRUMInternalContext(hooks);
|
|
28
|
+
startTabContext(assembleHook);
|
|
29
|
+
startNetworkErrorCollection(configuration, lifeCycle, bufferedDataObservable);
|
|
30
|
+
startRuntimeErrorCollection(configuration, lifeCycle, bufferedDataObservable);
|
|
31
|
+
startConsoleCollection(configuration, lifeCycle, bufferedDataObservable);
|
|
32
|
+
bufferedDataObservable.unbuffer();
|
|
33
|
+
startReportCollection(configuration, lifeCycle);
|
|
34
|
+
const { handleLog } = startLoggerCollection(lifeCycle);
|
|
35
|
+
startLogsAssembly(configuration, lifeCycle, hooks, getCommonContext, reportError);
|
|
36
|
+
if (!canUseEventBridge()) {
|
|
37
|
+
const { stop: stopLogsBatch } = startLogsBatch(configuration, lifeCycle, reportError, sessionManager);
|
|
38
|
+
cleanupTasks.push(() => stopLogsBatch());
|
|
39
|
+
} else startLogsBridge(lifeCycle);
|
|
40
|
+
return {
|
|
41
|
+
handleLog,
|
|
42
|
+
getInternalContext: startInternalContext(sessionManager).get,
|
|
43
|
+
accountContext,
|
|
44
|
+
globalContext,
|
|
45
|
+
userContext,
|
|
46
|
+
stop: () => {
|
|
47
|
+
cleanupTasks.forEach((task) => task());
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { startLogs };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=startLogs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startLogs.mjs","names":[],"sources":["../../src/boot/startLogs.ts"],"sourcesContent":["import type { BufferedObservable, BufferedData, SessionManager } from '@kubesense/kubesense-browser-core'\nimport {\n sendToExtension,\n canUseEventBridge,\n startAccountContext,\n startGlobalContext,\n startUserContext,\n startTabContext,\n} from '@kubesense/kubesense-browser-core'\nimport type { LogsConfiguration } from '../domain/configuration'\nimport { startLogsAssembly } from '../domain/assembly'\nimport { startConsoleCollection } from '../domain/console/consoleCollection'\nimport { startReportCollection } from '../domain/report/reportCollection'\nimport { startNetworkErrorCollection } from '../domain/networkError/networkErrorCollection'\nimport { startRuntimeErrorCollection } from '../domain/runtimeError/runtimeErrorCollection'\nimport { LifeCycle, LifeCycleEventType } from '../domain/lifeCycle'\nimport { startLoggerCollection } from '../domain/logger/loggerCollection'\nimport { startLogsBatch } from '../transport/startLogsBatch'\nimport { startLogsBridge } from '../transport/startLogsBridge'\nimport { startInternalContext } from '../domain/contexts/internalContext'\nimport { startReportError } from '../domain/reportError'\nimport type { CommonContext } from '../rawLogsEvent.types'\nimport type { Hooks } from '../domain/hooks'\nimport { startRUMInternalContext } from '../domain/contexts/rumInternalContext'\nimport { startSessionContext } from '../domain/contexts/sessionContext'\n\nconst LOGS_STORAGE_KEY = 'logs'\n\nexport type StartLogs = typeof startLogs\nexport type StartLogsResult = ReturnType<StartLogs>\n\nexport function startLogs(\n configuration: LogsConfiguration,\n sessionManager: SessionManager,\n getCommonContext: () => CommonContext,\n bufferedDataObservable: BufferedObservable<BufferedData>,\n hooks: Hooks\n) {\n const lifeCycle = new LifeCycle()\n const cleanupTasks: Array<() => void> = []\n\n lifeCycle.subscribe(LifeCycleEventType.LOG_COLLECTED, (log) => sendToExtension('logs', log))\n\n const reportError = startReportError(lifeCycle)\n\n // Start user and account context first to allow overrides from global context\n const { assembleEventDefaults: assembleHook } = hooks\n startSessionContext(assembleHook, configuration, sessionManager)\n const accountContext = startAccountContext(assembleHook, configuration, LOGS_STORAGE_KEY)\n const userContext = startUserContext(assembleHook, configuration, sessionManager, LOGS_STORAGE_KEY)\n const globalContext = startGlobalContext(assembleHook, configuration, LOGS_STORAGE_KEY, false)\n startRUMInternalContext(hooks)\n startTabContext(assembleHook)\n\n startNetworkErrorCollection(configuration, lifeCycle, bufferedDataObservable)\n startRuntimeErrorCollection(configuration, lifeCycle, bufferedDataObservable)\n startConsoleCollection(configuration, lifeCycle, bufferedDataObservable)\n bufferedDataObservable.unbuffer()\n startReportCollection(configuration, lifeCycle)\n const { handleLog } = startLoggerCollection(lifeCycle)\n\n startLogsAssembly(configuration, lifeCycle, hooks, getCommonContext, reportError)\n\n if (!canUseEventBridge()) {\n const { stop: stopLogsBatch } = startLogsBatch(configuration, lifeCycle, reportError, sessionManager)\n cleanupTasks.push(() => stopLogsBatch())\n } else {\n startLogsBridge(lifeCycle)\n }\n\n const internalContext = startInternalContext(sessionManager)\n\n return {\n handleLog,\n getInternalContext: internalContext.get,\n accountContext,\n globalContext,\n userContext,\n stop: () => {\n cleanupTasks.forEach((task) => task())\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAM,mBAAmB;AAKzB,SAAgB,UACd,eACA,gBACA,kBACA,wBACA,OACA;CACA,MAAM,YAAY,IAAI,UAAU;CAChC,MAAM,eAAkC,CAAC;CAEzC,UAAU,UAAA,IAA6C,QAAQ,gBAAgB,QAAQ,GAAG,CAAC;CAE3F,MAAM,cAAc,iBAAiB,SAAS;CAG9C,MAAM,EAAE,uBAAuB,iBAAiB;CAChD,oBAAoB,cAAc,eAAe,cAAc;CAC/D,MAAM,iBAAiB,oBAAoB,cAAc,eAAe,gBAAgB;CACxF,MAAM,cAAc,iBAAiB,cAAc,eAAe,gBAAgB,gBAAgB;CAClG,MAAM,gBAAgB,mBAAmB,cAAc,eAAe,kBAAkB,KAAK;CAC7F,wBAAwB,KAAK;CAC7B,gBAAgB,YAAY;CAE5B,4BAA4B,eAAe,WAAW,sBAAsB;CAC5E,4BAA4B,eAAe,WAAW,sBAAsB;CAC5E,uBAAuB,eAAe,WAAW,sBAAsB;CACvE,uBAAuB,SAAS;CAChC,sBAAsB,eAAe,SAAS;CAC9C,MAAM,EAAE,cAAc,sBAAsB,SAAS;CAErD,kBAAkB,eAAe,WAAW,OAAO,kBAAkB,WAAW;CAEhF,IAAI,CAAC,kBAAkB,GAAG;EACxB,MAAM,EAAE,MAAM,kBAAkB,eAAe,eAAe,WAAW,aAAa,cAAc;EACpG,aAAa,WAAW,cAAc,CAAC;CACzC,OACE,gBAAgB,SAAS;CAK3B,OAAO;EACL;EACA,oBAJsB,qBAAqB,cAIT,CAAC,CAAC;EACpC;EACA;EACA;EACA,YAAY;GACV,aAAa,SAAS,SAAS,KAAK,CAAC;EACvC;CACF;AACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { STATUSES } from "./logger.mjs";
|
|
2
|
+
import "./lifeCycle.mjs";
|
|
3
|
+
import { combine } from "@kubesense/kubesense-js-core/util";
|
|
4
|
+
import { ErrorSource, buildTags, createEventRateLimiter } from "@kubesense/kubesense-browser-core";
|
|
5
|
+
import { toRelativeTime } from "@kubesense/kubesense-js-core/time";
|
|
6
|
+
import { DISCARDED } from "@kubesense/kubesense-js-core/assembly";
|
|
7
|
+
//#region src/domain/assembly.ts
|
|
8
|
+
function startLogsAssembly(configuration, lifeCycle, hooks, getCommonContext, reportError, eventRateLimit) {
|
|
9
|
+
const statusWithCustom = STATUSES.concat(["custom"]);
|
|
10
|
+
const logRateLimiters = {};
|
|
11
|
+
statusWithCustom.forEach((status) => {
|
|
12
|
+
logRateLimiters[status] = createEventRateLimiter(status, reportError, eventRateLimit);
|
|
13
|
+
});
|
|
14
|
+
lifeCycle.subscribe(0, ({ rawLogsEvent, savedCommonContext = void 0, domainContext, ktags = [] }) => {
|
|
15
|
+
const startTime = toRelativeTime(rawLogsEvent.date);
|
|
16
|
+
const commonContext = savedCommonContext || getCommonContext();
|
|
17
|
+
const assemblyParams = {
|
|
18
|
+
startTime,
|
|
19
|
+
rawLogsEvent,
|
|
20
|
+
domainContext
|
|
21
|
+
};
|
|
22
|
+
const defaultLogsEventAttributes = hooks.assembleEventDefaults.trigger(assemblyParams);
|
|
23
|
+
if (defaultLogsEventAttributes === DISCARDED) return;
|
|
24
|
+
const logsEventAttributes = hooks.assembleEvent.trigger(assemblyParams);
|
|
25
|
+
if (logsEventAttributes === DISCARDED) return;
|
|
26
|
+
const defaultKtags = buildTags(configuration);
|
|
27
|
+
const log = combine({ view: commonContext.view }, defaultLogsEventAttributes, rawLogsEvent, logsEventAttributes, { ktags: defaultKtags.concat(ktags).join(",") });
|
|
28
|
+
if (configuration.beforeSend?.(log, domainContext) === false || log.origin !== ErrorSource.AGENT && (logRateLimiters[log.status] ?? logRateLimiters["custom"]).isLimitReached()) return;
|
|
29
|
+
lifeCycle.notify(1, log);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { startLogsAssembly };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=assembly.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assembly.mjs","names":[],"sources":["../../src/domain/assembly.ts"],"sourcesContent":["import type { Context, EventRateLimiter } from '@kubesense/kubesense-browser-core'\nimport { ErrorSource, buildTags, createEventRateLimiter } from '@kubesense/kubesense-browser-core'\nimport { toRelativeTime } from '@kubesense/kubesense-js-core/time'\nimport { DISCARDED } from '@kubesense/kubesense-js-core/assembly'\nimport { combine } from '@kubesense/kubesense-js-core/util'\nimport type { CommonContext } from '../rawLogsEvent.types'\nimport type { LogsEvent } from '../logsEvent.types'\nimport type { LogsConfiguration } from './configuration'\nimport type { LifeCycle } from './lifeCycle'\nimport { LifeCycleEventType } from './lifeCycle'\nimport { STATUSES } from './logger'\nimport type { Hooks, AssembleHookParams } from './hooks'\n\nexport function startLogsAssembly(\n configuration: LogsConfiguration,\n lifeCycle: LifeCycle,\n hooks: Hooks,\n getCommonContext: () => CommonContext,\n reportError: (message: string) => void,\n eventRateLimit?: number\n) {\n const statusWithCustom = (STATUSES as string[]).concat(['custom'])\n const logRateLimiters: { [key: string]: EventRateLimiter } = {}\n statusWithCustom.forEach((status) => {\n logRateLimiters[status] = createEventRateLimiter(status, reportError, eventRateLimit)\n })\n\n lifeCycle.subscribe(\n LifeCycleEventType.RAW_LOG_COLLECTED,\n ({ rawLogsEvent, savedCommonContext = undefined, domainContext, ktags = [] }) => {\n const startTime = toRelativeTime(rawLogsEvent.date)\n const commonContext = savedCommonContext || getCommonContext()\n const assemblyParams: AssembleHookParams = {\n startTime,\n rawLogsEvent: rawLogsEvent as AssembleHookParams['rawLogsEvent'],\n domainContext,\n }\n const defaultLogsEventAttributes = hooks.assembleEventDefaults.trigger(assemblyParams)\n if (defaultLogsEventAttributes === DISCARDED) {\n return\n }\n\n const logsEventAttributes = hooks.assembleEvent.trigger(assemblyParams)!\n if (logsEventAttributes === DISCARDED) {\n return\n }\n\n const defaultKtags = buildTags(configuration)\n\n const log = combine(\n {\n view: commonContext.view,\n },\n defaultLogsEventAttributes,\n rawLogsEvent,\n logsEventAttributes,\n {\n ktags: defaultKtags.concat(ktags).join(','),\n }\n ) as LogsEvent & Context\n\n if (\n configuration.beforeSend?.(log, domainContext) === false ||\n (log.origin !== ErrorSource.AGENT &&\n (logRateLimiters[log.status] ?? logRateLimiters['custom']).isLimitReached())\n ) {\n return\n }\n\n lifeCycle.notify(LifeCycleEventType.LOG_COLLECTED, log)\n }\n )\n}\n"],"mappings":";;;;;;;AAaA,SAAgB,kBACd,eACA,WACA,OACA,kBACA,aACA,gBACA;CACA,MAAM,mBAAoB,SAAsB,OAAO,CAAC,QAAQ,CAAC;CACjE,MAAM,kBAAuD,CAAC;CAC9D,iBAAiB,SAAS,WAAW;EACnC,gBAAgB,UAAU,uBAAuB,QAAQ,aAAa,cAAc;CACtF,CAAC;CAED,UAAU,UAAA,IAEP,EAAE,cAAc,qBAAqB,KAAA,GAAW,eAAe,QAAQ,CAAC,QAAQ;EAC/E,MAAM,YAAY,eAAe,aAAa,IAAI;EAClD,MAAM,gBAAgB,sBAAsB,iBAAiB;EAC7D,MAAM,iBAAqC;GACzC;GACc;GACd;EACF;EACA,MAAM,6BAA6B,MAAM,sBAAsB,QAAQ,cAAc;EACrF,IAAI,+BAA+B,WACjC;EAGF,MAAM,sBAAsB,MAAM,cAAc,QAAQ,cAAc;EACtE,IAAI,wBAAwB,WAC1B;EAGF,MAAM,eAAe,UAAU,aAAa;EAE5C,MAAM,MAAM,QACV,EACE,MAAM,cAAc,KACtB,GACA,4BACA,cACA,qBACA,EACE,OAAO,aAAa,OAAO,KAAK,CAAC,CAAC,KAAK,GAAG,EAC5C,CACF;EAEA,IACE,cAAc,aAAa,KAAK,aAAa,MAAM,SAClD,IAAI,WAAW,YAAY,UACzB,gBAAgB,IAAI,WAAW,gBAAgB,UAAA,CAAW,eAAe,GAE5E;EAGF,UAAU,OAAA,GAAyC,GAAG;CACxD,CACF;AACF"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ConsoleApiName } from "@kubesense/kubesense-js-core/util";
|
|
2
|
+
import { BROWSER_CORE_SCHEMA, RawReportType, catchUserErrors, display, serializeConfiguration } from "@kubesense/kubesense-browser-core";
|
|
3
|
+
import { validateAndBuildConfiguration } from "@kubesense/kubesense-js-core/configuration";
|
|
4
|
+
//#region src/domain/configuration.ts
|
|
5
|
+
const LOGS_SCHEMA = {
|
|
6
|
+
...BROWSER_CORE_SCHEMA,
|
|
7
|
+
forwardErrorsToLogs: {
|
|
8
|
+
type: "boolean",
|
|
9
|
+
default: true,
|
|
10
|
+
strict: false
|
|
11
|
+
},
|
|
12
|
+
enableRemoteSdkConfiguration: {
|
|
13
|
+
type: "boolean",
|
|
14
|
+
default: false,
|
|
15
|
+
strict: false
|
|
16
|
+
},
|
|
17
|
+
forwardConsoleLogs: {
|
|
18
|
+
type: "enum",
|
|
19
|
+
values: ConsoleApiName,
|
|
20
|
+
multiple: true,
|
|
21
|
+
allowAll: true,
|
|
22
|
+
default: []
|
|
23
|
+
},
|
|
24
|
+
forwardReports: {
|
|
25
|
+
type: "enum",
|
|
26
|
+
values: RawReportType,
|
|
27
|
+
multiple: true,
|
|
28
|
+
allowAll: true,
|
|
29
|
+
default: []
|
|
30
|
+
},
|
|
31
|
+
plugins: {
|
|
32
|
+
type: "schema",
|
|
33
|
+
multiple: true,
|
|
34
|
+
strict: false,
|
|
35
|
+
default: [],
|
|
36
|
+
schema: {
|
|
37
|
+
name: {
|
|
38
|
+
type: "string",
|
|
39
|
+
required: true
|
|
40
|
+
},
|
|
41
|
+
getConfigurationTelemetry: {
|
|
42
|
+
type: "function",
|
|
43
|
+
strict: false,
|
|
44
|
+
signature: void 0
|
|
45
|
+
},
|
|
46
|
+
onInit: {
|
|
47
|
+
type: "function",
|
|
48
|
+
strict: false,
|
|
49
|
+
signature: void 0
|
|
50
|
+
},
|
|
51
|
+
onLogsStart: {
|
|
52
|
+
type: "function",
|
|
53
|
+
strict: false,
|
|
54
|
+
signature: void 0
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
function validateAndBuildLogsConfiguration(initConfiguration) {
|
|
60
|
+
const config = validateAndBuildConfiguration(initConfiguration, LOGS_SCHEMA, display);
|
|
61
|
+
if (!config) return;
|
|
62
|
+
return {
|
|
63
|
+
...config,
|
|
64
|
+
beforeSend: config.beforeSend ? catchUserErrors(config.beforeSend, "beforeSend threw an error:") : void 0
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function serializeLogsConfiguration(configuration) {
|
|
68
|
+
const baseSerializedInitConfiguration = serializeConfiguration(configuration);
|
|
69
|
+
return {
|
|
70
|
+
forward_errors_to_logs: configuration.forwardErrorsToLogs,
|
|
71
|
+
enable_remote_sdk_configuration: !!configuration.enableRemoteSdkConfiguration,
|
|
72
|
+
forward_console_logs: configuration.forwardConsoleLogs,
|
|
73
|
+
forward_reports: configuration.forwardReports,
|
|
74
|
+
plugins: configuration.plugins?.map((plugin) => ({
|
|
75
|
+
name: plugin.name,
|
|
76
|
+
...plugin.getConfigurationTelemetry?.()
|
|
77
|
+
})),
|
|
78
|
+
...baseSerializedInitConfiguration
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { LOGS_SCHEMA, serializeLogsConfiguration, validateAndBuildLogsConfiguration };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=configuration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.mjs","names":[],"sources":["../../src/domain/configuration.ts"],"sourcesContent":["import type { InitConfiguration, RawTelemetryConfiguration } from '@kubesense/kubesense-browser-core'\nimport { ConsoleApiName } from '@kubesense/kubesense-js-core/util'\nimport {\n serializeConfiguration,\n catchUserErrors,\n display,\n RawReportType,\n BROWSER_CORE_SCHEMA,\n} from '@kubesense/kubesense-browser-core'\nimport { validateAndBuildConfiguration } from '@kubesense/kubesense-js-core/configuration'\nimport type { InferredConfig } from '@kubesense/kubesense-js-core/configuration'\nimport type { LogsEvent } from '../logsEvent.types'\nimport type { LogsEventDomainContext } from '../domainContext.types'\nimport type { LogsPlugin } from './plugins'\n\n/**\n * Init Configuration for the Logs browser SDK.\n *\n * @category Main\n * @example NPM\n * ```ts\n * import { kubesenseLogs } from '@kubesense/kubesense-browser-logs'\n *\n * kubesenseLogs.init({\n * clientToken: '<KUBESENSE_CLIENT_TOKEN>',\n * kubesenseRumEndpoint: '<KUBESENSE_RUM_ENDPOINT>',\n * // ...\n * })\n * ```\n * @example CDN\n * ```ts\n * KUBESENSE_LOGS.init({\n * clientToken: '<KUBESENSE_CLIENT_TOKEN>',\n * kubesenseRumEndpoint: '<KUBESENSE_RUM_ENDPOINT>',\n * // ...\n * })\n * ```\n */\nexport interface LogsInitConfiguration extends InitConfiguration {\n /**\n * Access to every logs collected by the Logs SDK before they are sent to KubeSense.\n * It allows:\n * - Enrich your logs with additional context attributes\n * - Modify your logs to modify their content, or redact sensitive sequences (see the list of editable properties)\n * - Discard selected logs\n *\n * @category Data Collection\n */\n beforeSend?: LogsBeforeSend | undefined\n\n /**\n * Forward uncaught exceptions and network errors to KubeSense.\n *\n * To capture `console.error` calls, use {@link forwardConsoleLogs} with `\"error\"` (or `\"all\"`).\n *\n * @category Data Collection\n * @defaultValue true\n * @see forwardConsoleLogs\n */\n forwardErrorsToLogs?: boolean | undefined\n\n /**\n * Forward logs from console.* to KubeSense. Use \"all\" to forward everything or an array of console API names to forward only a subset.\n *\n * @category Data Collection\n */\n forwardConsoleLogs?: ConsoleApiName[] | 'all' | undefined\n\n /**\n * Forward reports from the [Reporting API](https://developer.mozilla.org/en-US/docs/Web/API/Reporting_API) to KubeSense. Use \"all\" to forward everything or an array of report types to forward only a subset.\n *\n * @category Data Collection\n */\n forwardReports?: RawReportType[] | 'all' | undefined\n\n /**\n * List of plugins to enable. The plugins API is unstable and experimental, and may change without\n * notice. Please use only plugins provided by KubeSense matching the version of the SDK you are\n * using.\n *\n * @experimental\n */\n plugins?: LogsPlugin[] | undefined\n\n /**\n * Enable dashboard-managed SDK settings served by the KubeSense collector.\n *\n * Logs reads the same cached document as RUM, but only consumes the `features.logs` switch and\n * the `logs` section. The document is fetched asynchronously after the SDK starts, so it never\n * delays initialization, and cached settings are applied on the next page load.\n *\n * @category Data Collection\n * @defaultValue false\n */\n enableRemoteSdkConfiguration?: boolean | undefined\n}\n\n/**\n * Function called before a Log event is sent to KubeSense. See {@link LogsInitConfiguration.beforeSend}\n *\n * @param event - The log event\n * @param context - The log event domain context\n * @returns true if the event should be sent to KubeSense, false otherwise\n */\nexport type LogsBeforeSend = (event: LogsEvent, context: LogsEventDomainContext) => boolean\n\nexport const LOGS_SCHEMA = {\n ...BROWSER_CORE_SCHEMA,\n forwardErrorsToLogs: { type: 'boolean', default: true, strict: false },\n enableRemoteSdkConfiguration: { type: 'boolean', default: false, strict: false },\n forwardConsoleLogs: {\n type: 'enum',\n values: ConsoleApiName,\n multiple: true,\n allowAll: true,\n default: [] as ConsoleApiName[],\n },\n forwardReports: {\n type: 'enum',\n values: RawReportType,\n multiple: true,\n allowAll: true,\n default: [] as RawReportType[],\n },\n plugins: {\n type: 'schema',\n multiple: true,\n strict: false,\n default: [] as LogsPlugin[],\n schema: {\n name: { type: 'string', required: true },\n getConfigurationTelemetry: {\n type: 'function',\n strict: false,\n signature: undefined as LogsPlugin['getConfigurationTelemetry'],\n },\n onInit: { type: 'function', strict: false, signature: undefined as LogsPlugin['onInit'] },\n onLogsStart: { type: 'function', strict: false, signature: undefined as LogsPlugin['onLogsStart'] },\n },\n },\n} as const\n\nexport type LogsConfiguration = InferredConfig<typeof LOGS_SCHEMA>\n\nexport function validateAndBuildLogsConfiguration(\n initConfiguration: LogsInitConfiguration\n): LogsConfiguration | undefined {\n const config = validateAndBuildConfiguration(\n initConfiguration as unknown as Record<string, unknown>,\n LOGS_SCHEMA,\n display\n )\n if (!config) {\n return\n }\n return {\n ...config,\n beforeSend: config.beforeSend ? catchUserErrors(config.beforeSend as any, 'beforeSend threw an error:') : undefined,\n }\n}\n\nexport function serializeLogsConfiguration(configuration: LogsInitConfiguration) {\n const baseSerializedInitConfiguration = serializeConfiguration(configuration)\n\n return {\n forward_errors_to_logs: configuration.forwardErrorsToLogs,\n enable_remote_sdk_configuration: !!configuration.enableRemoteSdkConfiguration,\n forward_console_logs: configuration.forwardConsoleLogs,\n forward_reports: configuration.forwardReports,\n plugins: configuration.plugins?.map((plugin) => ({\n name: plugin.name,\n ...plugin.getConfigurationTelemetry?.(),\n })),\n ...baseSerializedInitConfiguration,\n } satisfies RawTelemetryConfiguration\n}\n"],"mappings":";;;;AA0GA,MAAa,cAAc;CACzB,GAAG;CACH,qBAAqB;EAAE,MAAM;EAAW,SAAS;EAAM,QAAQ;CAAM;CACrE,8BAA8B;EAAE,MAAM;EAAW,SAAS;EAAO,QAAQ;CAAM;CAC/E,oBAAoB;EAClB,MAAM;EACN,QAAQ;EACR,UAAU;EACV,UAAU;EACV,SAAS,CAAC;CACZ;CACA,gBAAgB;EACd,MAAM;EACN,QAAQ;EACR,UAAU;EACV,UAAU;EACV,SAAS,CAAC;CACZ;CACA,SAAS;EACP,MAAM;EACN,UAAU;EACV,QAAQ;EACR,SAAS,CAAC;EACV,QAAQ;GACN,MAAM;IAAE,MAAM;IAAU,UAAU;GAAK;GACvC,2BAA2B;IACzB,MAAM;IACN,QAAQ;IACR,WAAW,KAAA;GACb;GACA,QAAQ;IAAE,MAAM;IAAY,QAAQ;IAAO,WAAW,KAAA;GAAkC;GACxF,aAAa;IAAE,MAAM;IAAY,QAAQ;IAAO,WAAW,KAAA;GAAuC;EACpG;CACF;AACF;AAIA,SAAgB,kCACd,mBAC+B;CAC/B,MAAM,SAAS,8BACb,mBACA,aACA,OACF;CACA,IAAI,CAAC,QACH;CAEF,OAAO;EACL,GAAG;EACH,YAAY,OAAO,aAAa,gBAAgB,OAAO,YAAmB,4BAA4B,IAAI,KAAA;CAC5G;AACF;AAEA,SAAgB,2BAA2B,eAAsC;CAC/E,MAAM,kCAAkC,uBAAuB,aAAa;CAE5E,OAAO;EACL,wBAAwB,cAAc;EACtC,iCAAiC,CAAC,CAAC,cAAc;EACjD,sBAAsB,cAAc;EACpC,iBAAiB,cAAc;EAC/B,SAAS,cAAc,SAAS,KAAK,YAAY;GAC/C,MAAM,OAAO;GACb,GAAG,OAAO,4BAA4B;EACxC,EAAE;EACF,GAAG;CACL;AACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StatusType } from "../logger/isAuthorized.mjs";
|
|
2
|
+
import { createErrorFieldFromRawError } from "../createErrorFieldFromRawError.mjs";
|
|
3
|
+
import "../lifeCycle.mjs";
|
|
4
|
+
import { ConsoleApiName, combine } from "@kubesense/kubesense-js-core/util";
|
|
5
|
+
import { BufferedDataType, ErrorSource } from "@kubesense/kubesense-browser-core";
|
|
6
|
+
import { timeStampNow } from "@kubesense/kubesense-js-core/time";
|
|
7
|
+
//#region src/domain/console/consoleCollection.ts
|
|
8
|
+
const LogStatusForApi = {
|
|
9
|
+
[ConsoleApiName.log]: StatusType.info,
|
|
10
|
+
[ConsoleApiName.debug]: StatusType.debug,
|
|
11
|
+
[ConsoleApiName.info]: StatusType.info,
|
|
12
|
+
[ConsoleApiName.warn]: StatusType.warn,
|
|
13
|
+
[ConsoleApiName.error]: StatusType.error
|
|
14
|
+
};
|
|
15
|
+
function startConsoleCollection(configuration, lifeCycle, bufferedDataObservable) {
|
|
16
|
+
const subscription = bufferedDataObservable.subscribe(({ data: log, type }) => {
|
|
17
|
+
if (type !== BufferedDataType.CONSOLE || !configuration.forwardConsoleLogs.includes(log.api)) return;
|
|
18
|
+
const collectedData = {
|
|
19
|
+
rawLogsEvent: combine({
|
|
20
|
+
date: timeStampNow(),
|
|
21
|
+
message: log.message,
|
|
22
|
+
origin: ErrorSource.CONSOLE,
|
|
23
|
+
error: log.error && createErrorFieldFromRawError(log.error),
|
|
24
|
+
_kubesense: log.error && { debug_ids: log.error.debugIds },
|
|
25
|
+
status: LogStatusForApi[log.api]
|
|
26
|
+
}, log.error?.context),
|
|
27
|
+
domainContext: { handlingStack: log.handlingStack }
|
|
28
|
+
};
|
|
29
|
+
lifeCycle.notify(0, collectedData);
|
|
30
|
+
});
|
|
31
|
+
return { stop: () => subscription.unsubscribe() };
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { LogStatusForApi, startConsoleCollection };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=consoleCollection.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consoleCollection.mjs","names":[],"sources":["../../../src/domain/console/consoleCollection.ts"],"sourcesContent":["import type { ClocksState } from '@kubesense/kubesense-js-core/time'\nimport { combine, ConsoleApiName } from '@kubesense/kubesense-js-core/util'\nimport type { Context, Observable, BufferedData } from '@kubesense/kubesense-browser-core'\nimport { timeStampNow } from '@kubesense/kubesense-js-core/time'\nimport { BufferedDataType, ErrorSource } from '@kubesense/kubesense-browser-core'\nimport type { LogsConfiguration } from '../configuration'\nimport type { LifeCycle, RawLogsEventCollectedData } from '../lifeCycle'\nimport { LifeCycleEventType } from '../lifeCycle'\nimport { StatusType } from '../logger/isAuthorized'\nimport type { RawLogsEvent } from '../../rawLogsEvent.types'\nimport { createErrorFieldFromRawError } from '../createErrorFieldFromRawError'\n\nexport interface ProvidedError {\n startClocks: ClocksState\n error: unknown\n context?: Context\n handlingStack: string\n}\n\nexport const LogStatusForApi = {\n [ConsoleApiName.log]: StatusType.info,\n [ConsoleApiName.debug]: StatusType.debug,\n [ConsoleApiName.info]: StatusType.info,\n [ConsoleApiName.warn]: StatusType.warn,\n [ConsoleApiName.error]: StatusType.error,\n}\n\nexport function startConsoleCollection(\n configuration: LogsConfiguration,\n lifeCycle: LifeCycle,\n bufferedDataObservable: Observable<BufferedData>\n) {\n const subscription = bufferedDataObservable.subscribe(({ data: log, type }) => {\n if (type !== BufferedDataType.CONSOLE || !configuration.forwardConsoleLogs.includes(log.api)) {\n return\n }\n const collectedData: RawLogsEventCollectedData<RawLogsEvent> = {\n rawLogsEvent: combine(\n {\n date: timeStampNow(),\n message: log.message,\n origin: ErrorSource.CONSOLE,\n error: log.error && createErrorFieldFromRawError(log.error),\n _kubesense: log.error && { debug_ids: log.error.debugIds },\n status: LogStatusForApi[log.api],\n },\n log.error?.context\n ),\n domainContext: {\n handlingStack: log.handlingStack,\n },\n }\n\n lifeCycle.notify(LifeCycleEventType.RAW_LOG_COLLECTED, collectedData)\n })\n\n return { stop: () => subscription.unsubscribe() }\n}\n"],"mappings":";;;;;;;AAmBA,MAAa,kBAAkB;EAC5B,eAAe,MAAM,WAAW;EAChC,eAAe,QAAQ,WAAW;EAClC,eAAe,OAAO,WAAW;EACjC,eAAe,OAAO,WAAW;EACjC,eAAe,QAAQ,WAAW;AACrC;AAEA,SAAgB,uBACd,eACA,WACA,wBACA;CACA,MAAM,eAAe,uBAAuB,WAAW,EAAE,MAAM,KAAK,WAAW;EAC7E,IAAI,SAAS,iBAAiB,WAAW,CAAC,cAAc,mBAAmB,SAAS,IAAI,GAAG,GACzF;EAEF,MAAM,gBAAyD;GAC7D,cAAc,QACZ;IACE,MAAM,aAAa;IACnB,SAAS,IAAI;IACb,QAAQ,YAAY;IACpB,OAAO,IAAI,SAAS,6BAA6B,IAAI,KAAK;IAC1D,YAAY,IAAI,SAAS,EAAE,WAAW,IAAI,MAAM,SAAS;IACzD,QAAQ,gBAAgB,IAAI;GAC9B,GACA,IAAI,OAAO,OACb;GACA,eAAe,EACb,eAAe,IAAI,cACrB;EACF;EAEA,UAAU,OAAA,GAA6C,aAAa;CACtE,CAAC;CAED,OAAO,EAAE,YAAY,aAAa,YAAY,EAAE;AAClD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isWorkerEnvironment } from "@kubesense/kubesense-js-core/util";
|
|
2
|
+
//#region src/domain/contexts/commonContext.ts
|
|
3
|
+
function buildCommonContext() {
|
|
4
|
+
if (isWorkerEnvironment) return {};
|
|
5
|
+
return { view: {
|
|
6
|
+
referrer: document.referrer,
|
|
7
|
+
url: window.location.href
|
|
8
|
+
} };
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { buildCommonContext };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=commonContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commonContext.mjs","names":[],"sources":["../../../src/domain/contexts/commonContext.ts"],"sourcesContent":["import { isWorkerEnvironment } from '@kubesense/kubesense-js-core/util'\nimport type { CommonContext } from '../../rawLogsEvent.types'\n\nexport function buildCommonContext(): CommonContext {\n if (isWorkerEnvironment) {\n return {}\n }\n\n return {\n view: {\n referrer: document.referrer,\n url: window.location.href,\n },\n }\n}\n"],"mappings":";;AAGA,SAAgB,qBAAoC;CAClD,IAAI,qBACF,OAAO,CAAC;CAGV,OAAO,EACL,MAAM;EACJ,UAAU,SAAS;EACnB,KAAK,OAAO,SAAS;CACvB,EACF;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/domain/contexts/internalContext.ts
|
|
2
|
+
function startInternalContext(sessionManager) {
|
|
3
|
+
return { get: (startTime) => {
|
|
4
|
+
const trackedSession = sessionManager.findTrackedSession(startTime);
|
|
5
|
+
if (trackedSession) return { session_id: trackedSession.id };
|
|
6
|
+
} };
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { startInternalContext };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=internalContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internalContext.mjs","names":[],"sources":["../../../src/domain/contexts/internalContext.ts"],"sourcesContent":["import type { RelativeTime } from '@kubesense/kubesense-js-core/time'\nimport type { SessionManager } from '@kubesense/kubesense-browser-core'\n\nexport interface InternalContext {\n session_id: string | undefined\n}\n\nexport function startInternalContext(sessionManager: SessionManager) {\n return {\n get: (startTime?: number): InternalContext | undefined => {\n const trackedSession = sessionManager.findTrackedSession(startTime as RelativeTime)\n if (trackedSession) {\n return {\n session_id: trackedSession.id,\n }\n }\n },\n }\n}\n"],"mappings":";AAOA,SAAgB,qBAAqB,gBAAgC;CACnE,OAAO,EACL,MAAM,cAAoD;EACxD,MAAM,iBAAiB,eAAe,mBAAmB,SAAyB;EAClF,IAAI,gBACF,OAAO,EACL,YAAY,eAAe,GAC7B;CAEJ,EACF;AACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { globalObject } from "@kubesense/kubesense-js-core/util";
|
|
2
|
+
import { willSyntheticsInjectRum } from "@kubesense/kubesense-browser-core";
|
|
3
|
+
import { SKIPPED } from "@kubesense/kubesense-js-core/assembly";
|
|
4
|
+
//#region src/domain/contexts/rumInternalContext.ts
|
|
5
|
+
function startRUMInternalContext(hooks) {
|
|
6
|
+
const browserWindow = globalObject;
|
|
7
|
+
hooks.assembleEventDefaults.register(({ startTime }) => {
|
|
8
|
+
const internalContext = getRUMInternalContext(startTime);
|
|
9
|
+
if (!internalContext) return SKIPPED;
|
|
10
|
+
return internalContext;
|
|
11
|
+
});
|
|
12
|
+
hooks.assembleTelemetry.register(({ startTime }) => {
|
|
13
|
+
const internalContext = getRUMInternalContext(startTime);
|
|
14
|
+
if (!internalContext) return SKIPPED;
|
|
15
|
+
return {
|
|
16
|
+
application: { id: internalContext.application_id },
|
|
17
|
+
view: { id: internalContext.view?.id },
|
|
18
|
+
action: { id: internalContext.user_action?.id }
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
function getRUMInternalContext(startTime) {
|
|
22
|
+
const rumContext = getInternalContextFromRumGlobal(startTime, willSyntheticsInjectRum() ? browserWindow.KUBESENSE_SDK_SYNTHETICS : browserWindow.KUBESENSE_SDK);
|
|
23
|
+
if (rumContext) return rumContext;
|
|
24
|
+
}
|
|
25
|
+
function getInternalContextFromRumGlobal(startTime, rumGlobal) {
|
|
26
|
+
if (rumGlobal?.getInternalContext) return rumGlobal.getInternalContext(startTime);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { startRUMInternalContext };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=rumInternalContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rumInternalContext.mjs","names":[],"sources":["../../../src/domain/contexts/rumInternalContext.ts"],"sourcesContent":["import { globalObject } from '@kubesense/kubesense-js-core/util'\nimport type { RelativeTime } from '@kubesense/kubesense-js-core/time'\nimport type { RumInternalContext } from '@kubesense/kubesense-browser-core'\nimport { willSyntheticsInjectRum } from '@kubesense/kubesense-browser-core'\nimport { SKIPPED } from '@kubesense/kubesense-js-core/assembly'\nimport type { Hooks } from '../hooks'\n\ninterface Rum {\n getInternalContext?: (startTime?: RelativeTime) => RumInternalContext | undefined\n}\n\ninterface BrowserWindow {\n KUBESENSE_SDK?: Rum\n KUBESENSE_SDK_SYNTHETICS?: Rum\n}\n\nexport function startRUMInternalContext(hooks: Hooks) {\n const browserWindow = globalObject as BrowserWindow\n\n hooks.assembleEventDefaults.register(({ startTime }) => {\n const internalContext = getRUMInternalContext(startTime)\n if (!internalContext) {\n return SKIPPED\n }\n\n return internalContext\n })\n\n hooks.assembleTelemetry.register(({ startTime }) => {\n const internalContext = getRUMInternalContext(startTime)\n\n if (!internalContext) {\n return SKIPPED\n }\n\n return {\n application: { id: internalContext.application_id },\n view: { id: internalContext.view?.id },\n action: { id: internalContext.user_action?.id as string },\n }\n })\n\n function getRUMInternalContext(startTime?: RelativeTime) {\n const willSyntheticsInjectRumResult = willSyntheticsInjectRum()\n const rumSource = willSyntheticsInjectRumResult\n ? browserWindow.KUBESENSE_SDK_SYNTHETICS\n : browserWindow.KUBESENSE_SDK\n const rumContext = getInternalContextFromRumGlobal(startTime, rumSource)\n\n if (rumContext) {\n return rumContext\n }\n }\n\n function getInternalContextFromRumGlobal(startTime?: RelativeTime, rumGlobal?: Rum): RumInternalContext | undefined {\n if (rumGlobal?.getInternalContext) {\n return rumGlobal.getInternalContext(startTime)\n }\n }\n}\n"],"mappings":";;;;AAgBA,SAAgB,wBAAwB,OAAc;CACpD,MAAM,gBAAgB;CAEtB,MAAM,sBAAsB,UAAU,EAAE,gBAAgB;EACtD,MAAM,kBAAkB,sBAAsB,SAAS;EACvD,IAAI,CAAC,iBACH,OAAO;EAGT,OAAO;CACT,CAAC;CAED,MAAM,kBAAkB,UAAU,EAAE,gBAAgB;EAClD,MAAM,kBAAkB,sBAAsB,SAAS;EAEvD,IAAI,CAAC,iBACH,OAAO;EAGT,OAAO;GACL,aAAa,EAAE,IAAI,gBAAgB,eAAe;GAClD,MAAM,EAAE,IAAI,gBAAgB,MAAM,GAAG;GACrC,QAAQ,EAAE,IAAI,gBAAgB,aAAa,GAAa;EAC1D;CACF,CAAC;CAED,SAAS,sBAAsB,WAA0B;EAKvD,MAAM,aAAa,gCAAgC,WAJb,wBACQ,IAC1C,cAAc,2BACd,cAAc,aACqD;EAEvE,IAAI,YACF,OAAO;CAEX;CAEA,SAAS,gCAAgC,WAA0B,WAAiD;EAClH,IAAI,WAAW,oBACb,OAAO,UAAU,mBAAmB,SAAS;CAEjD;AACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DISCARDED } from "@kubesense/kubesense-js-core/assembly";
|
|
2
|
+
//#region src/domain/contexts/sessionContext.ts
|
|
3
|
+
function startSessionContext(hook, configuration, sessionManager) {
|
|
4
|
+
hook.register(({ startTime }) => {
|
|
5
|
+
const session = sessionManager.findTrackedSession(startTime);
|
|
6
|
+
if (!sessionManager.findTrackedSession(startTime, {
|
|
7
|
+
returnInactive: true,
|
|
8
|
+
maxAge: Infinity
|
|
9
|
+
})) return DISCARDED;
|
|
10
|
+
return {
|
|
11
|
+
service: configuration.service,
|
|
12
|
+
session_id: session ? session.id : void 0,
|
|
13
|
+
session: session ? { id: session.id } : void 0
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { startSessionContext };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=sessionContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionContext.mjs","names":[],"sources":["../../../src/domain/contexts/sessionContext.ts"],"sourcesContent":["import type { SessionManager } from '@kubesense/kubesense-browser-core'\nimport { DISCARDED } from '@kubesense/kubesense-js-core/assembly'\nimport type { LogsConfiguration } from '../configuration'\nimport type { AssembleHook } from '../hooks'\n\nexport function startSessionContext(\n hook: AssembleHook,\n configuration: LogsConfiguration,\n sessionManager: SessionManager\n) {\n hook.register(({ startTime }) => {\n // Used to attach a (fresh, safe-to-reference) session id: subject to the default\n // TRACKED_SESSION_MAX_AGE, so it becomes undefined once the session is too old to reference.\n const session = sessionManager.findTrackedSession(startTime)\n\n // Used for the discard decision: unlike `session` above, this ignores session age (logs\n // should keep being sent indefinitely, with or without a session, once a session was\n // legitimately tracked here) but still respects sampling.\n const isSessionTracked = sessionManager.findTrackedSession(startTime, {\n returnInactive: true,\n maxAge: Infinity,\n })\n\n if (!isSessionTracked) {\n return DISCARDED\n }\n\n return {\n service: configuration.service,\n session_id: session ? session.id : undefined,\n session: session ? { id: session.id } : undefined,\n }\n })\n}\n"],"mappings":";;AAKA,SAAgB,oBACd,MACA,eACA,gBACA;CACA,KAAK,UAAU,EAAE,gBAAgB;EAG/B,MAAM,UAAU,eAAe,mBAAmB,SAAS;EAU3D,IAAI,CALqB,eAAe,mBAAmB,WAAW;GACpE,gBAAgB;GAChB,QAAQ;EACV,CAEoB,GAClB,OAAO;EAGT,OAAO;GACL,SAAS,cAAc;GACvB,YAAY,UAAU,QAAQ,KAAK,KAAA;GACnC,SAAS,UAAU,EAAE,IAAI,QAAQ,GAAG,IAAI,KAAA;EAC1C;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DISCARDED, SKIPPED } from "@kubesense/kubesense-js-core/assembly";
|
|
2
|
+
//#region src/domain/contexts/trackingConsentContext.ts
|
|
3
|
+
function startTrackingConsentContext(hooks, trackingConsentState) {
|
|
4
|
+
function isConsented() {
|
|
5
|
+
if (!trackingConsentState.isGranted()) return DISCARDED;
|
|
6
|
+
return SKIPPED;
|
|
7
|
+
}
|
|
8
|
+
hooks.assembleEventDefaults.register(isConsented);
|
|
9
|
+
hooks.assembleTelemetry.register(isConsented);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { startTrackingConsentContext };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=trackingConsentContext.mjs.map
|