@cloudcare/browser-core 1.0.13 → 1.0.16

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.
@@ -14,6 +14,8 @@ var _cookie = require("./cookie");
14
14
 
15
15
  var _urlPolyfill = require("./helper/urlPolyfill");
16
16
 
17
+ var _enums = require("./helper/enums");
18
+
17
19
  var TRIM_REGIX = /^\s+|\s+$/g;
18
20
  var DEFAULT_CONFIGURATION = {
19
21
  resourceSampleRate: 100,
@@ -39,11 +41,21 @@ var DEFAULT_CONFIGURATION = {
39
41
  batchBytesLimit: 16 * _tools.ONE_KILO_BYTE,
40
42
  datakitUrl: '',
41
43
  logsEndpoint: '',
44
+ traceType: _enums.TraceType.DDTRACE,
45
+ traceId128Bit: false,
42
46
  trackInteractions: false,
43
47
  //是否开启交互action收集
44
48
  allowedDDTracingOrigins: [],
45
- //
46
- beforeSend: function beforeSend(event) {}
49
+ //废弃
50
+ allowedTracingOrigins: [],
51
+ // 新增
52
+ isServiceSampling: false,
53
+ // 是否不抛弃采样是数据, 采用在服务端菜样的方式
54
+ beforeSend: function beforeSend(event) {},
55
+ isServerError: function isServerError(request) {
56
+ return false;
57
+ } // 判断请求是否为error 请求
58
+
47
59
  };
48
60
  exports.DEFAULT_CONFIGURATION = DEFAULT_CONFIGURATION;
49
61
 
@@ -90,7 +102,11 @@ function commonInit(userConfiguration, buildEnv) {
90
102
  };
91
103
 
92
104
  if ('allowedDDTracingOrigins' in userConfiguration) {
93
- transportConfiguration.allowedDDTracingOrigins = userConfiguration.allowedDDTracingOrigins;
105
+ transportConfiguration.allowedTracingOrigins = userConfiguration.allowedDDTracingOrigins;
106
+ }
107
+
108
+ if ('allowedTracingOrigins' in userConfiguration) {
109
+ transportConfiguration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins;
94
110
  }
95
111
 
96
112
  if ('sampleRate' in userConfiguration) {
@@ -105,9 +121,30 @@ function commonInit(userConfiguration, buildEnv) {
105
121
  transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
106
122
  }
107
123
 
124
+ if ('isServerError' in userConfiguration && (0, _tools.isFunction)(userConfiguration.isServerError) && (0, _tools.isBoolean)(userConfiguration.isServerError())) {
125
+ transportConfiguration.isServerError = userConfiguration.isServerError;
126
+ }
127
+
128
+ if ('traceId128Bit' in userConfiguration) {
129
+ transportConfiguration.traceId128Bit = !!userConfiguration.traceId128Bit;
130
+ }
131
+
132
+ if ('traceType' in userConfiguration && hasTraceType(userConfiguration.traceType)) {
133
+ transportConfiguration.traceType = userConfiguration.traceType;
134
+ }
135
+
136
+ if ('isServiceSampling' in userConfiguration && (0, _tools.isBoolean)(userConfiguration.isServiceSampling)) {
137
+ transportConfiguration.isServiceSampling = userConfiguration.isServiceSampling;
138
+ }
139
+
108
140
  return (0, _tools.extend2Lev)({}, DEFAULT_CONFIGURATION, transportConfiguration);
109
141
  }
110
142
 
143
+ function hasTraceType(traceType) {
144
+ if (traceType && (0, _tools.values)(_enums.TraceType).indexOf(traceType) > -1) return true;
145
+ return false;
146
+ }
147
+
111
148
  function mustUseSecureCookie(userConfiguration) {
112
149
  return !!userConfiguration.useSecureSessionCookie || !!userConfiguration.useCrossSiteSessionCookie;
113
150
  }
package/cjs/cookie.js CHANGED
@@ -42,6 +42,10 @@ function cacheCookieAccess(name, options) {
42
42
  setCookie(name, value, expireDelay, options);
43
43
  cache = value;
44
44
  cacheAccess();
45
+ },
46
+ clearCache: function clearCache() {
47
+ window.clearTimeout(timeout);
48
+ hasCache = false;
45
49
  }
46
50
  };
47
51
  }
package/cjs/dataMap.js CHANGED
@@ -18,6 +18,7 @@ var commonTags = {
18
18
  user_name: 'user.name',
19
19
  session_id: 'session.id',
20
20
  session_type: 'session.type',
21
+ session_sampling: 'session.is_sampling',
21
22
  is_signin: 'user.is_signin',
22
23
  os: 'device.os',
23
24
  os_version: 'device.os_version',
@@ -113,7 +113,7 @@ function trackNetworkError(configuration, errorObservable) {
113
113
  });
114
114
 
115
115
  function handleCompleteRequest(type, request) {
116
- if (!(0, _configuration.isIntakeRequest)(request.url, configuration) && (!configuration.isEnabled('remove-network-errors') || !request.isAborted) && (isRejected(request) || isServerError(request))) {
116
+ if (!(0, _configuration.isIntakeRequest)(request.url, configuration) && !request.isAborted && (isRejected(request) || isServerError(request) || configuration.isServerError(request))) {
117
117
  errorObservable.notify({
118
118
  message: format(type) + ' error ' + request.method + ' ' + request.url,
119
119
  resource: {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.RequestType = exports.RumEventType = exports.ActionType = exports.ResourceType = exports.DOM_EVENT = void 0;
6
+ exports.ErrorHandling = exports.TraceType = exports.RequestType = exports.RumEventType = exports.ActionType = exports.ResourceType = exports.DOM_EVENT = void 0;
7
7
  var DOM_EVENT = {
8
8
  BEFORE_UNLOAD: 'beforeunload',
9
9
  CLICK: 'click',
@@ -53,4 +53,18 @@ var RequestType = {
53
53
  FETCH: ResourceType.FETCH,
54
54
  XHR: ResourceType.XHR
55
55
  };
56
- exports.RequestType = RequestType;
56
+ exports.RequestType = RequestType;
57
+ var TraceType = {
58
+ DDTRACE: 'ddtrace',
59
+ ZIPKIN_MULTI_HEADER: 'zipkin',
60
+ ZIPKIN_SINGLE_HEADER: 'zipkin_single_header',
61
+ W3C_TRACEPARENT: 'w3c_traceparent',
62
+ SKYWALKING_V3: 'skywalking_v3',
63
+ JAEGER: 'jaeger'
64
+ };
65
+ exports.TraceType = TraceType;
66
+ var ErrorHandling = {
67
+ HANDLED: 'handled',
68
+ UNHANDLED: 'unhandled'
69
+ };
70
+ exports.ErrorHandling = ErrorHandling;
@@ -53,6 +53,7 @@ function startSessionManagement(options, productKey, computeSessionState) {
53
53
  var currentSession = retrieveActiveSession(sessionCookie);
54
54
  var currentSessionId = currentSession.id;
55
55
  var expandOrRenewSession = (0, _tools.throttle)(function () {
56
+ sessionCookie.clearCache();
56
57
  var session = retrieveActiveSession(sessionCookie);
57
58
  var state = computeSessionState(session[productKey]);
58
59
  session[productKey] = state.trackingType;
@@ -72,6 +73,7 @@ function startSessionManagement(options, productKey, computeSessionState) {
72
73
  }, _cookie.COOKIE_ACCESS_DELAY);
73
74
 
74
75
  var expandSession = function expandSession() {
76
+ sessionCookie.clearCache();
75
77
  var session = retrieveActiveSession(sessionCookie);
76
78
  persistSession(session, sessionCookie);
77
79
  };
package/cjs/transport.js CHANGED
@@ -47,7 +47,10 @@ var HttpRequest = httpRequest;
47
47
  exports.HttpRequest = HttpRequest;
48
48
 
49
49
  var processedMessageByDataMap = function processedMessageByDataMap(message) {
50
- if (!message || !message.type) return '';
50
+ if (!message || !message.type) return {
51
+ rowStr: '',
52
+ rowData: undefined
53
+ };
51
54
  var rowData = {
52
55
  tags: {},
53
56
  fields: {}
@@ -1,6 +1,7 @@
1
- import { ONE_KILO_BYTE, ONE_SECOND, extend2Lev, isArray, includes } from './helper/tools';
1
+ import { ONE_KILO_BYTE, ONE_SECOND, extend2Lev, isArray, includes, isFunction, isBoolean, values } from './helper/tools';
2
2
  import { getCurrentSite } from './cookie';
3
3
  import { haveSameOrigin } from './helper/urlPolyfill';
4
+ import { TraceType } from './helper/enums';
4
5
  var TRIM_REGIX = /^\s+|\s+$/g;
5
6
  export var DEFAULT_CONFIGURATION = {
6
7
  resourceSampleRate: 100,
@@ -26,11 +27,21 @@ export var DEFAULT_CONFIGURATION = {
26
27
  batchBytesLimit: 16 * ONE_KILO_BYTE,
27
28
  datakitUrl: '',
28
29
  logsEndpoint: '',
30
+ traceType: TraceType.DDTRACE,
31
+ traceId128Bit: false,
29
32
  trackInteractions: false,
30
33
  //是否开启交互action收集
31
34
  allowedDDTracingOrigins: [],
32
- //
33
- beforeSend: function beforeSend(event) {}
35
+ //废弃
36
+ allowedTracingOrigins: [],
37
+ // 新增
38
+ isServiceSampling: false,
39
+ // 是否不抛弃采样是数据, 采用在服务端菜样的方式
40
+ beforeSend: function beforeSend(event) {},
41
+ isServerError: function isServerError(request) {
42
+ return false;
43
+ } // 判断请求是否为error 请求
44
+
34
45
  };
35
46
 
36
47
  function trim(str) {
@@ -76,7 +87,11 @@ export function commonInit(userConfiguration, buildEnv) {
76
87
  };
77
88
 
78
89
  if ('allowedDDTracingOrigins' in userConfiguration) {
79
- transportConfiguration.allowedDDTracingOrigins = userConfiguration.allowedDDTracingOrigins;
90
+ transportConfiguration.allowedTracingOrigins = userConfiguration.allowedDDTracingOrigins;
91
+ }
92
+
93
+ if ('allowedTracingOrigins' in userConfiguration) {
94
+ transportConfiguration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins;
80
95
  }
81
96
 
82
97
  if ('sampleRate' in userConfiguration) {
@@ -91,9 +106,30 @@ export function commonInit(userConfiguration, buildEnv) {
91
106
  transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
92
107
  }
93
108
 
109
+ if ('isServerError' in userConfiguration && isFunction(userConfiguration.isServerError) && isBoolean(userConfiguration.isServerError())) {
110
+ transportConfiguration.isServerError = userConfiguration.isServerError;
111
+ }
112
+
113
+ if ('traceId128Bit' in userConfiguration) {
114
+ transportConfiguration.traceId128Bit = !!userConfiguration.traceId128Bit;
115
+ }
116
+
117
+ if ('traceType' in userConfiguration && hasTraceType(userConfiguration.traceType)) {
118
+ transportConfiguration.traceType = userConfiguration.traceType;
119
+ }
120
+
121
+ if ('isServiceSampling' in userConfiguration && isBoolean(userConfiguration.isServiceSampling)) {
122
+ transportConfiguration.isServiceSampling = userConfiguration.isServiceSampling;
123
+ }
124
+
94
125
  return extend2Lev({}, DEFAULT_CONFIGURATION, transportConfiguration);
95
126
  }
96
127
 
128
+ function hasTraceType(traceType) {
129
+ if (traceType && values(TraceType).indexOf(traceType) > -1) return true;
130
+ return false;
131
+ }
132
+
97
133
  function mustUseSecureCookie(userConfiguration) {
98
134
  return !!userConfiguration.useSecureSessionCookie || !!userConfiguration.useCrossSiteSessionCookie;
99
135
  }
package/esm/cookie.js CHANGED
@@ -27,6 +27,10 @@ export function cacheCookieAccess(name, options) {
27
27
  setCookie(name, value, expireDelay, options);
28
28
  cache = value;
29
29
  cacheAccess();
30
+ },
31
+ clearCache: function clearCache() {
32
+ window.clearTimeout(timeout);
33
+ hasCache = false;
30
34
  }
31
35
  };
32
36
  }
package/esm/dataMap.js CHANGED
@@ -10,6 +10,7 @@ export var commonTags = {
10
10
  user_name: 'user.name',
11
11
  session_id: 'session.id',
12
12
  session_type: 'session.type',
13
+ session_sampling: 'session.is_sampling',
13
14
  is_signin: 'user.is_signin',
14
15
  os: 'device.os',
15
16
  os_version: 'device.os_version',
@@ -87,7 +87,7 @@ export function trackNetworkError(configuration, errorObservable) {
87
87
  });
88
88
 
89
89
  function handleCompleteRequest(type, request) {
90
- if (!isIntakeRequest(request.url, configuration) && (!configuration.isEnabled('remove-network-errors') || !request.isAborted) && (isRejected(request) || isServerError(request))) {
90
+ if (!isIntakeRequest(request.url, configuration) && !request.isAborted && (isRejected(request) || isServerError(request) || configuration.isServerError(request))) {
91
91
  errorObservable.notify({
92
92
  message: format(type) + ' error ' + request.method + ' ' + request.url,
93
93
  resource: {
@@ -42,4 +42,16 @@ export var RumEventType = {
42
42
  export var RequestType = {
43
43
  FETCH: ResourceType.FETCH,
44
44
  XHR: ResourceType.XHR
45
+ };
46
+ export var TraceType = {
47
+ DDTRACE: 'ddtrace',
48
+ ZIPKIN_MULTI_HEADER: 'zipkin',
49
+ ZIPKIN_SINGLE_HEADER: 'zipkin_single_header',
50
+ W3C_TRACEPARENT: 'w3c_traceparent',
51
+ SKYWALKING_V3: 'skywalking_v3',
52
+ JAEGER: 'jaeger'
53
+ };
54
+ export var ErrorHandling = {
55
+ HANDLED: 'handled',
56
+ UNHANDLED: 'unhandled'
45
57
  };
@@ -31,6 +31,7 @@ export function startSessionManagement(options, productKey, computeSessionState)
31
31
  var currentSession = retrieveActiveSession(sessionCookie);
32
32
  var currentSessionId = currentSession.id;
33
33
  var expandOrRenewSession = throttle(function () {
34
+ sessionCookie.clearCache();
34
35
  var session = retrieveActiveSession(sessionCookie);
35
36
  var state = computeSessionState(session[productKey]);
36
37
  session[productKey] = state.trackingType;
@@ -50,6 +51,7 @@ export function startSessionManagement(options, productKey, computeSessionState)
50
51
  }, COOKIE_ACCESS_DELAY);
51
52
 
52
53
  var expandSession = function expandSession() {
54
+ sessionCookie.clearCache();
53
55
  var session = retrieveActiveSession(sessionCookie);
54
56
  persistSession(session, sessionCookie);
55
57
  };
package/esm/transport.js CHANGED
@@ -35,7 +35,10 @@ httpRequest.prototype = {
35
35
  };
36
36
  export var HttpRequest = httpRequest;
37
37
  export var processedMessageByDataMap = function processedMessageByDataMap(message) {
38
- if (!message || !message.type) return '';
38
+ if (!message || !message.type) return {
39
+ rowStr: '',
40
+ rowData: undefined
41
+ };
39
42
  var rowData = {
40
43
  tags: {},
41
44
  fields: {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/browser-core",
3
- "version": "1.0.13",
3
+ "version": "1.0.16",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "scripts": {
@@ -20,5 +20,5 @@
20
20
  "author": "dataflux",
21
21
  "license": "MIT",
22
22
  "description": "DataFlux RUM Web 端数据指标监控",
23
- "gitHead": "666c0183f62de2c65313ff5cc2be75843aa95c25"
23
+ "gitHead": "82f05e083d4c4a86615dd759de38dda0674eb84f"
24
24
  }
@@ -3,10 +3,14 @@ import {
3
3
  ONE_SECOND,
4
4
  extend2Lev,
5
5
  isArray,
6
- includes
6
+ includes,
7
+ isFunction,
8
+ isBoolean,
9
+ values
7
10
  } from './helper/tools'
8
11
  import { getCurrentSite } from './cookie'
9
12
  import { haveSameOrigin } from './helper/urlPolyfill'
13
+ import { TraceType } from './helper/enums'
10
14
  var TRIM_REGIX = /^\s+|\s+$/g
11
15
  export var DEFAULT_CONFIGURATION = {
12
16
  resourceSampleRate: 100,
@@ -30,9 +34,14 @@ export var DEFAULT_CONFIGURATION = {
30
34
  batchBytesLimit: 16 * ONE_KILO_BYTE,
31
35
  datakitUrl: '',
32
36
  logsEndpoint: '',
37
+ traceType: TraceType.DDTRACE,
38
+ traceId128Bit: false,
33
39
  trackInteractions: false, //是否开启交互action收集
34
- allowedDDTracingOrigins: [], //
35
- beforeSend: function (event) {}
40
+ allowedDDTracingOrigins: [], //废弃
41
+ allowedTracingOrigins:[], // 新增
42
+ isServiceSampling: false, // 是否不抛弃采样是数据, 采用在服务端菜样的方式
43
+ beforeSend: function (event) {},
44
+ isServerError: function(request) {return false} // 判断请求是否为error 请求
36
45
  }
37
46
  function trim(str) {
38
47
  return str.replace(TRIM_REGIX, '')
@@ -78,10 +87,12 @@ export function commonInit(userConfiguration, buildEnv) {
78
87
  cookieOptions: buildCookieOptions(userConfiguration)
79
88
  }
80
89
  if ('allowedDDTracingOrigins' in userConfiguration) {
81
- transportConfiguration.allowedDDTracingOrigins =
90
+ transportConfiguration.allowedTracingOrigins =
82
91
  userConfiguration.allowedDDTracingOrigins
83
92
  }
84
-
93
+ if ('allowedTracingOrigins' in userConfiguration) {
94
+ transportConfiguration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins
95
+ }
85
96
  if ('sampleRate' in userConfiguration) {
86
97
  transportConfiguration.sampleRate = userConfiguration.sampleRate
87
98
  }
@@ -94,8 +105,24 @@ export function commonInit(userConfiguration, buildEnv) {
94
105
  if ('trackInteractions' in userConfiguration) {
95
106
  transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions
96
107
  }
108
+ if ('isServerError' in userConfiguration && isFunction(userConfiguration.isServerError) && isBoolean(userConfiguration.isServerError())) {
109
+ transportConfiguration.isServerError = userConfiguration.isServerError
110
+ }
111
+ if ('traceId128Bit' in userConfiguration) {
112
+ transportConfiguration.traceId128Bit = !!userConfiguration.traceId128Bit
113
+ }
114
+ if ('traceType' in userConfiguration && hasTraceType(userConfiguration.traceType)) {
115
+ transportConfiguration.traceType = userConfiguration.traceType
116
+ }
117
+ if ('isServiceSampling' in userConfiguration && isBoolean(userConfiguration.isServiceSampling)) {
118
+ transportConfiguration.isServiceSampling = userConfiguration.isServiceSampling
119
+ }
97
120
  return extend2Lev({}, DEFAULT_CONFIGURATION, transportConfiguration)
98
121
  }
122
+ function hasTraceType(traceType) {
123
+ if (traceType && values(TraceType).indexOf(traceType) > -1) return true
124
+ return false
125
+ }
99
126
  function mustUseSecureCookie(userConfiguration) {
100
127
  return (
101
128
  !!userConfiguration.useSecureSessionCookie ||
package/src/cookie.js CHANGED
@@ -26,7 +26,11 @@ export function cacheCookieAccess(name, options) {
26
26
  setCookie(name, value, expireDelay, options)
27
27
  cache = value
28
28
  cacheAccess()
29
- }
29
+ },
30
+ clearCache: function() {
31
+ window.clearTimeout(timeout)
32
+ hasCache = false
33
+ },
30
34
  }
31
35
  }
32
36
 
package/src/dataMap.js CHANGED
@@ -10,6 +10,7 @@ export var commonTags = {
10
10
  user_name: 'user.name',
11
11
  session_id: 'session.id',
12
12
  session_type: 'session.type',
13
+ session_sampling: 'session.is_sampling',
13
14
  is_signin: 'user.is_signin',
14
15
  os: 'device.os',
15
16
  os_version: 'device.os_version',
@@ -108,9 +108,8 @@ export function trackNetworkError(configuration, errorObservable) {
108
108
  function handleCompleteRequest(type, request) {
109
109
  if (
110
110
  !isIntakeRequest(request.url, configuration) &&
111
- (!configuration.isEnabled('remove-network-errors') ||
112
- !request.isAborted) &&
113
- (isRejected(request) || isServerError(request))
111
+ !request.isAborted &&
112
+ (isRejected(request) || isServerError(request) || configuration.isServerError(request))
114
113
  ) {
115
114
  errorObservable.notify({
116
115
  message: format(type) + ' error ' + request.method + ' ' + request.url,
@@ -45,3 +45,16 @@ export var RequestType = {
45
45
  FETCH: ResourceType.FETCH,
46
46
  XHR: ResourceType.XHR
47
47
  }
48
+
49
+ export var TraceType = {
50
+ DDTRACE: 'ddtrace',
51
+ ZIPKIN_MULTI_HEADER: 'zipkin',
52
+ ZIPKIN_SINGLE_HEADER: 'zipkin_single_header',
53
+ W3C_TRACEPARENT: 'w3c_traceparent',
54
+ SKYWALKING_V3: 'skywalking_v3',
55
+ JAEGER: 'jaeger',
56
+ }
57
+ export var ErrorHandling = {
58
+ HANDLED: 'handled',
59
+ UNHANDLED: 'unhandled',
60
+ }
@@ -41,6 +41,7 @@ export function startSessionManagement(
41
41
  var currentSession = retrieveActiveSession(sessionCookie)
42
42
  var currentSessionId = currentSession.id
43
43
  var expandOrRenewSession = throttle(function () {
44
+ sessionCookie.clearCache()
44
45
  var session = retrieveActiveSession(sessionCookie)
45
46
  var state = computeSessionState(session[productKey])
46
47
  session[productKey] = state.trackingType
@@ -59,6 +60,7 @@ export function startSessionManagement(
59
60
  }, COOKIE_ACCESS_DELAY)
60
61
 
61
62
  var expandSession = function () {
63
+ sessionCookie.clearCache()
62
64
  var session = retrieveActiveSession(sessionCookie)
63
65
  persistSession(session, sessionCookie)
64
66
  }
package/src/transport.js CHANGED
@@ -44,7 +44,10 @@ httpRequest.prototype = {
44
44
 
45
45
  export var HttpRequest = httpRequest
46
46
  export var processedMessageByDataMap = function (message) {
47
- if (!message || !message.type) return ''
47
+ if (!message || !message.type) return {
48
+ rowStr: '',
49
+ rowData: undefined
50
+ }
48
51
  var rowData = { tags: {}, fields: {} }
49
52
  var hasFileds = false
50
53
  var rowStr = ''
package/src/xhrProxy.js CHANGED
@@ -84,7 +84,6 @@ function proxyXhr() {
84
84
  response: _this.response,
85
85
  status: _this.status
86
86
  })
87
-
88
87
  each(onRequestCompleteCallbacks, function (callback) {
89
88
  callback(xhrCompleteContext, _this)
90
89
  })