@cloudcare/browser-logs 2.0.4 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/dataflux-logs.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/logsPublicApi.js +16 -6
- package/cjs/boot/startLogs.js +4 -4
- package/cjs/domain/assembly.js +3 -2
- package/cjs/domain/logger.js +1 -1
- package/cjs/domain/logsSessionManager.js +14 -8
- package/cjs/transport/startLogsBatch.js +2 -2
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/logsPublicApi.js +17 -7
- package/esm/boot/startLogs.js +6 -6
- package/esm/domain/assembly.js +4 -3
- package/esm/domain/logger.js +2 -2
- package/esm/domain/logsSessionManager.js +14 -9
- package/esm/transport/startLogsBatch.js +2 -2
- package/package.json +30 -30
- package/src/boot/logsPublicApi.js +39 -21
- package/src/boot/startLogs.js +18 -6
- package/src/domain/assembly.js +59 -56
- package/src/domain/logger.js +41 -23
- package/src/domain/logsSessionManager.js +18 -9
- package/src/transport/startLogsBatch.js +4 -2
package/esm/domain/assembly.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ErrorSource, extend2Lev, createEventRateLimiter, getRelativeTime, withSnakeCaseKeys, LifeCycleEventType, deviceInfo, each, RumEventType, isNullUndefinedDefaultValue } from '@cloudcare/browser-core';
|
|
1
|
+
import { ErrorSource, extend2Lev, createEventRateLimiter, getRelativeTime, withSnakeCaseKeys, LifeCycleEventType, deviceInfo, each, RumEventType, isEmptyObject, isNullUndefinedDefaultValue } from '@cloudcare/browser-core';
|
|
2
2
|
import { STATUSES, HandlerType } from './logger';
|
|
3
3
|
import { isAuthorized } from './logsCollection/logger/loggerCollection';
|
|
4
|
-
export function startLogsAssembly(sessionManager, configuration, lifeCycle,
|
|
4
|
+
export function startLogsAssembly(sessionManager, configuration, lifeCycle, buildCommonContext, mainLogger, reportError) {
|
|
5
5
|
var statusWithCustom = STATUSES.concat(['custom']);
|
|
6
6
|
var logRateLimiters = {};
|
|
7
7
|
each(statusWithCustom, function (status) {
|
|
@@ -20,7 +20,7 @@ export function startLogsAssembly(sessionManager, configuration, lifeCycle, getC
|
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
var commonContext = savedCommonContext ||
|
|
23
|
+
var commonContext = savedCommonContext || buildCommonContext();
|
|
24
24
|
var log = extend2Lev({
|
|
25
25
|
service: configuration.service || 'browser',
|
|
26
26
|
env: configuration.env || '',
|
|
@@ -33,6 +33,7 @@ export function startLogsAssembly(sessionManager, configuration, lifeCycle, getC
|
|
|
33
33
|
id: session.id
|
|
34
34
|
},
|
|
35
35
|
view: commonContext.view,
|
|
36
|
+
user: !isEmptyObject(commonContext.user) ? commonContext.user : undefined,
|
|
36
37
|
device: deviceInfo,
|
|
37
38
|
type: RumEventType.LOGGER
|
|
38
39
|
}, commonContext.context, getRUMInternalContext(startTime), rawLogsEvent, logger.getContext(), messageContext);
|
package/esm/domain/logger.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { deepClone, assign, extend2Lev, createContextManager, ErrorSource, keys } from '@cloudcare/browser-core';
|
|
1
|
+
import { deepClone, assign, extend2Lev, createContextManager, ErrorSource, keys, CustomerDataType } from '@cloudcare/browser-core';
|
|
2
2
|
export var StatusType = {
|
|
3
3
|
debug: 'debug',
|
|
4
4
|
error: 'error',
|
|
@@ -14,7 +14,7 @@ export var HandlerType = {
|
|
|
14
14
|
export var STATUSES = keys(StatusType); // eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
15
15
|
|
|
16
16
|
export function Logger(handleLogStrategy, name, handlerType, level, loggerContext) {
|
|
17
|
-
this.contextManager = createContextManager();
|
|
17
|
+
this.contextManager = createContextManager(CustomerDataType.LoggerContext);
|
|
18
18
|
|
|
19
19
|
if (typeof handlerType === 'undefined') {
|
|
20
20
|
handlerType = HandlerType.http;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { performDraw, startSessionManager } from '@cloudcare/browser-core';
|
|
1
|
+
import { performDraw, startSessionManager, Observable } from '@cloudcare/browser-core';
|
|
2
2
|
export var LOGS_SESSION_KEY = 'logs';
|
|
3
3
|
export var LoggerTrackingType = {
|
|
4
4
|
NOT_TRACKED: '0',
|
|
@@ -14,15 +14,20 @@ export function startLogsSessionManager(configuration) {
|
|
|
14
14
|
return session && session.trackingType === LoggerTrackingType.TRACKED ? {
|
|
15
15
|
id: session.id
|
|
16
16
|
} : undefined;
|
|
17
|
-
}
|
|
17
|
+
},
|
|
18
|
+
expireObservable: sessionManager.expireObservable
|
|
18
19
|
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
}
|
|
21
|
+
export function startLogsSessionManagerStub(configuration) {
|
|
22
|
+
var isTracked = computeTrackingType(configuration) === LoggerTrackingType.TRACKED;
|
|
23
|
+
var session = isTracked ? {} : undefined;
|
|
24
|
+
return {
|
|
25
|
+
findTrackedSession: function findTrackedSession() {
|
|
26
|
+
return session;
|
|
27
|
+
},
|
|
28
|
+
expireObservable: new Observable()
|
|
29
|
+
};
|
|
30
|
+
}
|
|
26
31
|
|
|
27
32
|
function computeTrackingType(configuration) {
|
|
28
33
|
if (!performDraw(configuration.sessionSampleRate)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { startBatchWithReplica, LifeCycleEventType } from '@cloudcare/browser-core';
|
|
2
|
-
export function startLogsBatch(configuration, lifeCycle, reportError, pageExitObservable) {
|
|
3
|
-
var batch = startBatchWithReplica(configuration, configuration.logsEndpoint, reportError, pageExitObservable);
|
|
2
|
+
export function startLogsBatch(configuration, lifeCycle, reportError, pageExitObservable, sessionExpireObservable) {
|
|
3
|
+
var batch = startBatchWithReplica(configuration, configuration.logsEndpoint, reportError, pageExitObservable, sessionExpireObservable);
|
|
4
4
|
lifeCycle.subscribe(LifeCycleEventType.LOG_COLLECTED, function (serverLogsEvent) {
|
|
5
5
|
batch.add(serverLogsEvent);
|
|
6
6
|
});
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
"name": "@cloudcare/browser-logs",
|
|
3
|
+
"main": "cjs/index.js",
|
|
4
|
+
"module": "esm/index.js",
|
|
5
|
+
"version": "2.0.6",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@cloudcare/browser-core": "2.0.5"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "webpack serve --open --mode=development",
|
|
11
|
+
"build": "run-p build:cjs build:esm build:bundle",
|
|
12
|
+
"build:cjs": "rm -rf cjs && babel --config-file ./babel.cjs.json --out-dir cjs ./src && npm run replace-build-env cjs",
|
|
13
|
+
"build:esm": "rm -rf esm && babel --config-file ./babel.esm.json --out-dir esm ./src && npm run replace-build-env esm",
|
|
14
|
+
"build:bundle": "rm -rf bundle && webpack --config webpack.config.js --mode=production && npm run replace-build-env bundle ",
|
|
15
|
+
"publish:oss": "npm run build && node ./scripts/publish-oss.js",
|
|
16
|
+
"publish:oss:test": "npm run build && node ./scripts/publish-oss.js test",
|
|
17
|
+
"replace-build-env": "node scripts/replace-build-env.js"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"dataflux",
|
|
21
|
+
"logs",
|
|
22
|
+
"sdk"
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"url": "https://github.com/DataFlux-cn/datakit-js",
|
|
26
|
+
"type": "git"
|
|
27
|
+
},
|
|
28
|
+
"author": "dataflux",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"description": "DataFlux RUM Web 端数据指标监控",
|
|
31
|
+
"gitHead": "d73a29f283e62c5b13fe0b0f710b7e1e186267bc"
|
|
32
32
|
}
|
|
@@ -2,9 +2,12 @@ import {
|
|
|
2
2
|
BoundedBuffer,
|
|
3
3
|
createContextManager,
|
|
4
4
|
makePublicApi,
|
|
5
|
+
CustomerDataType,
|
|
5
6
|
display,
|
|
6
7
|
deepClone,
|
|
7
8
|
timeStampNow,
|
|
9
|
+
checkUser,
|
|
10
|
+
sanitizeUser
|
|
8
11
|
} from '@cloudcare/browser-core'
|
|
9
12
|
import { validateAndBuildLogsConfiguration } from '../domain/configuration'
|
|
10
13
|
import { Logger } from '../domain/logger'
|
|
@@ -12,53 +15,57 @@ import { Logger } from '../domain/logger'
|
|
|
12
15
|
export function makeLogsPublicApi(startLogsImpl) {
|
|
13
16
|
var isAlreadyInitialized = false
|
|
14
17
|
|
|
15
|
-
var globalContextManager = createContextManager(
|
|
18
|
+
var globalContextManager = createContextManager(
|
|
19
|
+
CustomerDataType.GlobalContext
|
|
20
|
+
)
|
|
21
|
+
var userContextManager = createContextManager(CustomerDataType.User)
|
|
16
22
|
var customLoggers = {}
|
|
17
|
-
var getInternalContextStrategy = function() {
|
|
23
|
+
var getInternalContextStrategy = function () {
|
|
18
24
|
return undefined
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
var beforeInitLoggerLog = new BoundedBuffer()
|
|
22
28
|
|
|
23
|
-
var handleLogStrategy = function(
|
|
29
|
+
var handleLogStrategy = function (
|
|
24
30
|
logsMessage,
|
|
25
31
|
logger,
|
|
26
32
|
savedCommonContext,
|
|
27
33
|
date
|
|
28
|
-
){
|
|
34
|
+
) {
|
|
29
35
|
if (typeof savedCommonContext === 'undefined') {
|
|
30
|
-
savedCommonContext = deepClone(
|
|
36
|
+
savedCommonContext = deepClone(buildCommonContext())
|
|
31
37
|
}
|
|
32
38
|
if (typeof date === 'undefined') {
|
|
33
39
|
date = timeStampNow()
|
|
34
40
|
}
|
|
35
|
-
beforeInitLoggerLog.add(function() {
|
|
41
|
+
beforeInitLoggerLog.add(function () {
|
|
36
42
|
return handleLogStrategy(logsMessage, logger, savedCommonContext, date)
|
|
37
43
|
})
|
|
38
44
|
}
|
|
39
45
|
|
|
40
|
-
var getInitConfigurationStrategy = function() {
|
|
46
|
+
var getInitConfigurationStrategy = function () {
|
|
41
47
|
return undefined
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
var mainLogger = new Logger(function() {
|
|
50
|
+
var mainLogger = new Logger(function () {
|
|
45
51
|
return handleLogStrategy.apply(this, arguments)
|
|
46
52
|
})
|
|
47
53
|
|
|
48
|
-
function
|
|
54
|
+
function buildCommonContext() {
|
|
49
55
|
return {
|
|
50
56
|
view: {
|
|
51
57
|
referrer: document.referrer,
|
|
52
|
-
url: window.location.href
|
|
58
|
+
url: window.location.href
|
|
53
59
|
},
|
|
54
|
-
context: globalContextManager.
|
|
60
|
+
context: globalContextManager.getContext(),
|
|
61
|
+
user: userContextManager.getContext()
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
return makePublicApi({
|
|
59
66
|
logger: mainLogger,
|
|
60
67
|
|
|
61
|
-
init: function(initConfiguration) {
|
|
68
|
+
init: function (initConfiguration) {
|
|
62
69
|
if (!canInitLogs(initConfiguration)) {
|
|
63
70
|
return
|
|
64
71
|
}
|
|
@@ -67,10 +74,14 @@ export function makeLogsPublicApi(startLogsImpl) {
|
|
|
67
74
|
if (!configuration) {
|
|
68
75
|
return
|
|
69
76
|
}
|
|
70
|
-
var _startLogsImpl = startLogsImpl(
|
|
77
|
+
var _startLogsImpl = startLogsImpl(
|
|
78
|
+
configuration,
|
|
79
|
+
buildCommonContext,
|
|
80
|
+
mainLogger
|
|
81
|
+
)
|
|
71
82
|
handleLogStrategy = _startLogsImpl.handleLog
|
|
72
83
|
getInternalContextStrategy = _startLogsImpl.getInternalContext
|
|
73
|
-
getInitConfigurationStrategy = function() {
|
|
84
|
+
getInitConfigurationStrategy = function () {
|
|
74
85
|
return deepClone(initConfiguration)
|
|
75
86
|
}
|
|
76
87
|
beforeInitLoggerLog.drain()
|
|
@@ -92,13 +103,13 @@ export function makeLogsPublicApi(startLogsImpl) {
|
|
|
92
103
|
|
|
93
104
|
clearGlobalContext: globalContextManager.clearContext,
|
|
94
105
|
|
|
95
|
-
createLogger: function(name, conf){
|
|
106
|
+
createLogger: function (name, conf) {
|
|
96
107
|
if (typeof conf == 'undefined') {
|
|
97
108
|
conf = {}
|
|
98
109
|
}
|
|
99
110
|
customLoggers[name] = new Logger(
|
|
100
|
-
function() {
|
|
101
|
-
return handleLogStrategy(this.
|
|
111
|
+
function () {
|
|
112
|
+
return handleLogStrategy(this.arguments)
|
|
102
113
|
},
|
|
103
114
|
name,
|
|
104
115
|
conf.handler,
|
|
@@ -108,20 +119,27 @@ export function makeLogsPublicApi(startLogsImpl) {
|
|
|
108
119
|
return customLoggers[name]
|
|
109
120
|
},
|
|
110
121
|
|
|
111
|
-
getLogger: function(name) {
|
|
122
|
+
getLogger: function (name) {
|
|
112
123
|
return customLoggers[name]
|
|
113
124
|
},
|
|
114
125
|
|
|
115
|
-
getInitConfiguration: function() {
|
|
126
|
+
getInitConfiguration: function () {
|
|
116
127
|
return getInitConfigurationStrategy()
|
|
117
128
|
},
|
|
118
129
|
|
|
119
|
-
getInternalContext: function(startTime) {
|
|
130
|
+
getInternalContext: function (startTime) {
|
|
120
131
|
return getInternalContextStrategy(startTime)
|
|
121
132
|
},
|
|
133
|
+
setUser: function (newUser) {
|
|
134
|
+
if (checkUser(newUser)) {
|
|
135
|
+
userContextManager.setContext(sanitizeUser(newUser))
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
getUser: userContextManager.getContext,
|
|
139
|
+
removeUserProperty: userContextManager.removeContextProperty,
|
|
140
|
+
clearUser: userContextManager.clearContext
|
|
122
141
|
})
|
|
123
142
|
|
|
124
|
-
|
|
125
143
|
function canInitLogs(initConfiguration) {
|
|
126
144
|
if (isAlreadyInitialized) {
|
|
127
145
|
if (!initConfiguration.silentMultipleInit) {
|
package/src/boot/startLogs.js
CHANGED
|
@@ -2,9 +2,13 @@ import {
|
|
|
2
2
|
ErrorSource,
|
|
3
3
|
LifeCycle,
|
|
4
4
|
LifeCycleEventType,
|
|
5
|
-
createPageExitObservable
|
|
5
|
+
createPageExitObservable,
|
|
6
|
+
areCookiesAuthorized
|
|
6
7
|
} from '@cloudcare/browser-core'
|
|
7
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
startLogsSessionManager,
|
|
10
|
+
startLogsSessionManagerStub
|
|
11
|
+
} from '../domain/logsSessionManager'
|
|
8
12
|
import { startLogsAssembly } from '../domain/assembly'
|
|
9
13
|
import { startConsoleCollection } from '../domain/logsCollection/console/consoleCollection'
|
|
10
14
|
import { startReportCollection } from '../domain/logsCollection/report/reportCollection'
|
|
@@ -15,7 +19,7 @@ import { startLogsBatch } from '../transport/startLogsBatch'
|
|
|
15
19
|
import { StatusType } from '../domain/logger'
|
|
16
20
|
import { startInternalContext } from '../domain/internalContext'
|
|
17
21
|
|
|
18
|
-
export function startLogs(configuration,
|
|
22
|
+
export function startLogs(configuration, buildCommonContext, mainLogger) {
|
|
19
23
|
var lifeCycle = new LifeCycle()
|
|
20
24
|
|
|
21
25
|
var reportError = function (error) {
|
|
@@ -32,23 +36,31 @@ export function startLogs(configuration, getCommonContext, mainLogger) {
|
|
|
32
36
|
})
|
|
33
37
|
}
|
|
34
38
|
var pageExitObservable = createPageExitObservable()
|
|
39
|
+
var session = areCookiesAuthorized(configuration.cookieOptions)
|
|
40
|
+
? startLogsSessionManager(configuration)
|
|
41
|
+
: startLogsSessionManagerStub(configuration)
|
|
35
42
|
startNetworkErrorCollection(configuration, lifeCycle)
|
|
36
43
|
startRuntimeErrorCollection(configuration, lifeCycle)
|
|
37
44
|
startConsoleCollection(configuration, lifeCycle)
|
|
38
45
|
startReportCollection(configuration, lifeCycle)
|
|
39
46
|
var _startLoggerCollection = startLoggerCollection(lifeCycle)
|
|
40
47
|
|
|
41
|
-
var session = startLogsSessionManager(configuration)
|
|
42
48
|
startLogsAssembly(
|
|
43
49
|
session,
|
|
44
50
|
configuration,
|
|
45
51
|
lifeCycle,
|
|
46
|
-
|
|
52
|
+
buildCommonContext,
|
|
47
53
|
mainLogger,
|
|
48
54
|
reportError
|
|
49
55
|
)
|
|
50
56
|
|
|
51
|
-
startLogsBatch(
|
|
57
|
+
startLogsBatch(
|
|
58
|
+
configuration,
|
|
59
|
+
lifeCycle,
|
|
60
|
+
reportError,
|
|
61
|
+
pageExitObservable,
|
|
62
|
+
session.expireObservable
|
|
63
|
+
)
|
|
52
64
|
|
|
53
65
|
var internalContext = startInternalContext(session)
|
|
54
66
|
|
package/src/domain/assembly.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
deviceInfo,
|
|
9
9
|
each,
|
|
10
10
|
RumEventType,
|
|
11
|
+
isEmptyObject,
|
|
11
12
|
isNullUndefinedDefaultValue
|
|
12
13
|
} from '@cloudcare/browser-core'
|
|
13
14
|
|
|
@@ -18,73 +19,75 @@ export function startLogsAssembly(
|
|
|
18
19
|
sessionManager,
|
|
19
20
|
configuration,
|
|
20
21
|
lifeCycle,
|
|
21
|
-
|
|
22
|
+
buildCommonContext,
|
|
22
23
|
mainLogger,
|
|
23
24
|
reportError
|
|
24
25
|
) {
|
|
25
26
|
var statusWithCustom = STATUSES.concat(['custom'])
|
|
26
27
|
var logRateLimiters = {}
|
|
27
|
-
each(statusWithCustom, function(status) {
|
|
28
|
-
logRateLimiters[status] = createEventRateLimiter(
|
|
28
|
+
each(statusWithCustom, function (status) {
|
|
29
|
+
logRateLimiters[status] = createEventRateLimiter(
|
|
30
|
+
status,
|
|
31
|
+
configuration.eventRateLimiterThreshold,
|
|
32
|
+
reportError
|
|
33
|
+
)
|
|
29
34
|
})
|
|
30
|
-
lifeCycle.subscribe(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var startTime = getRelativeTime(rawLogsEvent.date)
|
|
39
|
-
var session = sessionManager.findTrackedSession(startTime)
|
|
35
|
+
lifeCycle.subscribe(LifeCycleEventType.RAW_LOG_COLLECTED, function (data) {
|
|
36
|
+
// { rawLogsEvent, messageContext = undefined, savedCommonContext = undefined, logger = mainLogger }
|
|
37
|
+
var rawLogsEvent = data.rawLogsEvent
|
|
38
|
+
var messageContext = data.messageContext || undefined
|
|
39
|
+
var savedCommonContext = data.messageContext || undefined
|
|
40
|
+
var logger = data.logger || mainLogger
|
|
41
|
+
var startTime = getRelativeTime(rawLogsEvent.date)
|
|
42
|
+
var session = sessionManager.findTrackedSession(startTime)
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
session: {
|
|
55
|
-
id: session.id
|
|
56
|
-
},
|
|
57
|
-
view: commonContext.view,
|
|
58
|
-
device: deviceInfo,
|
|
59
|
-
type: RumEventType.LOGGER
|
|
44
|
+
if (!session) {
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
var commonContext = savedCommonContext || buildCommonContext()
|
|
48
|
+
var log = extend2Lev(
|
|
49
|
+
{
|
|
50
|
+
service: configuration.service || 'browser',
|
|
51
|
+
env: configuration.env || '',
|
|
52
|
+
version: configuration.version || '',
|
|
53
|
+
_dd: {
|
|
54
|
+
sdkName: configuration.sdkName,
|
|
55
|
+
sdkVersion: configuration.sdkVersion
|
|
60
56
|
},
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
isNullUndefinedDefaultValue(logRateLimiters[log.status], logRateLimiters['custom']).isLimitReached()
|
|
78
|
-
)
|
|
79
|
-
) {
|
|
80
|
-
return
|
|
81
|
-
}
|
|
57
|
+
session: {
|
|
58
|
+
id: session.id
|
|
59
|
+
},
|
|
60
|
+
view: commonContext.view,
|
|
61
|
+
user: !isEmptyObject(commonContext.user)
|
|
62
|
+
? commonContext.user
|
|
63
|
+
: undefined,
|
|
64
|
+
device: deviceInfo,
|
|
65
|
+
type: RumEventType.LOGGER
|
|
66
|
+
},
|
|
67
|
+
commonContext.context,
|
|
68
|
+
getRUMInternalContext(startTime),
|
|
69
|
+
rawLogsEvent,
|
|
70
|
+
logger.getContext(),
|
|
71
|
+
messageContext
|
|
72
|
+
)
|
|
82
73
|
|
|
83
|
-
|
|
74
|
+
if (
|
|
75
|
+
// Todo: [RUMF-1230] Move this check to the logger collection in the next major release
|
|
76
|
+
!isAuthorized(rawLogsEvent.status, HandlerType.http, logger) ||
|
|
77
|
+
(configuration.beforeSend && configuration.beforeSend(log) === false) ||
|
|
78
|
+
(log.error &&
|
|
79
|
+
log.error.origin !== ErrorSource.AGENT &&
|
|
80
|
+
isNullUndefinedDefaultValue(
|
|
81
|
+
logRateLimiters[log.status],
|
|
82
|
+
logRateLimiters['custom']
|
|
83
|
+
).isLimitReached())
|
|
84
|
+
) {
|
|
85
|
+
return
|
|
84
86
|
}
|
|
85
|
-
)
|
|
86
|
-
}
|
|
87
87
|
|
|
88
|
+
lifeCycle.notify(LifeCycleEventType.LOG_COLLECTED, withSnakeCaseKeys(log))
|
|
89
|
+
})
|
|
90
|
+
}
|
|
88
91
|
|
|
89
92
|
export function getRUMInternalContext(startTime) {
|
|
90
93
|
return getInternalContextFromRumGlobal(window.DATAFLUX_RUM)
|
package/src/domain/logger.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
deepClone,
|
|
3
|
+
assign,
|
|
4
|
+
extend2Lev,
|
|
5
|
+
createContextManager,
|
|
6
|
+
ErrorSource,
|
|
7
|
+
keys,
|
|
8
|
+
CustomerDataType
|
|
9
|
+
} from '@cloudcare/browser-core'
|
|
3
10
|
|
|
4
11
|
export var StatusType = {
|
|
5
12
|
debug: 'debug',
|
|
@@ -12,13 +19,19 @@ export var StatusType = {
|
|
|
12
19
|
export var HandlerType = {
|
|
13
20
|
console: 'console',
|
|
14
21
|
http: 'http',
|
|
15
|
-
silent: 'silent'
|
|
22
|
+
silent: 'silent'
|
|
16
23
|
}
|
|
17
24
|
|
|
18
25
|
export var STATUSES = keys(StatusType)
|
|
19
26
|
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
20
|
-
export function Logger(
|
|
21
|
-
|
|
27
|
+
export function Logger(
|
|
28
|
+
handleLogStrategy,
|
|
29
|
+
name,
|
|
30
|
+
handlerType,
|
|
31
|
+
level,
|
|
32
|
+
loggerContext
|
|
33
|
+
) {
|
|
34
|
+
this.contextManager = createContextManager(CustomerDataType.LoggerContext)
|
|
22
35
|
if (typeof handlerType === 'undefined') {
|
|
23
36
|
handlerType = HandlerType.http
|
|
24
37
|
}
|
|
@@ -31,66 +44,71 @@ export function Logger(handleLogStrategy, name, handlerType, level, loggerContex
|
|
|
31
44
|
this.handleLogStrategy = handleLogStrategy
|
|
32
45
|
this.handlerType = handlerType
|
|
33
46
|
this.level = level
|
|
34
|
-
this.contextManager.set(
|
|
47
|
+
this.contextManager.set(
|
|
48
|
+
assign({}, loggerContext, name ? { logger: { name: name } } : undefined)
|
|
49
|
+
)
|
|
35
50
|
}
|
|
36
51
|
Logger.prototype = {
|
|
37
|
-
log: function(message, messageContext, status) {
|
|
52
|
+
log: function (message, messageContext, status) {
|
|
38
53
|
if (typeof status === 'undefined') {
|
|
39
54
|
status = StatusType.info
|
|
40
55
|
}
|
|
41
|
-
this.handleLogStrategy(
|
|
56
|
+
this.handleLogStrategy(
|
|
57
|
+
{ message: message, context: deepClone(messageContext), status: status },
|
|
58
|
+
this
|
|
59
|
+
)
|
|
42
60
|
},
|
|
43
61
|
|
|
44
|
-
debug: function(message, messageContext) {
|
|
62
|
+
debug: function (message, messageContext) {
|
|
45
63
|
this.log(message, messageContext, StatusType.debug)
|
|
46
64
|
},
|
|
47
65
|
|
|
48
|
-
info: function(message, messageContext) {
|
|
66
|
+
info: function (message, messageContext) {
|
|
49
67
|
this.log(message, messageContext, StatusType.info)
|
|
50
68
|
},
|
|
51
69
|
|
|
52
|
-
warn: function(message, messageContext) {
|
|
70
|
+
warn: function (message, messageContext) {
|
|
53
71
|
this.log(message, messageContext, StatusType.warn)
|
|
54
72
|
},
|
|
55
|
-
critical: function(message, messageContext) {
|
|
73
|
+
critical: function (message, messageContext) {
|
|
56
74
|
this.log(message, messageContext, StatusType.critical)
|
|
57
75
|
},
|
|
58
|
-
error: function(message, messageContext) {
|
|
76
|
+
error: function (message, messageContext) {
|
|
59
77
|
var errorOrigin = {
|
|
60
78
|
error: {
|
|
61
|
-
origin: ErrorSource.LOGGER
|
|
62
|
-
}
|
|
79
|
+
origin: ErrorSource.LOGGER
|
|
80
|
+
}
|
|
63
81
|
}
|
|
64
82
|
this.log(message, extend2Lev(errorOrigin, messageContext), StatusType.error)
|
|
65
83
|
},
|
|
66
84
|
|
|
67
|
-
setContext:function(context) {
|
|
85
|
+
setContext: function (context) {
|
|
68
86
|
this.contextManager.set(context)
|
|
69
87
|
},
|
|
70
88
|
|
|
71
|
-
getContext: function() {
|
|
89
|
+
getContext: function () {
|
|
72
90
|
return this.contextManager.get()
|
|
73
91
|
},
|
|
74
92
|
|
|
75
|
-
addContext: function(key, value) {
|
|
93
|
+
addContext: function (key, value) {
|
|
76
94
|
this.contextManager.add(key, value)
|
|
77
95
|
},
|
|
78
96
|
|
|
79
|
-
removeContext: function(key) {
|
|
97
|
+
removeContext: function (key) {
|
|
80
98
|
this.contextManager.remove(key)
|
|
81
99
|
},
|
|
82
100
|
|
|
83
|
-
setHandler:function(handler) {
|
|
101
|
+
setHandler: function (handler) {
|
|
84
102
|
this.handlerType = handler
|
|
85
103
|
},
|
|
86
104
|
|
|
87
|
-
getHandler: function() {
|
|
105
|
+
getHandler: function () {
|
|
88
106
|
return this.handlerType
|
|
89
107
|
},
|
|
90
|
-
setLevel: function(level) {
|
|
108
|
+
setLevel: function (level) {
|
|
91
109
|
this.level = level
|
|
92
110
|
},
|
|
93
|
-
getLevel: function() {
|
|
111
|
+
getLevel: function () {
|
|
94
112
|
return this.level
|
|
95
113
|
}
|
|
96
114
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
performDraw,
|
|
3
|
+
startSessionManager,
|
|
4
|
+
Observable
|
|
5
|
+
} from '@cloudcare/browser-core'
|
|
2
6
|
|
|
3
7
|
export var LOGS_SESSION_KEY = 'logs'
|
|
4
8
|
|
|
@@ -23,17 +27,22 @@ export function startLogsSessionManager(configuration) {
|
|
|
23
27
|
id: session.id
|
|
24
28
|
}
|
|
25
29
|
: undefined
|
|
26
|
-
}
|
|
30
|
+
},
|
|
31
|
+
expireObservable: sessionManager.expireObservable
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
export function startLogsSessionManagerStub(configuration) {
|
|
36
|
+
var isTracked =
|
|
37
|
+
computeTrackingType(configuration) === LoggerTrackingType.TRACKED
|
|
38
|
+
var session = isTracked ? {} : undefined
|
|
39
|
+
return {
|
|
40
|
+
findTrackedSession: function () {
|
|
41
|
+
return session
|
|
42
|
+
},
|
|
43
|
+
expireObservable: new Observable()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
37
46
|
|
|
38
47
|
function computeTrackingType(configuration) {
|
|
39
48
|
if (!performDraw(configuration.sessionSampleRate)) {
|