@cloudcare/browser-logs 3.1.8 → 3.1.10
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/bundle/dataflux-logs.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/startLogs.js +1 -2
- package/cjs/boot/startLogs.js.map +1 -1
- package/cjs/domain/assembly.js +1 -3
- package/cjs/domain/assembly.js.map +1 -1
- package/cjs/domain/logger.js +3 -0
- package/cjs/domain/logger.js.map +1 -1
- package/cjs/domain/logsCollection/console/consoleCollection.js +0 -1
- package/cjs/domain/logsCollection/console/consoleCollection.js.map +1 -1
- package/cjs/domain/logsCollection/networkError/networkErrorCollection.js +0 -8
- package/cjs/domain/logsCollection/networkError/networkErrorCollection.js.map +1 -1
- package/cjs/domain/logsCollection/report/reportCollection.js +0 -1
- package/cjs/domain/logsCollection/report/reportCollection.js.map +1 -1
- package/cjs/domain/logsCollection/rumtimeError/runtimeErrorCollection.js +0 -1
- package/cjs/domain/logsCollection/rumtimeError/runtimeErrorCollection.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/startLogs.js +1 -2
- package/esm/boot/startLogs.js.map +1 -1
- package/esm/domain/assembly.js +1 -3
- package/esm/domain/assembly.js.map +1 -1
- package/esm/domain/logger.js +3 -0
- package/esm/domain/logger.js.map +1 -1
- package/esm/domain/logsCollection/console/consoleCollection.js +0 -1
- package/esm/domain/logsCollection/console/consoleCollection.js.map +1 -1
- package/esm/domain/logsCollection/networkError/networkErrorCollection.js +0 -8
- package/esm/domain/logsCollection/networkError/networkErrorCollection.js.map +1 -1
- package/esm/domain/logsCollection/report/reportCollection.js +0 -1
- package/esm/domain/logsCollection/report/reportCollection.js.map +1 -1
- package/esm/domain/logsCollection/rumtimeError/runtimeErrorCollection.js +0 -1
- package/esm/domain/logsCollection/rumtimeError/runtimeErrorCollection.js.map +1 -1
- package/package.json +5 -4
- package/src/boot/startLogs.js +1 -1
- package/src/domain/assembly.js +0 -1
- package/src/domain/logger.js +3 -1
- package/src/domain/logsCollection/console/consoleCollection.js +17 -10
- package/src/domain/logsCollection/networkError/networkErrorCollection.js +2 -7
- package/src/domain/logsCollection/report/reportCollection.js +1 -1
- package/src/domain/logsCollection/rumtimeError/runtimeErrorCollection.js +14 -8
- package/types/configuration.d.ts +12 -0
- package/types/index.d.ts +30 -0
- package/types/logger.d.ts +71 -0
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
timeStampNow,
|
|
3
|
+
ConsoleApiName,
|
|
4
|
+
ErrorSource,
|
|
5
|
+
initConsoleObservable,
|
|
6
|
+
LifeCycleEventType
|
|
7
|
+
} from '@cloudcare/browser-core'
|
|
2
8
|
import { StatusType } from '../../logger'
|
|
3
9
|
|
|
4
|
-
|
|
5
10
|
var LogStatusForApi = {
|
|
6
11
|
[ConsoleApiName.log]: StatusType.info,
|
|
7
12
|
[ConsoleApiName.debug]: StatusType.debug,
|
|
8
13
|
[ConsoleApiName.info]: StatusType.info,
|
|
9
14
|
[ConsoleApiName.warn]: StatusType.warn,
|
|
10
|
-
[ConsoleApiName.error]: StatusType.error
|
|
15
|
+
[ConsoleApiName.error]: StatusType.error
|
|
11
16
|
}
|
|
12
17
|
export function startConsoleCollection(configuration, lifeCycle) {
|
|
13
|
-
var consoleSubscription = initConsoleObservable(
|
|
18
|
+
var consoleSubscription = initConsoleObservable(
|
|
19
|
+
configuration.forwardConsoleLogs
|
|
20
|
+
).subscribe(function (log) {
|
|
14
21
|
lifeCycle.notify(LifeCycleEventType.RAW_LOG_COLLECTED, {
|
|
15
22
|
rawLogsEvent: {
|
|
16
23
|
date: timeStampNow(),
|
|
@@ -19,18 +26,18 @@ export function startConsoleCollection(configuration, lifeCycle) {
|
|
|
19
26
|
error:
|
|
20
27
|
log.api === ConsoleApiName.error
|
|
21
28
|
? {
|
|
22
|
-
origin: ErrorSource.CONSOLE,
|
|
23
|
-
stack: log.stack
|
|
29
|
+
origin: ErrorSource.CONSOLE,
|
|
30
|
+
stack: log.stack
|
|
24
31
|
}
|
|
25
32
|
: undefined,
|
|
26
|
-
status: LogStatusForApi[log.api]
|
|
27
|
-
}
|
|
33
|
+
status: LogStatusForApi[log.api]
|
|
34
|
+
}
|
|
28
35
|
})
|
|
29
36
|
})
|
|
30
37
|
|
|
31
38
|
return {
|
|
32
|
-
stop: function(){
|
|
39
|
+
stop: function () {
|
|
33
40
|
consoleSubscription.unsubscribe()
|
|
34
|
-
}
|
|
41
|
+
}
|
|
35
42
|
}
|
|
36
43
|
}
|
|
@@ -69,11 +69,11 @@ export function startNetworkErrorCollection(configuration, lifeCycle) {
|
|
|
69
69
|
format(type) + ' error ' + request.method + ' ' + request.url,
|
|
70
70
|
date: request.startClocks.timeStamp,
|
|
71
71
|
error: {
|
|
72
|
-
origin: ErrorSource.NETWORK,
|
|
72
|
+
origin: ErrorSource.NETWORK,
|
|
73
73
|
stack: responseData || 'Failed to load'
|
|
74
74
|
},
|
|
75
75
|
http: {
|
|
76
|
-
method: request.method,
|
|
76
|
+
method: request.method,
|
|
77
77
|
status_code: request.status,
|
|
78
78
|
url: request.url,
|
|
79
79
|
statusGroup: getStatusGroup(request.status),
|
|
@@ -96,11 +96,6 @@ export function startNetworkErrorCollection(configuration, lifeCycle) {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
// TODO: ideally, computeXhrResponseData should always call the callback with a string instead of
|
|
100
|
-
// `unknown`. But to keep backward compatibility, in the case of XHR with a `responseType` different
|
|
101
|
-
// than "text", the response data should be whatever `xhr.response` is. This is a bit confusing as
|
|
102
|
-
// Logs event 'stack' is expected to be a string. This should be changed in a future major version
|
|
103
|
-
// as it could be a breaking change.
|
|
104
99
|
export function computeXhrResponseData(xhr, configuration, callback) {
|
|
105
100
|
if (typeof xhr.response === 'string') {
|
|
106
101
|
callback(truncateResponseText(xhr.response, configuration))
|
|
@@ -25,7 +25,7 @@ export function startReportCollection(configuration, lifeCycle) {
|
|
|
25
25
|
if (status === StatusType.error) {
|
|
26
26
|
error = {
|
|
27
27
|
kind: report.subtype,
|
|
28
|
-
origin: ErrorSource.REPORT,
|
|
28
|
+
origin: ErrorSource.REPORT,
|
|
29
29
|
stack: report.stack
|
|
30
30
|
}
|
|
31
31
|
} else if (report.stack) {
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
noop,
|
|
3
|
+
ErrorSource,
|
|
4
|
+
trackRuntimeError,
|
|
5
|
+
Observable,
|
|
6
|
+
LifeCycleEventType
|
|
7
|
+
} from '@cloudcare/browser-core'
|
|
2
8
|
import { StatusType } from '../../logger'
|
|
3
9
|
|
|
4
10
|
export function startRuntimeErrorCollection(configuration, lifeCycle) {
|
|
@@ -10,26 +16,26 @@ export function startRuntimeErrorCollection(configuration, lifeCycle) {
|
|
|
10
16
|
|
|
11
17
|
var _trackRuntimeError = trackRuntimeError(rawErrorObservable)
|
|
12
18
|
|
|
13
|
-
var rawErrorSubscription = rawErrorObservable.subscribe(function(rawError) {
|
|
19
|
+
var rawErrorSubscription = rawErrorObservable.subscribe(function (rawError) {
|
|
14
20
|
lifeCycle.notify(LifeCycleEventType.RAW_LOG_COLLECTED, {
|
|
15
21
|
rawLogsEvent: {
|
|
16
22
|
message: rawError.message,
|
|
17
23
|
date: rawError.startClocks.timeStamp,
|
|
18
24
|
error: {
|
|
19
25
|
kind: rawError.type,
|
|
20
|
-
origin: ErrorSource.SOURCE,
|
|
21
|
-
stack: rawError.stack
|
|
26
|
+
origin: ErrorSource.SOURCE,
|
|
27
|
+
stack: rawError.stack
|
|
22
28
|
},
|
|
23
29
|
origin: ErrorSource.SOURCE,
|
|
24
|
-
status: StatusType.error
|
|
25
|
-
}
|
|
30
|
+
status: StatusType.error
|
|
31
|
+
}
|
|
26
32
|
})
|
|
27
33
|
})
|
|
28
34
|
|
|
29
35
|
return {
|
|
30
|
-
stop: function() {
|
|
36
|
+
stop: function () {
|
|
31
37
|
_trackRuntimeError.stop()
|
|
32
38
|
rawErrorSubscription.unsubscribe()
|
|
33
|
-
}
|
|
39
|
+
}
|
|
34
40
|
}
|
|
35
41
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
InitConfiguration,
|
|
3
|
+
ConsoleApiName,
|
|
4
|
+
RawReportType
|
|
5
|
+
} from '@cloudcare/browser-core'
|
|
6
|
+
export interface LogsInitConfiguration extends InitConfiguration {
|
|
7
|
+
beforeSend?: ((event: any) => boolean) | undefined
|
|
8
|
+
forwardErrorsToLogs?: boolean | undefined
|
|
9
|
+
forwardConsoleLogs?: ConsoleApiName[] | 'all' | undefined
|
|
10
|
+
forwardReports?: RawReportType[] | 'all' | undefined
|
|
11
|
+
requestErrorResponseLengthLimit: number
|
|
12
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Logger, LoggerConfiguration } from './logger'
|
|
2
|
+
import type { LogsInitConfiguration } from './configuration'
|
|
3
|
+
import type { InitConfiguration, User, Context } from '@cloudcare/browser-core'
|
|
4
|
+
export interface InternalContext {
|
|
5
|
+
session: {
|
|
6
|
+
id: string | undefined
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export declare const datafluxLogs: {
|
|
10
|
+
logger: Logger
|
|
11
|
+
init: (initConfiguration: LogsInitConfiguration) => void
|
|
12
|
+
getGlobalContext: () => Context
|
|
13
|
+
setGlobalContext: (context: any) => void
|
|
14
|
+
setGlobalContextProperty: (key: any, value: any) => void
|
|
15
|
+
removeGlobalContextProperty: (key: any) => void
|
|
16
|
+
clearGlobalContext: () => void
|
|
17
|
+
createLogger: (name: string, conf?: LoggerConfiguration) => Logger
|
|
18
|
+
getLogger: (name: string) => Logger | undefined
|
|
19
|
+
getInitConfiguration: () => InitConfiguration | undefined
|
|
20
|
+
getInternalContext: (
|
|
21
|
+
startTime?: number | undefined
|
|
22
|
+
) => InternalContext | undefined
|
|
23
|
+
setUser: (newUser: User) => void
|
|
24
|
+
getUser: () => Context
|
|
25
|
+
setUserProperty: (key: any, property: any) => void
|
|
26
|
+
removeUserProperty: (key: any) => void
|
|
27
|
+
clearUser: () => void
|
|
28
|
+
} & {
|
|
29
|
+
onReady(callback: () => void): void
|
|
30
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Context } from '@cloudcare/browser-core'
|
|
2
|
+
export interface CommonContext {
|
|
3
|
+
view: {
|
|
4
|
+
referrer: string
|
|
5
|
+
url: string
|
|
6
|
+
}
|
|
7
|
+
context: Context
|
|
8
|
+
user: User
|
|
9
|
+
}
|
|
10
|
+
export interface LogsMessage {
|
|
11
|
+
message: string
|
|
12
|
+
status: StatusType
|
|
13
|
+
context?: Context
|
|
14
|
+
}
|
|
15
|
+
export type TimeStamp = number & { t: 'Epoch time' }
|
|
16
|
+
export declare const StatusType: {
|
|
17
|
+
readonly debug: 'debug'
|
|
18
|
+
readonly error: 'error'
|
|
19
|
+
readonly info: 'info'
|
|
20
|
+
readonly warn: 'warn'
|
|
21
|
+
}
|
|
22
|
+
export type StatusType = (typeof StatusType)[keyof typeof StatusType]
|
|
23
|
+
export declare const HandlerType: {
|
|
24
|
+
readonly console: 'console'
|
|
25
|
+
readonly http: 'http'
|
|
26
|
+
readonly silent: 'silent'
|
|
27
|
+
}
|
|
28
|
+
export type HandlerType = (typeof HandlerType)[keyof typeof HandlerType]
|
|
29
|
+
export declare const STATUSES: StatusType[]
|
|
30
|
+
export interface LoggerConfiguration {
|
|
31
|
+
level?: StatusType
|
|
32
|
+
handler?: HandlerType | HandlerType[]
|
|
33
|
+
context?: object
|
|
34
|
+
}
|
|
35
|
+
export declare class Logger {
|
|
36
|
+
private handleLogStrategy
|
|
37
|
+
private handlerType
|
|
38
|
+
private level
|
|
39
|
+
private contextManager
|
|
40
|
+
constructor(
|
|
41
|
+
handleLogStrategy: (
|
|
42
|
+
logsMessage: LogsMessage,
|
|
43
|
+
logger: Logger,
|
|
44
|
+
savedCommonContext?: CommonContext,
|
|
45
|
+
savedDate?: TimeStamp
|
|
46
|
+
) => void,
|
|
47
|
+
name?: string,
|
|
48
|
+
handlerType?: HandlerType | HandlerType[],
|
|
49
|
+
level?: StatusType,
|
|
50
|
+
loggerContext?: object
|
|
51
|
+
)
|
|
52
|
+
log(
|
|
53
|
+
message: string,
|
|
54
|
+
messageContext?: object,
|
|
55
|
+
status?: StatusType,
|
|
56
|
+
error?: Error
|
|
57
|
+
): void
|
|
58
|
+
debug(message: string, messageContext?: object, error?: Error): void
|
|
59
|
+
info(message: string, messageContext?: object, error?: Error): void
|
|
60
|
+
warn(message: string, messageContext?: object, error?: Error): void
|
|
61
|
+
error(message: string, messageContext?: object, error?: Error): void
|
|
62
|
+
setContext(context: object): void
|
|
63
|
+
getContext(): Context
|
|
64
|
+
addContext(key: string, value: any): void
|
|
65
|
+
removeContext(key: string): void
|
|
66
|
+
clearContext(): void
|
|
67
|
+
setHandler(handler: HandlerType | HandlerType[]): void
|
|
68
|
+
getHandler(): HandlerType | HandlerType[]
|
|
69
|
+
setLevel(level: StatusType): void
|
|
70
|
+
getLevel(): StatusType
|
|
71
|
+
}
|