@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 @@
|
|
|
1
|
+
{"version":3,"file":"assembly.js","names":["STATUSES","createEventRateLimiter","toRelativeTime","DISCARDED","buildTags","combine","ErrorSource"],"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,mBAAoBA,eAAAA,SAAsB,OAAO,CAAC,QAAQ,CAAC;CACjE,MAAM,kBAAuD,CAAC;CAC9D,iBAAiB,SAAS,WAAW;EACnC,gBAAgB,WAAA,GAAUC,kCAAAA,uBAAAA,CAAuB,QAAQ,aAAa,cAAc;CACtF,CAAC;CAED,UAAU,UAAA,IAEP,EAAE,cAAc,qBAAqB,KAAA,GAAW,eAAe,QAAQ,CAAC,QAAQ;EAC/E,MAAM,aAAA,GAAYC,kCAAAA,eAAAA,CAAe,aAAa,IAAI;EAClD,MAAM,gBAAgB,sBAAsB,iBAAiB;EAC7D,MAAM,iBAAqC;GACzC;GACc;GACd;EACF;EACA,MAAM,6BAA6B,MAAM,sBAAsB,QAAQ,cAAc;EACrF,IAAI,+BAA+BC,sCAAAA,WACjC;EAGF,MAAM,sBAAsB,MAAM,cAAc,QAAQ,cAAc;EACtE,IAAI,wBAAwBA,sCAAAA,WAC1B;EAGF,MAAM,gBAAA,GAAeC,kCAAAA,UAAAA,CAAU,aAAa;EAE5C,MAAM,OAAA,GAAMC,kCAAAA,QAAAA,CACV,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,WAAWC,kCAAAA,YAAY,UACzB,gBAAgB,IAAI,WAAW,gBAAgB,UAAA,CAAW,eAAe,GAE5E;EAGF,UAAU,OAAA,GAAyC,GAAG;CACxD,CACF;AACF"}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import type { InitConfiguration } from '@kubesense/kubesense-browser-core';
|
|
2
|
+
import { ConsoleApiName } from '@kubesense/kubesense-js-core/util';
|
|
3
|
+
import { RawReportType } from '@kubesense/kubesense-browser-core';
|
|
4
|
+
import type { InferredConfig } from '@kubesense/kubesense-js-core/configuration';
|
|
5
|
+
import type { LogsEvent } from '../logsEvent.types';
|
|
6
|
+
import type { LogsEventDomainContext } from '../domainContext.types';
|
|
7
|
+
import type { LogsPlugin } from './plugins';
|
|
8
|
+
/**
|
|
9
|
+
* Init Configuration for the Logs browser SDK.
|
|
10
|
+
*
|
|
11
|
+
* @category Main
|
|
12
|
+
* @example NPM
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { kubesenseLogs } from '@kubesense/kubesense-browser-logs'
|
|
15
|
+
*
|
|
16
|
+
* kubesenseLogs.init({
|
|
17
|
+
* clientToken: '<KUBESENSE_CLIENT_TOKEN>',
|
|
18
|
+
* kubesenseRumEndpoint: '<KUBESENSE_RUM_ENDPOINT>',
|
|
19
|
+
* // ...
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
* @example CDN
|
|
23
|
+
* ```ts
|
|
24
|
+
* KUBESENSE_LOGS.init({
|
|
25
|
+
* clientToken: '<KUBESENSE_CLIENT_TOKEN>',
|
|
26
|
+
* kubesenseRumEndpoint: '<KUBESENSE_RUM_ENDPOINT>',
|
|
27
|
+
* // ...
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export interface LogsInitConfiguration extends InitConfiguration {
|
|
32
|
+
/**
|
|
33
|
+
* Access to every logs collected by the Logs SDK before they are sent to KubeSense.
|
|
34
|
+
* It allows:
|
|
35
|
+
* - Enrich your logs with additional context attributes
|
|
36
|
+
* - Modify your logs to modify their content, or redact sensitive sequences (see the list of editable properties)
|
|
37
|
+
* - Discard selected logs
|
|
38
|
+
*
|
|
39
|
+
* @category Data Collection
|
|
40
|
+
*/
|
|
41
|
+
beforeSend?: LogsBeforeSend | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Forward uncaught exceptions and network errors to KubeSense.
|
|
44
|
+
*
|
|
45
|
+
* To capture `console.error` calls, use {@link forwardConsoleLogs} with `"error"` (or `"all"`).
|
|
46
|
+
*
|
|
47
|
+
* @category Data Collection
|
|
48
|
+
* @defaultValue true
|
|
49
|
+
* @see forwardConsoleLogs
|
|
50
|
+
*/
|
|
51
|
+
forwardErrorsToLogs?: boolean | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Forward logs from console.* to KubeSense. Use "all" to forward everything or an array of console API names to forward only a subset.
|
|
54
|
+
*
|
|
55
|
+
* @category Data Collection
|
|
56
|
+
*/
|
|
57
|
+
forwardConsoleLogs?: ConsoleApiName[] | 'all' | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* 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.
|
|
60
|
+
*
|
|
61
|
+
* @category Data Collection
|
|
62
|
+
*/
|
|
63
|
+
forwardReports?: RawReportType[] | 'all' | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* List of plugins to enable. The plugins API is unstable and experimental, and may change without
|
|
66
|
+
* notice. Please use only plugins provided by KubeSense matching the version of the SDK you are
|
|
67
|
+
* using.
|
|
68
|
+
*
|
|
69
|
+
* @experimental
|
|
70
|
+
*/
|
|
71
|
+
plugins?: LogsPlugin[] | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Enable dashboard-managed SDK settings served by the KubeSense collector.
|
|
74
|
+
*
|
|
75
|
+
* Logs reads the same cached document as RUM, but only consumes the `features.logs` switch and
|
|
76
|
+
* the `logs` section. The document is fetched asynchronously after the SDK starts, so it never
|
|
77
|
+
* delays initialization, and cached settings are applied on the next page load.
|
|
78
|
+
*
|
|
79
|
+
* @category Data Collection
|
|
80
|
+
* @defaultValue false
|
|
81
|
+
*/
|
|
82
|
+
enableRemoteSdkConfiguration?: boolean | undefined;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Function called before a Log event is sent to KubeSense. See {@link LogsInitConfiguration.beforeSend}
|
|
86
|
+
*
|
|
87
|
+
* @param event - The log event
|
|
88
|
+
* @param context - The log event domain context
|
|
89
|
+
* @returns true if the event should be sent to KubeSense, false otherwise
|
|
90
|
+
*/
|
|
91
|
+
export type LogsBeforeSend = (event: LogsEvent, context: LogsEventDomainContext) => boolean;
|
|
92
|
+
export declare const LOGS_SCHEMA: {
|
|
93
|
+
readonly forwardErrorsToLogs: {
|
|
94
|
+
readonly type: "boolean";
|
|
95
|
+
readonly default: true;
|
|
96
|
+
readonly strict: false;
|
|
97
|
+
};
|
|
98
|
+
readonly enableRemoteSdkConfiguration: {
|
|
99
|
+
readonly type: "boolean";
|
|
100
|
+
readonly default: false;
|
|
101
|
+
readonly strict: false;
|
|
102
|
+
};
|
|
103
|
+
readonly forwardConsoleLogs: {
|
|
104
|
+
readonly type: "enum";
|
|
105
|
+
readonly values: {
|
|
106
|
+
readonly log: "log";
|
|
107
|
+
readonly debug: "debug";
|
|
108
|
+
readonly info: "info";
|
|
109
|
+
readonly warn: "warn";
|
|
110
|
+
readonly error: "error";
|
|
111
|
+
};
|
|
112
|
+
readonly multiple: true;
|
|
113
|
+
readonly allowAll: true;
|
|
114
|
+
readonly default: ConsoleApiName[];
|
|
115
|
+
};
|
|
116
|
+
readonly forwardReports: {
|
|
117
|
+
readonly type: "enum";
|
|
118
|
+
readonly values: {
|
|
119
|
+
readonly intervention: "intervention";
|
|
120
|
+
readonly deprecation: "deprecation";
|
|
121
|
+
readonly cspViolation: "csp_violation";
|
|
122
|
+
};
|
|
123
|
+
readonly multiple: true;
|
|
124
|
+
readonly allowAll: true;
|
|
125
|
+
readonly default: RawReportType[];
|
|
126
|
+
};
|
|
127
|
+
readonly plugins: {
|
|
128
|
+
readonly type: "schema";
|
|
129
|
+
readonly multiple: true;
|
|
130
|
+
readonly strict: false;
|
|
131
|
+
readonly default: LogsPlugin[];
|
|
132
|
+
readonly schema: {
|
|
133
|
+
readonly name: {
|
|
134
|
+
readonly type: "string";
|
|
135
|
+
readonly required: true;
|
|
136
|
+
};
|
|
137
|
+
readonly getConfigurationTelemetry: {
|
|
138
|
+
readonly type: "function";
|
|
139
|
+
readonly strict: false;
|
|
140
|
+
readonly signature: LogsPlugin["getConfigurationTelemetry"];
|
|
141
|
+
};
|
|
142
|
+
readonly onInit: {
|
|
143
|
+
readonly type: "function";
|
|
144
|
+
readonly strict: false;
|
|
145
|
+
readonly signature: LogsPlugin["onInit"];
|
|
146
|
+
};
|
|
147
|
+
readonly onLogsStart: {
|
|
148
|
+
readonly type: "function";
|
|
149
|
+
readonly strict: false;
|
|
150
|
+
readonly signature: LogsPlugin["onLogsStart"];
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
readonly clientToken: {
|
|
155
|
+
readonly type: "string";
|
|
156
|
+
readonly required: true;
|
|
157
|
+
};
|
|
158
|
+
readonly service: {
|
|
159
|
+
readonly type: "string";
|
|
160
|
+
};
|
|
161
|
+
readonly env: {
|
|
162
|
+
readonly type: "string";
|
|
163
|
+
};
|
|
164
|
+
readonly version: {
|
|
165
|
+
readonly type: "string";
|
|
166
|
+
};
|
|
167
|
+
readonly kubesenseRumEndpoint: {
|
|
168
|
+
readonly type: "site";
|
|
169
|
+
readonly default: string;
|
|
170
|
+
};
|
|
171
|
+
readonly proxy: {
|
|
172
|
+
readonly type: "union";
|
|
173
|
+
readonly variants: readonly [{
|
|
174
|
+
readonly type: "string";
|
|
175
|
+
}, {
|
|
176
|
+
readonly type: "function";
|
|
177
|
+
readonly signature: import("@kubesense/kubesense-js-core/transport").ProxyFn | undefined;
|
|
178
|
+
}];
|
|
179
|
+
};
|
|
180
|
+
readonly sessionSampleRate: {
|
|
181
|
+
readonly type: "percentage";
|
|
182
|
+
readonly default: 100;
|
|
183
|
+
};
|
|
184
|
+
readonly telemetrySampleRate: {
|
|
185
|
+
readonly type: "percentage";
|
|
186
|
+
readonly default: 20;
|
|
187
|
+
};
|
|
188
|
+
readonly telemetryConfigurationSampleRate: {
|
|
189
|
+
readonly type: "percentage";
|
|
190
|
+
readonly default: 5;
|
|
191
|
+
};
|
|
192
|
+
readonly telemetryUsageSampleRate: {
|
|
193
|
+
readonly type: "percentage";
|
|
194
|
+
readonly default: 5;
|
|
195
|
+
};
|
|
196
|
+
readonly silentMultipleInit: {
|
|
197
|
+
readonly type: "boolean";
|
|
198
|
+
readonly default: false;
|
|
199
|
+
readonly strict: false;
|
|
200
|
+
};
|
|
201
|
+
readonly storeContextsAcrossPages: {
|
|
202
|
+
readonly type: "boolean";
|
|
203
|
+
readonly default: false;
|
|
204
|
+
readonly strict: false;
|
|
205
|
+
};
|
|
206
|
+
readonly trackAnonymousUser: {
|
|
207
|
+
readonly type: "boolean";
|
|
208
|
+
readonly default: true;
|
|
209
|
+
readonly strict: false;
|
|
210
|
+
};
|
|
211
|
+
readonly useSecureSessionCookie: {
|
|
212
|
+
readonly type: "boolean";
|
|
213
|
+
readonly default: false;
|
|
214
|
+
readonly strict: false;
|
|
215
|
+
};
|
|
216
|
+
readonly usePartitionedCrossSiteSessionCookie: {
|
|
217
|
+
readonly type: "boolean";
|
|
218
|
+
readonly default: false;
|
|
219
|
+
readonly strict: false;
|
|
220
|
+
};
|
|
221
|
+
readonly trackSessionAcrossSubdomains: {
|
|
222
|
+
readonly type: "boolean";
|
|
223
|
+
readonly default: false;
|
|
224
|
+
readonly strict: false;
|
|
225
|
+
};
|
|
226
|
+
readonly allowedTrackingOrigins: {
|
|
227
|
+
readonly type: "match-option";
|
|
228
|
+
readonly multiple: true;
|
|
229
|
+
readonly strict: false;
|
|
230
|
+
};
|
|
231
|
+
readonly trackingConsent: {
|
|
232
|
+
readonly type: "enum";
|
|
233
|
+
readonly values: {
|
|
234
|
+
readonly GRANTED: "granted";
|
|
235
|
+
readonly NOT_GRANTED: "not-granted";
|
|
236
|
+
};
|
|
237
|
+
readonly default: "granted";
|
|
238
|
+
};
|
|
239
|
+
readonly beforeSend: {
|
|
240
|
+
readonly type: "function";
|
|
241
|
+
readonly signature: ((event: any, context?: any) => unknown) | undefined;
|
|
242
|
+
};
|
|
243
|
+
readonly source: {
|
|
244
|
+
readonly type: "enum";
|
|
245
|
+
readonly values: readonly ["browser", "flutter", "unity"];
|
|
246
|
+
readonly default: "browser";
|
|
247
|
+
readonly strict: false;
|
|
248
|
+
};
|
|
249
|
+
readonly sessionPersistence: {
|
|
250
|
+
readonly type: "enum";
|
|
251
|
+
readonly values: readonly ["cookie", "local-storage", "memory"];
|
|
252
|
+
readonly multiple: true;
|
|
253
|
+
readonly strict: false;
|
|
254
|
+
};
|
|
255
|
+
readonly replica: {
|
|
256
|
+
readonly type: "schema";
|
|
257
|
+
readonly schema: {
|
|
258
|
+
readonly clientToken: {
|
|
259
|
+
readonly type: "string";
|
|
260
|
+
readonly required: true;
|
|
261
|
+
};
|
|
262
|
+
readonly applicationId: {
|
|
263
|
+
readonly type: "string";
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
readonly datacenter: {
|
|
268
|
+
readonly type: "string";
|
|
269
|
+
};
|
|
270
|
+
readonly sdkVersion: {
|
|
271
|
+
readonly type: "string";
|
|
272
|
+
};
|
|
273
|
+
readonly variant: {
|
|
274
|
+
readonly type: "string";
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
export type LogsConfiguration = InferredConfig<typeof LOGS_SCHEMA>;
|
|
278
|
+
export declare function validateAndBuildLogsConfiguration(initConfiguration: LogsInitConfiguration): LogsConfiguration | undefined;
|
|
279
|
+
export declare function serializeLogsConfiguration(configuration: LogsInitConfiguration): {
|
|
280
|
+
session_sample_rate: number | undefined;
|
|
281
|
+
telemetry_sample_rate: number | undefined;
|
|
282
|
+
telemetry_configuration_sample_rate: number | undefined;
|
|
283
|
+
telemetry_usage_sample_rate: number | undefined;
|
|
284
|
+
use_before_send: boolean;
|
|
285
|
+
use_partitioned_cross_site_session_cookie: boolean | undefined;
|
|
286
|
+
use_secure_session_cookie: boolean | undefined;
|
|
287
|
+
use_proxy: boolean;
|
|
288
|
+
silent_multiple_init: boolean | undefined;
|
|
289
|
+
track_session_across_subdomains: boolean | undefined;
|
|
290
|
+
track_anonymous_user: boolean | undefined;
|
|
291
|
+
session_persistence: import("@kubesense/kubesense-browser-core").SessionPersistence | undefined;
|
|
292
|
+
store_contexts_across_pages: boolean;
|
|
293
|
+
allow_untrusted_events: boolean;
|
|
294
|
+
tracking_consent: import("@kubesense/kubesense-browser-core").TrackingConsent | undefined;
|
|
295
|
+
use_allowed_tracking_origins: boolean;
|
|
296
|
+
source: "browser" | "flutter" | "unity" | undefined;
|
|
297
|
+
sdk_version: string | undefined;
|
|
298
|
+
variant: string | undefined;
|
|
299
|
+
forward_errors_to_logs: boolean | undefined;
|
|
300
|
+
enable_remote_sdk_configuration: boolean;
|
|
301
|
+
forward_console_logs: ConsoleApiName[] | "all" | undefined;
|
|
302
|
+
forward_reports: RawReportType[] | "all" | undefined;
|
|
303
|
+
plugins: {
|
|
304
|
+
name: string;
|
|
305
|
+
}[] | undefined;
|
|
306
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
let _kubesense_kubesense_js_core_util = require("@kubesense/kubesense-js-core/util");
|
|
2
|
+
let _kubesense_kubesense_browser_core = require("@kubesense/kubesense-browser-core");
|
|
3
|
+
let _kubesense_kubesense_js_core_configuration = require("@kubesense/kubesense-js-core/configuration");
|
|
4
|
+
//#region src/domain/configuration.ts
|
|
5
|
+
const LOGS_SCHEMA = {
|
|
6
|
+
..._kubesense_kubesense_browser_core.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: _kubesense_kubesense_js_core_util.ConsoleApiName,
|
|
20
|
+
multiple: true,
|
|
21
|
+
allowAll: true,
|
|
22
|
+
default: []
|
|
23
|
+
},
|
|
24
|
+
forwardReports: {
|
|
25
|
+
type: "enum",
|
|
26
|
+
values: _kubesense_kubesense_browser_core.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 = (0, _kubesense_kubesense_js_core_configuration.validateAndBuildConfiguration)(initConfiguration, LOGS_SCHEMA, _kubesense_kubesense_browser_core.display);
|
|
61
|
+
if (!config) return;
|
|
62
|
+
return {
|
|
63
|
+
...config,
|
|
64
|
+
beforeSend: config.beforeSend ? (0, _kubesense_kubesense_browser_core.catchUserErrors)(config.beforeSend, "beforeSend threw an error:") : void 0
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function serializeLogsConfiguration(configuration) {
|
|
68
|
+
const baseSerializedInitConfiguration = (0, _kubesense_kubesense_browser_core.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
|
+
exports.LOGS_SCHEMA = LOGS_SCHEMA;
|
|
83
|
+
exports.serializeLogsConfiguration = serializeLogsConfiguration;
|
|
84
|
+
exports.validateAndBuildLogsConfiguration = validateAndBuildLogsConfiguration;
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.js","names":["BROWSER_CORE_SCHEMA","ConsoleApiName","RawReportType","validateAndBuildConfiguration","display","catchUserErrors","serializeConfiguration"],"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,GAAGA,kCAAAA;CACH,qBAAqB;EAAE,MAAM;EAAW,SAAS;EAAM,QAAQ;CAAM;CACrE,8BAA8B;EAAE,MAAM;EAAW,SAAS;EAAO,QAAQ;CAAM;CAC/E,oBAAoB;EAClB,MAAM;EACN,QAAQC,kCAAAA;EACR,UAAU;EACV,UAAU;EACV,SAAS,CAAC;CACZ;CACA,gBAAgB;EACd,MAAM;EACN,QAAQC,kCAAAA;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,UAAA,GAASC,2CAAAA,8BAAAA,CACb,mBACA,aACAC,kCAAAA,OACF;CACA,IAAI,CAAC,QACH;CAEF,OAAO;EACL,GAAG;EACH,YAAY,OAAO,cAAA,GAAaC,kCAAAA,gBAAAA,CAAgB,OAAO,YAAmB,4BAA4B,IAAI,KAAA;CAC5G;AACF;AAEA,SAAgB,2BAA2B,eAAsC;CAC/E,MAAM,mCAAA,GAAkCC,kCAAAA,uBAAAA,CAAuB,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,20 @@
|
|
|
1
|
+
import type { ClocksState } from '@kubesense/kubesense-js-core/time';
|
|
2
|
+
import type { Context, Observable, BufferedData } from '@kubesense/kubesense-browser-core';
|
|
3
|
+
import type { LogsConfiguration } from '../configuration';
|
|
4
|
+
import type { LifeCycle } from '../lifeCycle';
|
|
5
|
+
export interface ProvidedError {
|
|
6
|
+
startClocks: ClocksState;
|
|
7
|
+
error: unknown;
|
|
8
|
+
context?: Context;
|
|
9
|
+
handlingStack: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const LogStatusForApi: {
|
|
12
|
+
log: "info";
|
|
13
|
+
debug: "debug";
|
|
14
|
+
info: "info";
|
|
15
|
+
warn: "warn";
|
|
16
|
+
error: "error";
|
|
17
|
+
};
|
|
18
|
+
export declare function startConsoleCollection(configuration: LogsConfiguration, lifeCycle: LifeCycle, bufferedDataObservable: Observable<BufferedData>): {
|
|
19
|
+
stop: () => void;
|
|
20
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const require_isAuthorized = require("../logger/isAuthorized.js");
|
|
2
|
+
const require_createErrorFieldFromRawError = require("../createErrorFieldFromRawError.js");
|
|
3
|
+
require("../lifeCycle.js");
|
|
4
|
+
let _kubesense_kubesense_js_core_util = require("@kubesense/kubesense-js-core/util");
|
|
5
|
+
let _kubesense_kubesense_browser_core = require("@kubesense/kubesense-browser-core");
|
|
6
|
+
let _kubesense_kubesense_js_core_time = require("@kubesense/kubesense-js-core/time");
|
|
7
|
+
//#region src/domain/console/consoleCollection.ts
|
|
8
|
+
const LogStatusForApi = {
|
|
9
|
+
[_kubesense_kubesense_js_core_util.ConsoleApiName.log]: require_isAuthorized.StatusType.info,
|
|
10
|
+
[_kubesense_kubesense_js_core_util.ConsoleApiName.debug]: require_isAuthorized.StatusType.debug,
|
|
11
|
+
[_kubesense_kubesense_js_core_util.ConsoleApiName.info]: require_isAuthorized.StatusType.info,
|
|
12
|
+
[_kubesense_kubesense_js_core_util.ConsoleApiName.warn]: require_isAuthorized.StatusType.warn,
|
|
13
|
+
[_kubesense_kubesense_js_core_util.ConsoleApiName.error]: require_isAuthorized.StatusType.error
|
|
14
|
+
};
|
|
15
|
+
function startConsoleCollection(configuration, lifeCycle, bufferedDataObservable) {
|
|
16
|
+
const subscription = bufferedDataObservable.subscribe(({ data: log, type }) => {
|
|
17
|
+
if (type !== _kubesense_kubesense_browser_core.BufferedDataType.CONSOLE || !configuration.forwardConsoleLogs.includes(log.api)) return;
|
|
18
|
+
const collectedData = {
|
|
19
|
+
rawLogsEvent: (0, _kubesense_kubesense_js_core_util.combine)({
|
|
20
|
+
date: (0, _kubesense_kubesense_js_core_time.timeStampNow)(),
|
|
21
|
+
message: log.message,
|
|
22
|
+
origin: _kubesense_kubesense_browser_core.ErrorSource.CONSOLE,
|
|
23
|
+
error: log.error && require_createErrorFieldFromRawError.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
|
+
exports.LogStatusForApi = LogStatusForApi;
|
|
35
|
+
exports.startConsoleCollection = startConsoleCollection;
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=consoleCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consoleCollection.js","names":["ConsoleApiName","StatusType","BufferedDataType","combine","timeStampNow","ErrorSource","createErrorFieldFromRawError"],"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;EAC5BA,kCAAAA,eAAe,MAAMC,qBAAAA,WAAW;EAChCD,kCAAAA,eAAe,QAAQC,qBAAAA,WAAW;EAClCD,kCAAAA,eAAe,OAAOC,qBAAAA,WAAW;EACjCD,kCAAAA,eAAe,OAAOC,qBAAAA,WAAW;EACjCD,kCAAAA,eAAe,QAAQC,qBAAAA,WAAW;AACrC;AAEA,SAAgB,uBACd,eACA,WACA,wBACA;CACA,MAAM,eAAe,uBAAuB,WAAW,EAAE,MAAM,KAAK,WAAW;EAC7E,IAAI,SAASC,kCAAAA,iBAAiB,WAAW,CAAC,cAAc,mBAAmB,SAAS,IAAI,GAAG,GACzF;EAEF,MAAM,gBAAyD;GAC7D,eAAA,GAAcC,kCAAAA,QAAAA,CACZ;IACE,OAAA,GAAMC,kCAAAA,aAAAA,CAAa;IACnB,SAAS,IAAI;IACb,QAAQC,kCAAAA,YAAY;IACpB,OAAO,IAAI,SAASC,qCAAAA,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
|
+
let _kubesense_kubesense_js_core_util = require("@kubesense/kubesense-js-core/util");
|
|
2
|
+
//#region src/domain/contexts/commonContext.ts
|
|
3
|
+
function buildCommonContext() {
|
|
4
|
+
if (_kubesense_kubesense_js_core_util.isWorkerEnvironment) return {};
|
|
5
|
+
return { view: {
|
|
6
|
+
referrer: document.referrer,
|
|
7
|
+
url: window.location.href
|
|
8
|
+
} };
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.buildCommonContext = buildCommonContext;
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=commonContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commonContext.js","names":["isWorkerEnvironment"],"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,IAAIA,kCAAAA,qBACF,OAAO,CAAC;CAGV,OAAO,EACL,MAAM;EACJ,UAAU,SAAS;EACnB,KAAK,OAAO,SAAS;CACvB,EACF;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SessionManager } from '@kubesense/kubesense-browser-core';
|
|
2
|
+
export interface InternalContext {
|
|
3
|
+
session_id: string | undefined;
|
|
4
|
+
}
|
|
5
|
+
export declare function startInternalContext(sessionManager: SessionManager): {
|
|
6
|
+
get: (startTime?: number) => InternalContext | undefined;
|
|
7
|
+
};
|
|
@@ -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
|
+
exports.startInternalContext = startInternalContext;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=internalContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internalContext.js","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
|
+
let _kubesense_kubesense_js_core_util = require("@kubesense/kubesense-js-core/util");
|
|
2
|
+
let _kubesense_kubesense_browser_core = require("@kubesense/kubesense-browser-core");
|
|
3
|
+
let _kubesense_kubesense_js_core_assembly = require("@kubesense/kubesense-js-core/assembly");
|
|
4
|
+
//#region src/domain/contexts/rumInternalContext.ts
|
|
5
|
+
function startRUMInternalContext(hooks) {
|
|
6
|
+
const browserWindow = _kubesense_kubesense_js_core_util.globalObject;
|
|
7
|
+
hooks.assembleEventDefaults.register(({ startTime }) => {
|
|
8
|
+
const internalContext = getRUMInternalContext(startTime);
|
|
9
|
+
if (!internalContext) return _kubesense_kubesense_js_core_assembly.SKIPPED;
|
|
10
|
+
return internalContext;
|
|
11
|
+
});
|
|
12
|
+
hooks.assembleTelemetry.register(({ startTime }) => {
|
|
13
|
+
const internalContext = getRUMInternalContext(startTime);
|
|
14
|
+
if (!internalContext) return _kubesense_kubesense_js_core_assembly.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, (0, _kubesense_kubesense_browser_core.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
|
+
exports.startRUMInternalContext = startRUMInternalContext;
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=rumInternalContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rumInternalContext.js","names":["globalObject","SKIPPED","willSyntheticsInjectRum"],"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,gBAAgBA,kCAAAA;CAEtB,MAAM,sBAAsB,UAAU,EAAE,gBAAgB;EACtD,MAAM,kBAAkB,sBAAsB,SAAS;EACvD,IAAI,CAAC,iBACH,OAAOC,sCAAAA;EAGT,OAAO;CACT,CAAC;CAED,MAAM,kBAAkB,UAAU,EAAE,gBAAgB;EAClD,MAAM,kBAAkB,sBAAsB,SAAS;EAEvD,IAAI,CAAC,iBACH,OAAOA,sCAAAA;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,YAAA,GAJbC,kCAAAA,wBAAAA,CACQ,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,4 @@
|
|
|
1
|
+
import type { SessionManager } from '@kubesense/kubesense-browser-core';
|
|
2
|
+
import type { LogsConfiguration } from '../configuration';
|
|
3
|
+
import type { AssembleHook } from '../hooks';
|
|
4
|
+
export declare function startSessionContext(hook: AssembleHook, configuration: LogsConfiguration, sessionManager: SessionManager): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
let _kubesense_kubesense_js_core_assembly = require("@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 _kubesense_kubesense_js_core_assembly.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
|
+
exports.startSessionContext = startSessionContext;
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=sessionContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionContext.js","names":["DISCARDED"],"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,OAAOA,sCAAAA;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
|
+
let _kubesense_kubesense_js_core_assembly = require("@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 _kubesense_kubesense_js_core_assembly.DISCARDED;
|
|
6
|
+
return _kubesense_kubesense_js_core_assembly.SKIPPED;
|
|
7
|
+
}
|
|
8
|
+
hooks.assembleEventDefaults.register(isConsented);
|
|
9
|
+
hooks.assembleTelemetry.register(isConsented);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.startTrackingConsentContext = startTrackingConsentContext;
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=trackingConsentContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trackingConsentContext.js","names":["DISCARDED","SKIPPED"],"sources":["../../../src/domain/contexts/trackingConsentContext.ts"],"sourcesContent":["import { DISCARDED, SKIPPED } from '@kubesense/kubesense-js-core/assembly'\nimport type { TrackingConsentState } from '@kubesense/kubesense-browser-core'\nimport type { Hooks } from '../hooks'\n\nexport function startTrackingConsentContext(hooks: Hooks, trackingConsentState: TrackingConsentState) {\n function isConsented() {\n const wasConsented = trackingConsentState.isGranted()\n\n if (!wasConsented) {\n return DISCARDED\n }\n\n return SKIPPED\n }\n\n hooks.assembleEventDefaults.register(isConsented)\n hooks.assembleTelemetry.register(isConsented)\n}\n"],"mappings":";;AAIA,SAAgB,4BAA4B,OAAc,sBAA4C;CACpG,SAAS,cAAc;EAGrB,IAAI,CAFiB,qBAAqB,UAE1B,GACd,OAAOA,sCAAAA;EAGT,OAAOC,sCAAAA;CACT;CAEA,MAAM,sBAAsB,SAAS,WAAW;CAChD,MAAM,kBAAkB,SAAS,WAAW;AAC9C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RawError } from '@kubesense/kubesense-browser-core';
|
|
2
|
+
import type { RawLoggerLogsEvent } from '../rawLogsEvent.types';
|
|
3
|
+
export declare function createErrorFieldFromRawError(rawError: RawError, {
|
|
4
|
+
/**
|
|
5
|
+
* Set this to `true` to include the error message in the error field. In most cases, the error
|
|
6
|
+
* message is already included in the log message, so we don't need to include it again.
|
|
7
|
+
*/
|
|
8
|
+
includeMessage, }?: {
|
|
9
|
+
includeMessage?: boolean | undefined;
|
|
10
|
+
}): NonNullable<RawLoggerLogsEvent['error']>;
|