@cloudcare/browser-logs 1.1.24 → 1.2.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.
Files changed (58) hide show
  1. package/README.md +5 -4
  2. package/bundle/dataflux-logs.js +1 -1
  3. package/cjs/boot/buildEnv.js +1 -1
  4. package/cjs/boot/logsPublicApi.js +133 -0
  5. package/cjs/boot/startLogs.js +63 -0
  6. package/cjs/domain/assembly.js +74 -0
  7. package/cjs/domain/configuration.js +55 -0
  8. package/cjs/domain/internalContext.js +22 -0
  9. package/cjs/domain/logger.js +28 -36
  10. package/cjs/domain/logsCollection/console/consoleCollection.js +39 -0
  11. package/cjs/domain/logsCollection/logger/loggerCollection.js +51 -0
  12. package/cjs/domain/logsCollection/networkError/networkErrorCollection.js +238 -0
  13. package/cjs/domain/logsCollection/report/reportCollection.js +50 -0
  14. package/cjs/domain/logsCollection/rumtimeError/runtimeErrorCollection.js +46 -0
  15. package/cjs/domain/{loggerSession.js → logsSessionManager.js} +19 -23
  16. package/cjs/entries/main.js +16 -0
  17. package/cjs/index.js +2 -2
  18. package/cjs/transport/startLogsBatch.js +15 -0
  19. package/esm/boot/buildEnv.js +1 -1
  20. package/esm/boot/logsPublicApi.js +122 -0
  21. package/esm/boot/startLogs.js +45 -0
  22. package/esm/domain/assembly.js +59 -0
  23. package/esm/domain/configuration.js +41 -0
  24. package/esm/domain/internalContext.js +15 -0
  25. package/esm/domain/logger.js +26 -36
  26. package/esm/domain/logsCollection/console/consoleCollection.js +31 -0
  27. package/esm/domain/logsCollection/logger/loggerCollection.js +38 -0
  28. package/esm/domain/logsCollection/networkError/networkErrorCollection.js +223 -0
  29. package/esm/domain/logsCollection/report/reportCollection.js +40 -0
  30. package/esm/domain/logsCollection/rumtimeError/runtimeErrorCollection.js +37 -0
  31. package/esm/domain/logsSessionManager.js +45 -0
  32. package/esm/entries/main.js +5 -0
  33. package/esm/index.js +1 -1
  34. package/esm/transport/startLogsBatch.js +7 -0
  35. package/package.json +3 -3
  36. package/src/boot/logsPublicApi.js +140 -0
  37. package/src/boot/startLogs.js +51 -0
  38. package/src/domain/assembly.js +101 -0
  39. package/src/domain/configuration.js +70 -0
  40. package/src/domain/internalContext.js +15 -0
  41. package/src/domain/logger.js +37 -58
  42. package/src/domain/logsCollection/console/consoleCollection.js +36 -0
  43. package/src/domain/logsCollection/logger/loggerCollection.js +48 -0
  44. package/src/domain/logsCollection/networkError/networkErrorCollection.js +260 -0
  45. package/src/domain/logsCollection/report/reportCollection.js +49 -0
  46. package/src/domain/logsCollection/rumtimeError/runtimeErrorCollection.js +35 -0
  47. package/src/domain/logsSessionManager.js +52 -0
  48. package/src/entries/main.js +7 -0
  49. package/src/index.js +1 -1
  50. package/src/transport/startLogsBatch.js +17 -0
  51. package/cjs/boot/log.entry.js +0 -115
  52. package/cjs/boot/log.js +0 -132
  53. package/esm/boot/log.entry.js +0 -87
  54. package/esm/boot/log.js +0 -115
  55. package/esm/domain/loggerSession.js +0 -46
  56. package/src/boot/log.entry.js +0 -119
  57. package/src/boot/log.js +0 -185
  58. package/src/domain/loggerSession.js +0 -56
package/cjs/boot/log.js DELETED
@@ -1,132 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.assembleMessageContexts = assembleMessageContexts;
7
- exports.buildAssemble = buildAssemble;
8
- exports.doStartLogs = doStartLogs;
9
- exports.startLogs = startLogs;
10
-
11
- var _browserCore = require("@cloudcare/browser-core");
12
-
13
- var _logger = require("../domain/logger");
14
-
15
- var _loggerSession = require("../domain/loggerSession");
16
-
17
- var _buildEnv = require("./buildEnv");
18
-
19
- var FIELDS_WITH_SENSITIVE_DATA = ['view.url', 'view.referrer', 'message', 'error.stack', 'source.url'];
20
-
21
- function startLogs(userConfiguration, errorLogger, getGlobalContext) {
22
- var configuration = (0, _browserCore.commonInit)(userConfiguration, _buildEnv.buildEnv);
23
- var errorObservable = userConfiguration.forwardErrorsToLogs !== false ? (0, _browserCore.startAutomaticErrorCollection)(configuration) : new _browserCore.Observable();
24
- var session = (0, _loggerSession.startLoggerSession)(configuration, (0, _browserCore.areCookiesAuthorized)(configuration.cookieOptions));
25
- return doStartLogs(configuration, errorObservable, session, errorLogger, getGlobalContext);
26
- }
27
-
28
- function doStartLogs(configuration, errorObservable, session, errorLogger, getGlobalContext) {
29
- var assemble = buildAssemble(session, configuration, reportError);
30
- var batch = startLoggerBatch(configuration);
31
-
32
- function reportError(error) {
33
- var resource = error.resource;
34
-
35
- if (resource) {
36
- var urlObj = (0, _browserCore.urlParse)(error.resource.url).getParse();
37
- resource = {
38
- method: error.resource.method,
39
- status: error.resource.statusCode,
40
- statusGroup: (0, _browserCore.getStatusGroup)(error.resource.statusCode),
41
- url: error.resource.url,
42
- urlHost: urlObj.Host,
43
- urlPath: urlObj.Path,
44
- urlPathGroup: (0, _browserCore.replaceNumberCharByPath)(urlObj.Path)
45
- };
46
- }
47
-
48
- errorLogger.error(error.message, (0, _browserCore.extend2Lev)({
49
- date: error.startClocks.timeStamp,
50
- error: {
51
- type: error.type,
52
- source: error.source,
53
- stack: error.stack
54
- }
55
- }, {
56
- resource: resource
57
- }, getRUMInternalContext(error.startClocks.relative)));
58
- }
59
-
60
- errorObservable.subscribe(reportError);
61
- return function (message, currentContext) {
62
- var contextualizedMessage = assemble(message, currentContext);
63
-
64
- if (contextualizedMessage) {
65
- batch.add(contextualizedMessage);
66
- }
67
- };
68
- }
69
-
70
- function startLoggerBatch(configuration) {
71
- var primaryBatch = createLoggerBatch(configuration.logsEndpoint);
72
-
73
- function createLoggerBatch(endpointUrl) {
74
- return new _browserCore.Batch(new _browserCore.HttpRequest(endpointUrl, configuration.batchBytesLimit, configuration.isLineProtocolToJson), configuration.maxBatchSize, configuration.batchBytesLimit, configuration.maxMessageSize, configuration.flushTimeout, configuration.isLineProtocolToJson);
75
- }
76
-
77
- return {
78
- add: function add(message) {
79
- primaryBatch.add(message);
80
- }
81
- };
82
- }
83
-
84
- function buildAssemble(session, configuration, reportError) {
85
- var errorFilter = (0, _browserCore.createErrorFilter)(configuration, reportError);
86
- return function (message, currentContext) {
87
- if (!session.isTracked()) {
88
- return undefined;
89
- }
90
-
91
- var contextualizedMessage = (0, _browserCore.extend2Lev)({
92
- service: configuration.service || 'browser',
93
- session: {
94
- id: session.getId()
95
- },
96
- type: _browserCore.RumEventType.LOGGER,
97
- _dd: {
98
- sdkName: configuration.sdkName,
99
- sdkVersion: configuration.sdkVersion,
100
- env: configuration.env,
101
- version: configuration.version
102
- },
103
- device: _browserCore.deviceInfo,
104
- user: {
105
- user_id: configuration.user_id
106
- }
107
- }, currentContext, getRUMInternalContext(), message);
108
-
109
- if (configuration.beforeSend) {
110
- var shouldSend = (0, _browserCore.limitModification)(contextualizedMessage, FIELDS_WITH_SENSITIVE_DATA, configuration.beforeSend);
111
-
112
- if (shouldSend === false) {
113
- return undefined;
114
- }
115
- }
116
-
117
- if (contextualizedMessage.status === _logger.StatusType.error && errorFilter.isLimitReached()) {
118
- return undefined;
119
- }
120
-
121
- return (0, _browserCore.withSnakeCaseKeys)(contextualizedMessage);
122
- };
123
- }
124
-
125
- function assembleMessageContexts(defaultContext, currentContext, rumInternalContext, message) {
126
- return (0, _browserCore.extend)(defaultContext, currentContext, rumInternalContext, message);
127
- }
128
-
129
- function getRUMInternalContext(startTime) {
130
- var rum = window.DATAFLUX_RUM;
131
- return rum && rum.getInternalContext ? rum.getInternalContext(startTime) : undefined;
132
- }
@@ -1,87 +0,0 @@
1
- import { isPercentage, createContextManager, extend, replaceNumberCharByPath, getQueryParamsFromUrl, jsonStringify, BoundedBuffer, makePublicApi, defineGlobal, getGlobalObject, extend2Lev } from '@cloudcare/browser-core';
2
- import { startLogs } from './log';
3
- import { Logger } from '../domain/logger';
4
- export var datafluxLogs = makeLogsPublicApi(startLogs);
5
- defineGlobal(getGlobalObject(), 'DATAFLUX_LOGS', datafluxLogs);
6
- export function makeLogsPublicApi(startLogsImpl) {
7
- var isAlreadyInitialized = false;
8
- var globalContextManager = createContextManager();
9
- var customLoggers = {};
10
- var beforeInitSendLog = new BoundedBuffer();
11
-
12
- var sendLogStrategy = function sendLogStrategy(message, currentContext) {
13
- beforeInitSendLog.add([message, currentContext]);
14
- };
15
-
16
- var logger = new Logger(sendLog);
17
- return makePublicApi({
18
- logger: logger,
19
- init: function init(userConfiguration) {
20
- if (!canInitLogs(userConfiguration)) {
21
- return;
22
- }
23
-
24
- sendLogStrategy = startLogsImpl(userConfiguration, logger, globalContextManager.get);
25
- beforeInitSendLog.drain(function (_ref) {
26
- var [message, context] = _ref;
27
- return sendLogStrategy(message, context);
28
- });
29
- isAlreadyInitialized = true;
30
- },
31
- getLoggerGlobalContext: globalContextManager.get,
32
- setLoggerGlobalContext: globalContextManager.set,
33
- addLoggerGlobalContext: globalContextManager.add,
34
- removeLoggerGlobalContext: globalContextManager.remove,
35
- createLogger: function createLogger(name, conf) {
36
- if (typeof conf === 'undefined') {
37
- conf = {};
38
- }
39
-
40
- customLoggers[name] = new Logger(sendLog, conf.handler, conf.level, extend({}, conf.context, {
41
- logger: {
42
- name: name
43
- }
44
- }));
45
- return customLoggers[name];
46
- },
47
- getLogger: function getLogger(name) {
48
- return customLoggers[name];
49
- }
50
- });
51
-
52
- function canInitLogs(userConfiguration) {
53
- if (isAlreadyInitialized) {
54
- if (!userConfiguration.silentMultipleInit) {
55
- console.error('DATAFLUX_LOGS is already initialized.');
56
- }
57
-
58
- return false;
59
- }
60
-
61
- if (!userConfiguration.datakitUrl && !userConfiguration.datakitOrigin) {
62
- console.error('datakitOrigin is not configured, no RUM data will be collected.');
63
- return false;
64
- }
65
-
66
- if (userConfiguration.sampleRate !== undefined && !isPercentage(userConfiguration.sampleRate)) {
67
- console.error('Sample Rate should be a number between 0 and 100');
68
- return false;
69
- }
70
-
71
- return true;
72
- }
73
-
74
- function sendLog(message) {
75
- sendLogStrategy(message, extend2Lev({
76
- date: new Date().getTime(),
77
- view: {
78
- referrer: document.referrer,
79
- url: window.location.href,
80
- host: window.location.host,
81
- path: window.location.pathname,
82
- pathGroup: replaceNumberCharByPath(window.location.pathname),
83
- urlQuery: jsonStringify(getQueryParamsFromUrl(window.location.href))
84
- }
85
- }, globalContextManager.get()));
86
- }
87
- }
package/esm/boot/log.js DELETED
@@ -1,115 +0,0 @@
1
- import { areCookiesAuthorized, commonInit, createErrorFilter, extend, startAutomaticErrorCollection, Observable, limitModification, Batch, HttpRequest, urlParse, getStatusGroup, deviceInfo, RumEventType, replaceNumberCharByPath, withSnakeCaseKeys, extend2Lev } from '@cloudcare/browser-core';
2
- import { StatusType } from '../domain/logger';
3
- import { startLoggerSession } from '../domain/loggerSession';
4
- import { buildEnv } from './buildEnv';
5
- var FIELDS_WITH_SENSITIVE_DATA = ['view.url', 'view.referrer', 'message', 'error.stack', 'source.url'];
6
- export function startLogs(userConfiguration, errorLogger, getGlobalContext) {
7
- var configuration = commonInit(userConfiguration, buildEnv);
8
- var errorObservable = userConfiguration.forwardErrorsToLogs !== false ? startAutomaticErrorCollection(configuration) : new Observable();
9
- var session = startLoggerSession(configuration, areCookiesAuthorized(configuration.cookieOptions));
10
- return doStartLogs(configuration, errorObservable, session, errorLogger, getGlobalContext);
11
- }
12
- export function doStartLogs(configuration, errorObservable, session, errorLogger, getGlobalContext) {
13
- var assemble = buildAssemble(session, configuration, reportError);
14
- var batch = startLoggerBatch(configuration);
15
-
16
- function reportError(error) {
17
- var resource = error.resource;
18
-
19
- if (resource) {
20
- var urlObj = urlParse(error.resource.url).getParse();
21
- resource = {
22
- method: error.resource.method,
23
- status: error.resource.statusCode,
24
- statusGroup: getStatusGroup(error.resource.statusCode),
25
- url: error.resource.url,
26
- urlHost: urlObj.Host,
27
- urlPath: urlObj.Path,
28
- urlPathGroup: replaceNumberCharByPath(urlObj.Path)
29
- };
30
- }
31
-
32
- errorLogger.error(error.message, extend2Lev({
33
- date: error.startClocks.timeStamp,
34
- error: {
35
- type: error.type,
36
- source: error.source,
37
- stack: error.stack
38
- }
39
- }, {
40
- resource: resource
41
- }, getRUMInternalContext(error.startClocks.relative)));
42
- }
43
-
44
- errorObservable.subscribe(reportError);
45
- return function (message, currentContext) {
46
- var contextualizedMessage = assemble(message, currentContext);
47
-
48
- if (contextualizedMessage) {
49
- batch.add(contextualizedMessage);
50
- }
51
- };
52
- }
53
-
54
- function startLoggerBatch(configuration) {
55
- var primaryBatch = createLoggerBatch(configuration.logsEndpoint);
56
-
57
- function createLoggerBatch(endpointUrl) {
58
- return new Batch(new HttpRequest(endpointUrl, configuration.batchBytesLimit, configuration.isLineProtocolToJson), configuration.maxBatchSize, configuration.batchBytesLimit, configuration.maxMessageSize, configuration.flushTimeout, configuration.isLineProtocolToJson);
59
- }
60
-
61
- return {
62
- add: function add(message) {
63
- primaryBatch.add(message);
64
- }
65
- };
66
- }
67
-
68
- export function buildAssemble(session, configuration, reportError) {
69
- var errorFilter = createErrorFilter(configuration, reportError);
70
- return function (message, currentContext) {
71
- if (!session.isTracked()) {
72
- return undefined;
73
- }
74
-
75
- var contextualizedMessage = extend2Lev({
76
- service: configuration.service || 'browser',
77
- session: {
78
- id: session.getId()
79
- },
80
- type: RumEventType.LOGGER,
81
- _dd: {
82
- sdkName: configuration.sdkName,
83
- sdkVersion: configuration.sdkVersion,
84
- env: configuration.env,
85
- version: configuration.version
86
- },
87
- device: deviceInfo,
88
- user: {
89
- user_id: configuration.user_id
90
- }
91
- }, currentContext, getRUMInternalContext(), message);
92
-
93
- if (configuration.beforeSend) {
94
- var shouldSend = limitModification(contextualizedMessage, FIELDS_WITH_SENSITIVE_DATA, configuration.beforeSend);
95
-
96
- if (shouldSend === false) {
97
- return undefined;
98
- }
99
- }
100
-
101
- if (contextualizedMessage.status === StatusType.error && errorFilter.isLimitReached()) {
102
- return undefined;
103
- }
104
-
105
- return withSnakeCaseKeys(contextualizedMessage);
106
- };
107
- }
108
- export function assembleMessageContexts(defaultContext, currentContext, rumInternalContext, message) {
109
- return extend(defaultContext, currentContext, rumInternalContext, message);
110
- }
111
-
112
- function getRUMInternalContext(startTime) {
113
- var rum = window.DATAFLUX_RUM;
114
- return rum && rum.getInternalContext ? rum.getInternalContext(startTime) : undefined;
115
- }
@@ -1,46 +0,0 @@
1
- import { performDraw, startSessionManagement } from '@cloudcare/browser-core';
2
- export var LOGGER_SESSION_KEY = 'logs';
3
- export var LoggerTrackingType = {
4
- NOT_TRACKED: '0',
5
- TRACKED: '1'
6
- };
7
- export function startLoggerSession(configuration, areCookieAuthorized) {
8
- if (!areCookieAuthorized) {
9
- var _isTracked = computeTrackingType(configuration) === LoggerTrackingType.TRACKED;
10
-
11
- return {
12
- getId: () => undefined,
13
- isTracked: () => _isTracked
14
- };
15
- }
16
-
17
- var session = startSessionManagement(configuration.cookieOptions, LOGGER_SESSION_KEY, function (rawTrackingType) {
18
- return computeSessionState(configuration, rawTrackingType);
19
- });
20
- return {
21
- getId: session.getId,
22
- isTracked: function isTracked() {
23
- return session.getTrackingType() === LoggerTrackingType.TRACKED;
24
- }
25
- };
26
- }
27
-
28
- function computeTrackingType(configuration) {
29
- if (!performDraw(configuration.sampleRate)) {
30
- return LoggerTrackingType.NOT_TRACKED;
31
- }
32
-
33
- return LoggerTrackingType.TRACKED;
34
- }
35
-
36
- function computeSessionState(configuration, rawSessionType) {
37
- var trackingType = hasValidLoggerSession(rawSessionType) ? rawSessionType : computeTrackingType(configuration);
38
- return {
39
- trackingType: trackingType,
40
- isTracked: trackingType === LoggerTrackingType.TRACKED
41
- };
42
- }
43
-
44
- function hasValidLoggerSession(trackingType) {
45
- return trackingType === LoggerTrackingType.NOT_TRACKED || trackingType === LoggerTrackingType.TRACKED;
46
- }
@@ -1,119 +0,0 @@
1
- import {
2
- isPercentage,
3
- createContextManager,
4
- extend,
5
- replaceNumberCharByPath,
6
- getQueryParamsFromUrl,
7
- jsonStringify,
8
- BoundedBuffer,
9
- makePublicApi,
10
- defineGlobal,
11
- getGlobalObject,
12
- extend2Lev
13
- } from '@cloudcare/browser-core'
14
- import { startLogs } from './log'
15
- import { Logger } from '../domain/logger'
16
-
17
- export var datafluxLogs = makeLogsPublicApi(startLogs)
18
-
19
- defineGlobal(getGlobalObject(), 'DATAFLUX_LOGS', datafluxLogs)
20
-
21
- export function makeLogsPublicApi(startLogsImpl) {
22
- var isAlreadyInitialized = false
23
-
24
- var globalContextManager = createContextManager()
25
- var customLoggers = {}
26
-
27
- var beforeInitSendLog = new BoundedBuffer()
28
- var sendLogStrategy = function (message, currentContext) {
29
- beforeInitSendLog.add([message, currentContext])
30
- }
31
- var logger = new Logger(sendLog)
32
-
33
- return makePublicApi({
34
- logger: logger,
35
- init: function (userConfiguration) {
36
- if (!canInitLogs(userConfiguration)) {
37
- return
38
- }
39
- sendLogStrategy = startLogsImpl(
40
- userConfiguration,
41
- logger,
42
- globalContextManager.get
43
- )
44
- beforeInitSendLog.drain(function ([message, context]) {
45
- return sendLogStrategy(message, context)
46
- })
47
- isAlreadyInitialized = true
48
- },
49
-
50
- getLoggerGlobalContext: globalContextManager.get,
51
- setLoggerGlobalContext: globalContextManager.set,
52
-
53
- addLoggerGlobalContext: globalContextManager.add,
54
-
55
- removeLoggerGlobalContext: globalContextManager.remove,
56
-
57
- createLogger: function (name, conf) {
58
- if (typeof conf === 'undefined') {
59
- conf = {}
60
- }
61
- customLoggers[name] = new Logger(
62
- sendLog,
63
- conf.handler,
64
- conf.level,
65
- extend({}, conf.context, {
66
- logger: { name: name }
67
- })
68
- )
69
- return customLoggers[name]
70
- },
71
-
72
- getLogger: function (name) {
73
- return customLoggers[name]
74
- }
75
- })
76
-
77
- function canInitLogs(userConfiguration) {
78
- if (isAlreadyInitialized) {
79
- if (!userConfiguration.silentMultipleInit) {
80
- console.error('DATAFLUX_LOGS is already initialized.')
81
- }
82
- return false
83
- }
84
- if (!userConfiguration.datakitUrl && !userConfiguration.datakitOrigin) {
85
- console.error(
86
- 'datakitOrigin is not configured, no RUM data will be collected.'
87
- )
88
- return false
89
- }
90
- if (
91
- userConfiguration.sampleRate !== undefined &&
92
- !isPercentage(userConfiguration.sampleRate)
93
- ) {
94
- console.error('Sample Rate should be a number between 0 and 100')
95
- return false
96
- }
97
- return true
98
- }
99
-
100
- function sendLog(message) {
101
- sendLogStrategy(
102
- message,
103
- extend2Lev(
104
- {
105
- date: new Date().getTime(),
106
- view: {
107
- referrer: document.referrer,
108
- url: window.location.href,
109
- host: window.location.host,
110
- path: window.location.pathname,
111
- pathGroup: replaceNumberCharByPath(window.location.pathname),
112
- urlQuery: jsonStringify(getQueryParamsFromUrl(window.location.href))
113
- }
114
- },
115
- globalContextManager.get()
116
- )
117
- )
118
- }
119
- }
package/src/boot/log.js DELETED
@@ -1,185 +0,0 @@
1
- import {
2
- areCookiesAuthorized,
3
- commonInit,
4
- createErrorFilter,
5
- extend,
6
- startAutomaticErrorCollection,
7
- Observable,
8
- limitModification,
9
- Batch,
10
- HttpRequest,
11
- urlParse,
12
- getStatusGroup,
13
- deviceInfo,
14
- RumEventType,
15
- replaceNumberCharByPath,
16
- withSnakeCaseKeys,
17
- extend2Lev
18
- } from '@cloudcare/browser-core'
19
- import { StatusType } from '../domain/logger'
20
- import { startLoggerSession } from '../domain/loggerSession'
21
- import { buildEnv } from './buildEnv'
22
-
23
- var FIELDS_WITH_SENSITIVE_DATA = [
24
- 'view.url',
25
- 'view.referrer',
26
- 'message',
27
- 'error.stack',
28
- 'source.url'
29
- ]
30
-
31
- export function startLogs(userConfiguration, errorLogger, getGlobalContext) {
32
- var configuration = commonInit(userConfiguration, buildEnv)
33
- var errorObservable =
34
- userConfiguration.forwardErrorsToLogs !== false
35
- ? startAutomaticErrorCollection(configuration)
36
- : new Observable()
37
- var session = startLoggerSession(
38
- configuration,
39
- areCookiesAuthorized(configuration.cookieOptions)
40
- )
41
- return doStartLogs(
42
- configuration,
43
- errorObservable,
44
- session,
45
- errorLogger,
46
- getGlobalContext
47
- )
48
- }
49
-
50
- export function doStartLogs(
51
- configuration,
52
- errorObservable,
53
- session,
54
- errorLogger,
55
- getGlobalContext
56
- ) {
57
- var assemble = buildAssemble(session, configuration, reportError)
58
- var batch = startLoggerBatch(configuration)
59
-
60
- function reportError(error) {
61
- var resource = error.resource
62
- if (resource) {
63
- var urlObj = urlParse(error.resource.url).getParse()
64
- resource = {
65
- method: error.resource.method,
66
- status: error.resource.statusCode,
67
- statusGroup: getStatusGroup(error.resource.statusCode),
68
- url: error.resource.url,
69
- urlHost: urlObj.Host,
70
- urlPath: urlObj.Path,
71
- urlPathGroup: replaceNumberCharByPath(urlObj.Path)
72
- }
73
- }
74
- errorLogger.error(
75
- error.message,
76
- extend2Lev(
77
- {
78
- date: error.startClocks.timeStamp,
79
- error: {
80
- type: error.type,
81
- source: error.source,
82
- stack: error.stack
83
- }
84
- },
85
- {
86
- resource: resource
87
- },
88
- getRUMInternalContext(error.startClocks.relative)
89
- )
90
- )
91
- }
92
- errorObservable.subscribe(reportError)
93
-
94
- return function (message, currentContext) {
95
- var contextualizedMessage = assemble(message, currentContext)
96
- if (contextualizedMessage) {
97
- batch.add(contextualizedMessage)
98
- }
99
- }
100
- }
101
-
102
- function startLoggerBatch(configuration) {
103
- var primaryBatch = createLoggerBatch(configuration.logsEndpoint)
104
-
105
- function createLoggerBatch(endpointUrl) {
106
- return new Batch(
107
- new HttpRequest(endpointUrl, configuration.batchBytesLimit, configuration.isLineProtocolToJson),
108
- configuration.maxBatchSize,
109
- configuration.batchBytesLimit,
110
- configuration.maxMessageSize,
111
- configuration.flushTimeout,
112
- configuration.isLineProtocolToJson,
113
- )
114
- }
115
-
116
- return {
117
- add: function (message) {
118
- primaryBatch.add(message)
119
- }
120
- }
121
- }
122
-
123
- export function buildAssemble(session, configuration, reportError) {
124
- var errorFilter = createErrorFilter(configuration, reportError)
125
- return function (message, currentContext) {
126
- if (!session.isTracked()) {
127
- return undefined
128
- }
129
- var contextualizedMessage = extend2Lev(
130
- {
131
- service: configuration.service || 'browser',
132
- session: {
133
- id: session.getId()
134
- },
135
- type: RumEventType.LOGGER,
136
- _dd: {
137
- sdkName: configuration.sdkName,
138
- sdkVersion: configuration.sdkVersion,
139
- env: configuration.env,
140
- version: configuration.version
141
- },
142
- device: deviceInfo,
143
- user: {
144
- user_id: configuration.user_id
145
- }
146
- },
147
- currentContext,
148
- getRUMInternalContext(),
149
- message
150
- )
151
- if (configuration.beforeSend) {
152
- var shouldSend = limitModification(
153
- contextualizedMessage,
154
- FIELDS_WITH_SENSITIVE_DATA,
155
- configuration.beforeSend
156
- )
157
- if (shouldSend === false) {
158
- return undefined
159
- }
160
- }
161
- if (
162
- contextualizedMessage.status === StatusType.error &&
163
- errorFilter.isLimitReached()
164
- ) {
165
- return undefined
166
- }
167
- return withSnakeCaseKeys(contextualizedMessage)
168
- }
169
- }
170
-
171
- export function assembleMessageContexts(
172
- defaultContext,
173
- currentContext,
174
- rumInternalContext,
175
- message
176
- ) {
177
- return extend(defaultContext, currentContext, rumInternalContext, message)
178
- }
179
-
180
- function getRUMInternalContext(startTime) {
181
- var rum = window.DATAFLUX_RUM
182
- return rum && rum.getInternalContext
183
- ? rum.getInternalContext(startTime)
184
- : undefined
185
- }