@cloudcare/browser-logs 3.1.23 → 3.2.0
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/logsPublicApi.js +35 -62
- package/cjs/boot/logsPublicApi.js.map +1 -1
- package/cjs/boot/preStartLogs.js +72 -0
- package/cjs/boot/preStartLogs.js.map +1 -0
- package/cjs/boot/startLogs.js +57 -38
- package/cjs/boot/startLogs.js.map +1 -1
- package/cjs/domain/assembly.js +5 -7
- package/cjs/domain/assembly.js.map +1 -1
- package/cjs/domain/contexts/commonContext.js +17 -0
- package/cjs/domain/contexts/commonContext.js.map +1 -0
- package/cjs/domain/contexts/internalContext.js.map +1 -0
- package/cjs/domain/createErrorFieldFromRawError.js +20 -0
- package/cjs/domain/createErrorFieldFromRawError.js.map +1 -0
- package/cjs/domain/logger.js +61 -54
- package/cjs/domain/logger.js.map +1 -1
- package/cjs/domain/logsCollection/console/consoleCollection.js +5 -5
- package/cjs/domain/logsCollection/console/consoleCollection.js.map +1 -1
- package/cjs/domain/logsCollection/logger/loggerCollection.js +37 -20
- package/cjs/domain/logsCollection/logger/loggerCollection.js.map +1 -1
- package/cjs/domain/logsCollection/networkError/networkErrorCollection.js +11 -6
- package/cjs/domain/logsCollection/networkError/networkErrorCollection.js.map +1 -1
- package/cjs/domain/logsCollection/report/reportCollection.js +6 -15
- package/cjs/domain/logsCollection/report/reportCollection.js.map +1 -1
- package/cjs/domain/logsCollection/rumtimeError/runtimeErrorCollection.js +2 -5
- package/cjs/domain/logsCollection/rumtimeError/runtimeErrorCollection.js.map +1 -1
- package/cjs/domain/reportError.js +24 -0
- package/cjs/domain/reportError.js.map +1 -0
- package/cjs/transport/startLogsBatch.js +6 -2
- package/cjs/transport/startLogsBatch.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/logsPublicApi.js +36 -63
- package/esm/boot/logsPublicApi.js.map +1 -1
- package/esm/boot/preStartLogs.js +66 -0
- package/esm/boot/preStartLogs.js.map +1 -0
- package/esm/boot/startLogs.js +57 -38
- package/esm/boot/startLogs.js.map +1 -1
- package/esm/domain/assembly.js +6 -8
- package/esm/domain/assembly.js.map +1 -1
- package/esm/domain/contexts/commonContext.js +11 -0
- package/esm/domain/contexts/commonContext.js.map +1 -0
- package/esm/domain/contexts/internalContext.js.map +1 -0
- package/esm/domain/createErrorFieldFromRawError.js +14 -0
- package/esm/domain/createErrorFieldFromRawError.js.map +1 -0
- package/esm/domain/logger.js +62 -55
- package/esm/domain/logger.js.map +1 -1
- package/esm/domain/logsCollection/console/consoleCollection.js +5 -5
- package/esm/domain/logsCollection/console/consoleCollection.js.map +1 -1
- package/esm/domain/logsCollection/logger/loggerCollection.js +39 -22
- package/esm/domain/logsCollection/logger/loggerCollection.js.map +1 -1
- package/esm/domain/logsCollection/networkError/networkErrorCollection.js +12 -7
- package/esm/domain/logsCollection/networkError/networkErrorCollection.js.map +1 -1
- package/esm/domain/logsCollection/report/reportCollection.js +7 -16
- package/esm/domain/logsCollection/report/reportCollection.js.map +1 -1
- package/esm/domain/logsCollection/rumtimeError/runtimeErrorCollection.js +2 -5
- package/esm/domain/logsCollection/rumtimeError/runtimeErrorCollection.js.map +1 -1
- package/esm/domain/reportError.js +18 -0
- package/esm/domain/reportError.js.map +1 -0
- package/esm/transport/startLogsBatch.js +7 -3
- package/esm/transport/startLogsBatch.js.map +1 -1
- package/package.json +4 -3
- package/src/boot/logsPublicApi.js +52 -86
- package/src/boot/preStartLogs.js +94 -0
- package/src/boot/startLogs.js +83 -60
- package/src/domain/assembly.js +7 -12
- package/src/domain/contexts/commonContext.js +10 -0
- package/src/domain/createErrorFieldFromRawError.js +13 -0
- package/src/domain/logger.js +89 -63
- package/src/domain/logsCollection/console/consoleCollection.js +5 -9
- package/src/domain/logsCollection/logger/loggerCollection.js +46 -25
- package/src/domain/logsCollection/networkError/networkErrorCollection.js +11 -7
- package/src/domain/logsCollection/report/reportCollection.js +9 -16
- package/src/domain/logsCollection/rumtimeError/runtimeErrorCollection.js +2 -6
- package/src/domain/reportError.js +21 -0
- package/src/transport/startLogsBatch.js +6 -4
- package/types/configuration.d.ts +2 -2
- package/types/logger.d.ts +3 -22
- package/cjs/domain/internalContext.js.map +0 -1
- package/esm/domain/internalContext.js.map +0 -1
- /package/cjs/domain/{internalContext.js → contexts/internalContext.js} +0 -0
- /package/esm/domain/{internalContext.js → contexts/internalContext.js} +0 -0
- /package/src/domain/{internalContext.js → contexts/internalContext.js} +0 -0
package/src/domain/logger.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
assign,
|
|
3
2
|
extend2Lev,
|
|
4
3
|
createContextManager,
|
|
5
4
|
ErrorSource,
|
|
@@ -11,15 +10,21 @@ import {
|
|
|
11
10
|
clocksNow,
|
|
12
11
|
ErrorHandling,
|
|
13
12
|
monitor,
|
|
14
|
-
NonErrorPrefix
|
|
13
|
+
NonErrorPrefix,
|
|
14
|
+
createHandlingStack
|
|
15
15
|
} from '@cloudcare/browser-core'
|
|
16
|
-
|
|
16
|
+
import { isAuthorized } from './logsCollection/logger/loggerCollection'
|
|
17
|
+
import { createErrorFieldFromRawError } from './createErrorFieldFromRawError'
|
|
17
18
|
export var StatusType = {
|
|
19
|
+
ok: 'ok',
|
|
18
20
|
debug: 'debug',
|
|
19
|
-
error: 'error',
|
|
20
21
|
info: 'info',
|
|
22
|
+
notice: 'notice',
|
|
21
23
|
warn: 'warn',
|
|
22
|
-
|
|
24
|
+
error: 'error',
|
|
25
|
+
critical: 'critical',
|
|
26
|
+
alert: 'alert',
|
|
27
|
+
emerg: 'emerg'
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
export var HandlerType = {
|
|
@@ -37,7 +42,6 @@ export function Logger(
|
|
|
37
42
|
level,
|
|
38
43
|
loggerContext
|
|
39
44
|
) {
|
|
40
|
-
this.contextManager = createContextManager(CustomerDataType.LoggerContext)
|
|
41
45
|
if (typeof handlerType === 'undefined') {
|
|
42
46
|
handlerType = HandlerType.http
|
|
43
47
|
}
|
|
@@ -47,96 +51,93 @@ export function Logger(
|
|
|
47
51
|
if (typeof loggerContext === 'undefined') {
|
|
48
52
|
loggerContext = {}
|
|
49
53
|
}
|
|
54
|
+
this.contextManager = createContextManager(CustomerDataType.LoggerContext)
|
|
50
55
|
this.handleLogStrategy = handleLogStrategy
|
|
51
56
|
this.handlerType = handlerType
|
|
52
57
|
this.level = level
|
|
53
|
-
this.contextManager.
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
this.contextManager.setContext(loggerContext)
|
|
59
|
+
if (name) {
|
|
60
|
+
this.contextManager.setContextProperty('logger', { name: name })
|
|
61
|
+
}
|
|
56
62
|
}
|
|
57
63
|
Logger.prototype = {
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
logImplementation: monitor(function (
|
|
65
|
+
message,
|
|
66
|
+
messageContext,
|
|
67
|
+
status,
|
|
68
|
+
error,
|
|
69
|
+
handlingStack
|
|
70
|
+
) {
|
|
71
|
+
if (status === undefined) {
|
|
60
72
|
status = StatusType.info
|
|
61
73
|
}
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
errorContext = { origin: ErrorSource.LOGGER }
|
|
66
|
-
}
|
|
74
|
+
var sanitizedMessageContext = sanitize(messageContext)
|
|
75
|
+
var context
|
|
76
|
+
|
|
67
77
|
if (error !== undefined && error !== null) {
|
|
68
|
-
var stackTrace =
|
|
69
|
-
error instanceof Error ? computeStackTrace(error) : undefined
|
|
70
78
|
var rawError = computeRawError({
|
|
71
|
-
stackTrace:
|
|
79
|
+
stackTrace:
|
|
80
|
+
error instanceof Error ? computeStackTrace(error) : undefined,
|
|
72
81
|
originalError: error,
|
|
73
82
|
nonErrorPrefix: NonErrorPrefix.PROVIDED,
|
|
74
83
|
source: ErrorSource.LOGGER,
|
|
75
84
|
handling: ErrorHandling.HANDLED,
|
|
76
85
|
startClocks: clocksNow()
|
|
77
86
|
})
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
context = extend2Lev(
|
|
88
|
+
{
|
|
89
|
+
error: createErrorFieldFromRawError(rawError, {
|
|
90
|
+
includeMessage: true
|
|
91
|
+
})
|
|
92
|
+
},
|
|
93
|
+
sanitizedMessageContext
|
|
94
|
+
)
|
|
95
|
+
} else {
|
|
96
|
+
context = sanitizedMessageContext
|
|
86
97
|
}
|
|
87
98
|
|
|
88
|
-
var sanitizedMessageContext = sanitize(messageContext)
|
|
89
|
-
|
|
90
|
-
var context = errorContext
|
|
91
|
-
? extend2Lev({ error: errorContext }, sanitizedMessageContext)
|
|
92
|
-
: sanitizedMessageContext
|
|
93
|
-
|
|
94
99
|
this.handleLogStrategy(
|
|
95
|
-
{
|
|
96
|
-
|
|
100
|
+
{
|
|
101
|
+
message: sanitize(message),
|
|
102
|
+
context: context,
|
|
103
|
+
status: status
|
|
104
|
+
},
|
|
105
|
+
this,
|
|
106
|
+
handlingStack
|
|
97
107
|
)
|
|
98
108
|
}),
|
|
109
|
+
log: function (message, messageContext, status, error) {
|
|
110
|
+
var handlingStack
|
|
99
111
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
info: function (message, messageContext, error) {
|
|
105
|
-
this.log(message, messageContext, StatusType.info, error)
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
warn: function (message, messageContext, error) {
|
|
109
|
-
this.log(message, messageContext, StatusType.warn, error)
|
|
110
|
-
},
|
|
111
|
-
critical: function (message, messageContext, error) {
|
|
112
|
-
this.log(message, messageContext, StatusType.critical, error)
|
|
113
|
-
},
|
|
114
|
-
error: function (message, messageContext, error) {
|
|
115
|
-
var errorOrigin = {
|
|
116
|
-
error: {
|
|
117
|
-
origin: ErrorSource.LOGGER
|
|
118
|
-
}
|
|
112
|
+
if (isAuthorized(status, HandlerType.http, this)) {
|
|
113
|
+
handlingStack = createHandlingStack()
|
|
119
114
|
}
|
|
120
|
-
|
|
115
|
+
|
|
116
|
+
this.logImplementation(
|
|
121
117
|
message,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
error
|
|
118
|
+
messageContext,
|
|
119
|
+
status,
|
|
120
|
+
error,
|
|
121
|
+
handlingStack
|
|
125
122
|
)
|
|
126
123
|
},
|
|
127
124
|
|
|
128
125
|
setContext: function (context) {
|
|
129
|
-
this.contextManager.
|
|
126
|
+
this.contextManager.setContext(context)
|
|
130
127
|
},
|
|
131
128
|
|
|
132
129
|
getContext: function () {
|
|
133
|
-
return this.contextManager.
|
|
130
|
+
return this.contextManager.getContext()
|
|
131
|
+
},
|
|
132
|
+
setContextProperty: function (key, value) {
|
|
133
|
+
this.contextManager.setContextProperty(key, value)
|
|
134
134
|
},
|
|
135
|
-
|
|
136
135
|
addContext: function (key, value) {
|
|
137
|
-
this.contextManager.
|
|
136
|
+
this.contextManager.setContextProperty(key, value)
|
|
137
|
+
},
|
|
138
|
+
removeContextProperty(key) {
|
|
139
|
+
this.contextManager.removeContextProperty(key)
|
|
138
140
|
},
|
|
139
|
-
|
|
140
141
|
removeContext: function (key) {
|
|
141
142
|
this.contextManager.remove(key)
|
|
142
143
|
},
|
|
@@ -157,3 +158,28 @@ Logger.prototype = {
|
|
|
157
158
|
return this.level
|
|
158
159
|
}
|
|
159
160
|
}
|
|
161
|
+
Logger.prototype.ok = createLoggerMethod(StatusType.ok)
|
|
162
|
+
Logger.prototype.debug = createLoggerMethod(StatusType.debug)
|
|
163
|
+
Logger.prototype.info = createLoggerMethod(StatusType.info)
|
|
164
|
+
Logger.prototype.notice = createLoggerMethod(StatusType.notice)
|
|
165
|
+
Logger.prototype.warn = createLoggerMethod(StatusType.warn)
|
|
166
|
+
Logger.prototype.error = createLoggerMethod(StatusType.error)
|
|
167
|
+
Logger.prototype.critical = createLoggerMethod(StatusType.critical)
|
|
168
|
+
Logger.prototype.alert = createLoggerMethod(StatusType.alert)
|
|
169
|
+
Logger.prototype.emerg = createLoggerMethod(StatusType.emerg)
|
|
170
|
+
function createLoggerMethod(status) {
|
|
171
|
+
return function (message, messageContext, error) {
|
|
172
|
+
var handlingStack
|
|
173
|
+
|
|
174
|
+
if (isAuthorized(status, HandlerType.http, this)) {
|
|
175
|
+
handlingStack = createHandlingStack()
|
|
176
|
+
}
|
|
177
|
+
this.logImplementation(
|
|
178
|
+
message,
|
|
179
|
+
messageContext,
|
|
180
|
+
status,
|
|
181
|
+
error,
|
|
182
|
+
handlingStack
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
LifeCycleEventType
|
|
7
7
|
} from '@cloudcare/browser-core'
|
|
8
8
|
import { StatusType } from '../../logger'
|
|
9
|
-
|
|
9
|
+
import { createErrorFieldFromRawError } from '../../createErrorFieldFromRawError'
|
|
10
10
|
var LogStatusForApi = {
|
|
11
11
|
[ConsoleApiName.log]: StatusType.info,
|
|
12
12
|
[ConsoleApiName.debug]: StatusType.debug,
|
|
@@ -23,15 +23,11 @@ export function startConsoleCollection(configuration, lifeCycle) {
|
|
|
23
23
|
date: timeStampNow(),
|
|
24
24
|
message: log.message,
|
|
25
25
|
origin: ErrorSource.CONSOLE,
|
|
26
|
-
error:
|
|
27
|
-
log.api === ConsoleApiName.error
|
|
28
|
-
? {
|
|
29
|
-
origin: ErrorSource.CONSOLE,
|
|
30
|
-
stack: log.stack,
|
|
31
|
-
causes: log.causes
|
|
32
|
-
}
|
|
33
|
-
: undefined,
|
|
26
|
+
error: log.error && createErrorFieldFromRawError(log.error),
|
|
34
27
|
status: LogStatusForApi[log.api]
|
|
28
|
+
},
|
|
29
|
+
domainContext: {
|
|
30
|
+
handlingStack: log.handlingStack
|
|
35
31
|
}
|
|
36
32
|
})
|
|
37
33
|
})
|
|
@@ -1,42 +1,54 @@
|
|
|
1
1
|
import {
|
|
2
2
|
includes,
|
|
3
|
-
display,
|
|
4
3
|
extend2Lev,
|
|
5
4
|
ErrorSource,
|
|
6
5
|
timeStampNow,
|
|
7
6
|
LifeCycleEventType,
|
|
8
|
-
isArray
|
|
7
|
+
isArray,
|
|
8
|
+
originalConsoleMethods
|
|
9
9
|
} from '@cloudcare/browser-core'
|
|
10
|
-
import {
|
|
10
|
+
import { HandlerType } from '../../logger'
|
|
11
11
|
|
|
12
12
|
export var STATUS_PRIORITIES = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
ok: 0,
|
|
14
|
+
debug: 1,
|
|
15
|
+
info: 2,
|
|
16
|
+
notice: 4,
|
|
17
|
+
warn: 5,
|
|
18
|
+
error: 6,
|
|
19
|
+
critical: 7,
|
|
20
|
+
alert: 8,
|
|
21
|
+
emerg: 9
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
export function startLoggerCollection(lifeCycle) {
|
|
20
|
-
function handleLog(
|
|
21
|
-
|
|
25
|
+
function handleLog(
|
|
26
|
+
logsMessage,
|
|
27
|
+
logger,
|
|
28
|
+
handlingStack,
|
|
29
|
+
savedCommonContext,
|
|
30
|
+
savedDate
|
|
31
|
+
) {
|
|
32
|
+
var messageContext = extend2Lev(logger.getContext(), logsMessage.context)
|
|
22
33
|
if (isAuthorized(logsMessage.status, HandlerType.console, logger)) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
displayInConsole(logsMessage, messageContext)
|
|
35
|
+
}
|
|
36
|
+
if (isAuthorized(logsMessage.status, HandlerType.http, logger)) {
|
|
37
|
+
var rawLogEventData = {
|
|
38
|
+
rawLogsEvent: {
|
|
39
|
+
date: savedDate || timeStampNow(),
|
|
40
|
+
message: logsMessage.message,
|
|
41
|
+
status: logsMessage.status,
|
|
42
|
+
origin: ErrorSource.LOGGER
|
|
43
|
+
},
|
|
44
|
+
messageContext: messageContext,
|
|
45
|
+
savedCommonContext: savedCommonContext
|
|
46
|
+
}
|
|
47
|
+
if (handlingStack) {
|
|
48
|
+
rawLogEventData.domainContext = { handlingStack }
|
|
49
|
+
}
|
|
50
|
+
lifeCycle.notify(LifeCycleEventType.RAW_LOG_COLLECTED, rawLogEventData)
|
|
28
51
|
}
|
|
29
|
-
lifeCycle.notify(LifeCycleEventType.RAW_LOG_COLLECTED, {
|
|
30
|
-
rawLogsEvent: {
|
|
31
|
-
date: savedDate || timeStampNow(),
|
|
32
|
-
message: logsMessage.message,
|
|
33
|
-
status: logsMessage.status,
|
|
34
|
-
origin: ErrorSource.LOGGER
|
|
35
|
-
},
|
|
36
|
-
messageContext: messageContext,
|
|
37
|
-
savedCommonContext: savedCommonContext,
|
|
38
|
-
logger: logger
|
|
39
|
-
})
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
return {
|
|
@@ -54,3 +66,12 @@ export function isAuthorized(status, handlerType, logger) {
|
|
|
54
66
|
includes(sanitizedHandlerType, handlerType)
|
|
55
67
|
)
|
|
56
68
|
}
|
|
69
|
+
function displayInConsole(data, messageContext) {
|
|
70
|
+
var status = data.status
|
|
71
|
+
var message = data.message
|
|
72
|
+
originalConsoleMethods[loggerToConsoleApiName[status]].call(
|
|
73
|
+
globalConsole,
|
|
74
|
+
message,
|
|
75
|
+
messageContext
|
|
76
|
+
)
|
|
77
|
+
}
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
computeStackTrace,
|
|
7
7
|
toStackTraceString,
|
|
8
8
|
noop,
|
|
9
|
-
each,
|
|
10
9
|
LifeCycleEventType,
|
|
11
10
|
getStatusGroup,
|
|
12
11
|
urlParse,
|
|
@@ -25,16 +24,16 @@ export function startNetworkErrorCollection(configuration, lifeCycle) {
|
|
|
25
24
|
|
|
26
25
|
var xhrSubscription = initXhrObservable().subscribe(function (context) {
|
|
27
26
|
if (context.state === 'complete') {
|
|
28
|
-
|
|
27
|
+
handleResponse(RequestType.XHR, context)
|
|
29
28
|
}
|
|
30
29
|
})
|
|
31
30
|
var fetchSubscription = initFetchObservable().subscribe(function (context) {
|
|
32
31
|
if (context.state === 'resolve') {
|
|
33
|
-
|
|
32
|
+
handleResponse(RequestType.FETCH, context)
|
|
34
33
|
}
|
|
35
34
|
})
|
|
36
35
|
|
|
37
|
-
function
|
|
36
|
+
function handleResponse(type, request) {
|
|
38
37
|
if (
|
|
39
38
|
!isIntakeRequest(request.url, configuration) &&
|
|
40
39
|
(isRejected(request) ||
|
|
@@ -63,6 +62,10 @@ export function startNetworkErrorCollection(configuration, lifeCycle) {
|
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
function onResponseDataAvailable(responseData) {
|
|
65
|
+
var domainContext = {
|
|
66
|
+
isAborted: request.isAborted,
|
|
67
|
+
handlingStack: request.handlingStack
|
|
68
|
+
}
|
|
66
69
|
var urlObj = urlParse(request.url).getParse()
|
|
67
70
|
lifeCycle.notify(LifeCycleEventType.RAW_LOG_COLLECTED, {
|
|
68
71
|
rawLogsEvent: {
|
|
@@ -70,8 +73,8 @@ export function startNetworkErrorCollection(configuration, lifeCycle) {
|
|
|
70
73
|
format(type) + ' error ' + request.method + ' ' + request.url,
|
|
71
74
|
date: request.startClocks.timeStamp,
|
|
72
75
|
error: {
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
stack: responseData || 'Failed to load',
|
|
77
|
+
handing: undefined
|
|
75
78
|
},
|
|
76
79
|
http: {
|
|
77
80
|
method: request.method,
|
|
@@ -84,7 +87,8 @@ export function startNetworkErrorCollection(configuration, lifeCycle) {
|
|
|
84
87
|
},
|
|
85
88
|
status: StatusType.error,
|
|
86
89
|
origin: ErrorSource.NETWORK
|
|
87
|
-
}
|
|
90
|
+
},
|
|
91
|
+
domainContext: domainContext
|
|
88
92
|
})
|
|
89
93
|
}
|
|
90
94
|
}
|
|
@@ -1,35 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
timeStampNow,
|
|
3
3
|
ErrorSource,
|
|
4
|
-
RawReportType,
|
|
5
4
|
getFileFromStackTraceString,
|
|
6
5
|
initReportObservable,
|
|
7
6
|
LifeCycleEventType
|
|
8
7
|
} from '@cloudcare/browser-core'
|
|
9
8
|
import { StatusType } from '../../logger'
|
|
10
|
-
|
|
11
|
-
var LogStatusForReport = {
|
|
12
|
-
[RawReportType.cspViolation]: StatusType.error,
|
|
13
|
-
[RawReportType.intervention]: StatusType.error,
|
|
14
|
-
[RawReportType.deprecation]: StatusType.warn
|
|
15
|
-
}
|
|
9
|
+
import { createErrorFieldFromRawError } from '../../createErrorFieldFromRawError'
|
|
16
10
|
|
|
17
11
|
export function startReportCollection(configuration, lifeCycle) {
|
|
18
12
|
var reportSubscription = initReportObservable(
|
|
19
13
|
configuration,
|
|
20
14
|
configuration.forwardReports
|
|
21
|
-
).subscribe(function (
|
|
22
|
-
var message =
|
|
23
|
-
var status =
|
|
15
|
+
).subscribe(function (rawError) {
|
|
16
|
+
var message = rawError.message
|
|
17
|
+
var status =
|
|
18
|
+
rawError.originalError.type === 'deprecation'
|
|
19
|
+
? StatusType.warn
|
|
20
|
+
: StatusType.error
|
|
24
21
|
var error
|
|
25
22
|
if (status === StatusType.error) {
|
|
26
|
-
error =
|
|
27
|
-
kind: report.subtype,
|
|
28
|
-
origin: ErrorSource.REPORT,
|
|
29
|
-
stack: report.stack
|
|
30
|
-
}
|
|
23
|
+
error = createErrorFieldFromRawError(rawError)
|
|
31
24
|
} else if (report.stack) {
|
|
32
|
-
message += ' Found in ' + getFileFromStackTraceString(
|
|
25
|
+
message += ' Found in ' + getFileFromStackTraceString(rawError.stack)
|
|
33
26
|
}
|
|
34
27
|
|
|
35
28
|
lifeCycle.notify(LifeCycleEventType.RAW_LOG_COLLECTED, {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
LifeCycleEventType
|
|
7
7
|
} from '@cloudcare/browser-core'
|
|
8
8
|
import { StatusType } from '../../logger'
|
|
9
|
-
|
|
9
|
+
import { createErrorFieldFromRawError } from '../../createErrorFieldFromRawError'
|
|
10
10
|
export function startRuntimeErrorCollection(configuration, lifeCycle) {
|
|
11
11
|
if (!configuration.forwardErrorsToLogs) {
|
|
12
12
|
return { stop: noop }
|
|
@@ -21,11 +21,7 @@ export function startRuntimeErrorCollection(configuration, lifeCycle) {
|
|
|
21
21
|
rawLogsEvent: {
|
|
22
22
|
message: rawError.message,
|
|
23
23
|
date: rawError.startClocks.timeStamp,
|
|
24
|
-
error:
|
|
25
|
-
kind: rawError.type,
|
|
26
|
-
stack: rawError.stack,
|
|
27
|
-
causes: rawError.causes
|
|
28
|
-
},
|
|
24
|
+
error: createErrorFieldFromRawError(rawError),
|
|
29
25
|
origin: ErrorSource.SOURCE,
|
|
30
26
|
status: StatusType.error
|
|
31
27
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ErrorSource,
|
|
3
|
+
LifeCycleEventType,
|
|
4
|
+
addTelemetryDebug
|
|
5
|
+
} from '@cloudcare/browser-core'
|
|
6
|
+
import { StatusType } from './logger'
|
|
7
|
+
export function startReportError(lifeCycle) {
|
|
8
|
+
return function (error) {
|
|
9
|
+
lifeCycle.notify(LifeCycleEventType.RAW_LOG_COLLECTED, {
|
|
10
|
+
rawLogsEvent: {
|
|
11
|
+
message: error.message,
|
|
12
|
+
date: error.startClocks.timeStamp,
|
|
13
|
+
origin: ErrorSource.AGENT,
|
|
14
|
+
status: StatusType.error
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
addTelemetryDebug('Error reported to customer', {
|
|
18
|
+
'error.message': error.message
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
startBatchWithReplica,
|
|
3
|
-
LifeCycleEventType
|
|
3
|
+
LifeCycleEventType,
|
|
4
|
+
createIdentityEncoder
|
|
4
5
|
} from '@cloudcare/browser-core'
|
|
5
6
|
|
|
6
7
|
export function startLogsBatch(
|
|
@@ -8,14 +9,14 @@ export function startLogsBatch(
|
|
|
8
9
|
lifeCycle,
|
|
9
10
|
reportError,
|
|
10
11
|
pageExitObservable,
|
|
11
|
-
|
|
12
|
+
session
|
|
12
13
|
) {
|
|
13
14
|
var batch = startBatchWithReplica(
|
|
14
15
|
configuration,
|
|
15
|
-
configuration.logsEndpoint,
|
|
16
|
+
{ endpoint: configuration.logsEndpoint, encoder: createIdentityEncoder() },
|
|
16
17
|
reportError,
|
|
17
18
|
pageExitObservable,
|
|
18
|
-
|
|
19
|
+
session.expireObservable
|
|
19
20
|
)
|
|
20
21
|
|
|
21
22
|
lifeCycle.subscribe(
|
|
@@ -24,4 +25,5 @@ export function startLogsBatch(
|
|
|
24
25
|
batch.add(serverLogsEvent)
|
|
25
26
|
}
|
|
26
27
|
)
|
|
28
|
+
return batch
|
|
27
29
|
}
|
package/types/configuration.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ import type {
|
|
|
7
7
|
} from '@cloudcare/browser-core'
|
|
8
8
|
export interface LogsBaseInitConfiguration extends InitConfiguration {
|
|
9
9
|
forwardErrorsToLogs?: boolean | undefined
|
|
10
|
-
forwardConsoleLogs?: ConsoleApiName[] |
|
|
11
|
-
forwardReports?: RawReportType[] |
|
|
10
|
+
forwardConsoleLogs?: ConsoleApiName[] | undefined
|
|
11
|
+
forwardReports?: RawReportType[] | undefined
|
|
12
12
|
requestErrorResponseLengthLimit?: number
|
|
13
13
|
}
|
|
14
14
|
|
package/types/logger.d.ts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
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
2
|
export interface LogsMessage {
|
|
11
3
|
message: string
|
|
12
4
|
status: StatusType
|
|
13
5
|
context?: Context
|
|
14
6
|
}
|
|
15
|
-
export type TimeStamp = number & { t: 'Epoch time' }
|
|
16
7
|
export declare const StatusType: {
|
|
17
8
|
readonly debug: 'debug'
|
|
18
9
|
readonly error: 'error'
|
|
@@ -27,23 +18,13 @@ export declare const HandlerType: {
|
|
|
27
18
|
}
|
|
28
19
|
export type HandlerType = (typeof HandlerType)[keyof typeof HandlerType]
|
|
29
20
|
export declare const STATUSES: StatusType[]
|
|
30
|
-
export interface LoggerConfiguration {
|
|
31
|
-
level?: StatusType
|
|
32
|
-
handler?: HandlerType | HandlerType[]
|
|
33
|
-
context?: object
|
|
34
|
-
}
|
|
35
21
|
export declare class Logger {
|
|
36
22
|
private handleLogStrategy
|
|
37
23
|
private handlerType
|
|
38
24
|
private level
|
|
39
25
|
private contextManager
|
|
40
26
|
constructor(
|
|
41
|
-
handleLogStrategy: (
|
|
42
|
-
logsMessage: LogsMessage,
|
|
43
|
-
logger: Logger,
|
|
44
|
-
savedCommonContext?: CommonContext,
|
|
45
|
-
savedDate?: TimeStamp
|
|
46
|
-
) => void,
|
|
27
|
+
handleLogStrategy: (logsMessage: LogsMessage, logger: Logger) => void,
|
|
47
28
|
name?: string,
|
|
48
29
|
handlerType?: HandlerType | HandlerType[],
|
|
49
30
|
level?: StatusType,
|
|
@@ -61,8 +42,8 @@ export declare class Logger {
|
|
|
61
42
|
error(message: string, messageContext?: object, error?: Error): void
|
|
62
43
|
setContext(context: object): void
|
|
63
44
|
getContext(): Context
|
|
64
|
-
|
|
65
|
-
|
|
45
|
+
setContextProperty(key: string, value: any): void
|
|
46
|
+
removeContextProperty(key: string): void
|
|
66
47
|
clearContext(): void
|
|
67
48
|
setHandler(handler: HandlerType | HandlerType[]): void
|
|
68
49
|
getHandler(): HandlerType | HandlerType[]
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internalContext.js","names":["startInternalContext","sessionManager","get","startTime","trackedSession","findTrackedSession","session","id"],"sources":["../../src/domain/internalContext.js"],"sourcesContent":["\nexport function startInternalContext(sessionManager) {\n return {\n get: function(startTime) {\n var trackedSession = sessionManager.findTrackedSession(startTime)\n if (trackedSession) {\n return {\n session: {\n id: trackedSession.id\n },\n }\n }\n },\n }\n}\n"],"mappings":";;;;;;AACO,SAASA,oBAAoBA,CAACC,cAAc,EAAE;EACnD,OAAO;IACLC,GAAG,EAAE,SAAAA,IAASC,SAAS,EAAE;MACvB,IAAIC,cAAc,GAAGH,cAAc,CAACI,kBAAkB,CAACF,SAAS,CAAC;MACjE,IAAIC,cAAc,EAAE;QAClB,OAAO;UACLE,OAAO,EAAE;YACPC,EAAE,EAAEH,cAAc,CAACG;UACrB;QACF,CAAC;MACH;IACF;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internalContext.js","names":["startInternalContext","sessionManager","get","startTime","trackedSession","findTrackedSession","session","id"],"sources":["../../src/domain/internalContext.js"],"sourcesContent":["\nexport function startInternalContext(sessionManager) {\n return {\n get: function(startTime) {\n var trackedSession = sessionManager.findTrackedSession(startTime)\n if (trackedSession) {\n return {\n session: {\n id: trackedSession.id\n },\n }\n }\n },\n }\n}\n"],"mappings":"AACA,OAAO,SAASA,oBAAoBA,CAACC,cAAc,EAAE;EACnD,OAAO;IACLC,GAAG,EAAE,SAAAA,IAASC,SAAS,EAAE;MACvB,IAAIC,cAAc,GAAGH,cAAc,CAACI,kBAAkB,CAACF,SAAS,CAAC;MACjE,IAAIC,cAAc,EAAE;QAClB,OAAO;UACLE,OAAO,EAAE;YACPC,EAAE,EAAEH,cAAc,CAACG;UACrB;QACF,CAAC;MACH;IACF;EACF,CAAC;AACH","ignoreList":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|