@cloudcare/browser-core 1.0.15 → 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,10 +41,16 @@ 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
- //
49
+ //废弃
50
+ allowedTracingOrigins: [],
51
+ // 新增
52
+ isServiceSampling: false,
53
+ // 是否不抛弃采样是数据, 采用在服务端菜样的方式
46
54
  beforeSend: function beforeSend(event) {},
47
55
  isServerError: function isServerError(request) {
48
56
  return false;
@@ -94,7 +102,11 @@ function commonInit(userConfiguration, buildEnv) {
94
102
  };
95
103
 
96
104
  if ('allowedDDTracingOrigins' in userConfiguration) {
97
- transportConfiguration.allowedDDTracingOrigins = userConfiguration.allowedDDTracingOrigins;
105
+ transportConfiguration.allowedTracingOrigins = userConfiguration.allowedDDTracingOrigins;
106
+ }
107
+
108
+ if ('allowedTracingOrigins' in userConfiguration) {
109
+ transportConfiguration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins;
98
110
  }
99
111
 
100
112
  if ('sampleRate' in userConfiguration) {
@@ -113,9 +125,26 @@ function commonInit(userConfiguration, buildEnv) {
113
125
  transportConfiguration.isServerError = userConfiguration.isServerError;
114
126
  }
115
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
+
116
140
  return (0, _tools.extend2Lev)({}, DEFAULT_CONFIGURATION, transportConfiguration);
117
141
  }
118
142
 
143
+ function hasTraceType(traceType) {
144
+ if (traceType && (0, _tools.values)(_enums.TraceType).indexOf(traceType) > -1) return true;
145
+ return false;
146
+ }
147
+
119
148
  function mustUseSecureCookie(userConfiguration) {
120
149
  return !!userConfiguration.useSecureSessionCookie || !!userConfiguration.useCrossSiteSessionCookie;
121
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',
@@ -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, isFunction, isBoolean } 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,10 +27,16 @@ 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
- //
35
+ //废弃
36
+ allowedTracingOrigins: [],
37
+ // 新增
38
+ isServiceSampling: false,
39
+ // 是否不抛弃采样是数据, 采用在服务端菜样的方式
33
40
  beforeSend: function beforeSend(event) {},
34
41
  isServerError: function isServerError(request) {
35
42
  return false;
@@ -80,7 +87,11 @@ export function commonInit(userConfiguration, buildEnv) {
80
87
  };
81
88
 
82
89
  if ('allowedDDTracingOrigins' in userConfiguration) {
83
- transportConfiguration.allowedDDTracingOrigins = userConfiguration.allowedDDTracingOrigins;
90
+ transportConfiguration.allowedTracingOrigins = userConfiguration.allowedDDTracingOrigins;
91
+ }
92
+
93
+ if ('allowedTracingOrigins' in userConfiguration) {
94
+ transportConfiguration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins;
84
95
  }
85
96
 
86
97
  if ('sampleRate' in userConfiguration) {
@@ -99,9 +110,26 @@ export function commonInit(userConfiguration, buildEnv) {
99
110
  transportConfiguration.isServerError = userConfiguration.isServerError;
100
111
  }
101
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
+
102
125
  return extend2Lev({}, DEFAULT_CONFIGURATION, transportConfiguration);
103
126
  }
104
127
 
128
+ function hasTraceType(traceType) {
129
+ if (traceType && values(TraceType).indexOf(traceType) > -1) return true;
130
+ return false;
131
+ }
132
+
105
133
  function mustUseSecureCookie(userConfiguration) {
106
134
  return !!userConfiguration.useSecureSessionCookie || !!userConfiguration.useCrossSiteSessionCookie;
107
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',
@@ -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.15",
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": "d8b3295bcb924ddd649b22ecffcf3ec6ccb4072d"
23
+ "gitHead": "82f05e083d4c4a86615dd759de38dda0674eb84f"
24
24
  }
@@ -5,10 +5,12 @@ import {
5
5
  isArray,
6
6
  includes,
7
7
  isFunction,
8
- isBoolean
8
+ isBoolean,
9
+ values
9
10
  } from './helper/tools'
10
11
  import { getCurrentSite } from './cookie'
11
12
  import { haveSameOrigin } from './helper/urlPolyfill'
13
+ import { TraceType } from './helper/enums'
12
14
  var TRIM_REGIX = /^\s+|\s+$/g
13
15
  export var DEFAULT_CONFIGURATION = {
14
16
  resourceSampleRate: 100,
@@ -32,8 +34,12 @@ export var DEFAULT_CONFIGURATION = {
32
34
  batchBytesLimit: 16 * ONE_KILO_BYTE,
33
35
  datakitUrl: '',
34
36
  logsEndpoint: '',
37
+ traceType: TraceType.DDTRACE,
38
+ traceId128Bit: false,
35
39
  trackInteractions: false, //是否开启交互action收集
36
- allowedDDTracingOrigins: [], //
40
+ allowedDDTracingOrigins: [], //废弃
41
+ allowedTracingOrigins:[], // 新增
42
+ isServiceSampling: false, // 是否不抛弃采样是数据, 采用在服务端菜样的方式
37
43
  beforeSend: function (event) {},
38
44
  isServerError: function(request) {return false} // 判断请求是否为error 请求
39
45
  }
@@ -81,10 +87,12 @@ export function commonInit(userConfiguration, buildEnv) {
81
87
  cookieOptions: buildCookieOptions(userConfiguration)
82
88
  }
83
89
  if ('allowedDDTracingOrigins' in userConfiguration) {
84
- transportConfiguration.allowedDDTracingOrigins =
90
+ transportConfiguration.allowedTracingOrigins =
85
91
  userConfiguration.allowedDDTracingOrigins
86
92
  }
87
-
93
+ if ('allowedTracingOrigins' in userConfiguration) {
94
+ transportConfiguration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins
95
+ }
88
96
  if ('sampleRate' in userConfiguration) {
89
97
  transportConfiguration.sampleRate = userConfiguration.sampleRate
90
98
  }
@@ -100,8 +108,21 @@ export function commonInit(userConfiguration, buildEnv) {
100
108
  if ('isServerError' in userConfiguration && isFunction(userConfiguration.isServerError) && isBoolean(userConfiguration.isServerError())) {
101
109
  transportConfiguration.isServerError = userConfiguration.isServerError
102
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
+ }
103
120
  return extend2Lev({}, DEFAULT_CONFIGURATION, transportConfiguration)
104
121
  }
122
+ function hasTraceType(traceType) {
123
+ if (traceType && values(TraceType).indexOf(traceType) > -1) return true
124
+ return false
125
+ }
105
126
  function mustUseSecureCookie(userConfiguration) {
106
127
  return (
107
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',
@@ -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 = ''