@cloudcare/browser-core 3.2.26 → 3.2.29

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 (87) hide show
  1. package/cjs/browser/asyncClocks.js +0 -4
  2. package/cjs/browser/asyncClocks.js.map +1 -1
  3. package/cjs/configuration/configuration.js +1 -1
  4. package/cjs/configuration/configuration.js.map +1 -1
  5. package/cjs/configuration/remoteConfiguration.js +0 -85
  6. package/cjs/configuration/remoteConfiguration.js.map +1 -1
  7. package/cjs/configuration/transportConfiguration.js +0 -2
  8. package/cjs/configuration/transportConfiguration.js.map +1 -1
  9. package/cjs/dataMap.js +1 -2
  10. package/cjs/dataMap.js.map +1 -1
  11. package/cjs/helper/deviceInfo.js +2 -41
  12. package/cjs/helper/deviceInfo.js.map +1 -1
  13. package/cjs/helper/mobileUtil.js +2 -2
  14. package/cjs/helper/mobileUtil.js.map +1 -1
  15. package/cjs/helper/serialisation/rowData.js +0 -1
  16. package/cjs/helper/serialisation/rowData.js.map +1 -1
  17. package/cjs/helper/tools.js +6 -21
  18. package/cjs/helper/tools.js.map +1 -1
  19. package/cjs/index.js +7 -0
  20. package/cjs/index.js.map +1 -1
  21. package/cjs/session/sessionConstants.js +5 -1
  22. package/cjs/session/sessionConstants.js.map +1 -1
  23. package/cjs/session/sessionInCookie.js +1 -1
  24. package/cjs/session/sessionInCookie.js.map +1 -1
  25. package/cjs/session/sessionInLocalStorage.js +1 -1
  26. package/cjs/session/sessionInLocalStorage.js.map +1 -1
  27. package/cjs/session/sessionStore.js +18 -5
  28. package/cjs/session/sessionStore.js.map +1 -1
  29. package/cjs/session/sessionStoreOperations.js +34 -8
  30. package/cjs/session/sessionStoreOperations.js.map +1 -1
  31. package/cjs/transport/batch.js +9 -11
  32. package/cjs/transport/batch.js.map +1 -1
  33. package/cjs/transport/httpRequest.js +40 -6
  34. package/cjs/transport/httpRequest.js.map +1 -1
  35. package/esm/browser/asyncClocks.js +0 -4
  36. package/esm/browser/asyncClocks.js.map +1 -1
  37. package/esm/configuration/configuration.js +1 -1
  38. package/esm/configuration/configuration.js.map +1 -1
  39. package/esm/configuration/remoteConfiguration.js +0 -85
  40. package/esm/configuration/remoteConfiguration.js.map +1 -1
  41. package/esm/configuration/transportConfiguration.js +0 -2
  42. package/esm/configuration/transportConfiguration.js.map +1 -1
  43. package/esm/dataMap.js +1 -2
  44. package/esm/dataMap.js.map +1 -1
  45. package/esm/helper/deviceInfo.js +2 -41
  46. package/esm/helper/deviceInfo.js.map +1 -1
  47. package/esm/helper/mobileUtil.js +2 -2
  48. package/esm/helper/mobileUtil.js.map +1 -1
  49. package/esm/helper/serialisation/rowData.js +0 -1
  50. package/esm/helper/serialisation/rowData.js.map +1 -1
  51. package/esm/helper/tools.js +6 -21
  52. package/esm/helper/tools.js.map +1 -1
  53. package/esm/index.js +1 -1
  54. package/esm/index.js.map +1 -1
  55. package/esm/session/sessionConstants.js +4 -0
  56. package/esm/session/sessionConstants.js.map +1 -1
  57. package/esm/session/sessionInCookie.js +2 -2
  58. package/esm/session/sessionInCookie.js.map +1 -1
  59. package/esm/session/sessionInLocalStorage.js +2 -2
  60. package/esm/session/sessionInLocalStorage.js.map +1 -1
  61. package/esm/session/sessionStore.js +18 -5
  62. package/esm/session/sessionStore.js.map +1 -1
  63. package/esm/session/sessionStoreOperations.js +34 -9
  64. package/esm/session/sessionStoreOperations.js.map +1 -1
  65. package/esm/transport/batch.js +9 -11
  66. package/esm/transport/batch.js.map +1 -1
  67. package/esm/transport/httpRequest.js +40 -6
  68. package/esm/transport/httpRequest.js.map +1 -1
  69. package/package.json +23 -24
  70. package/src/browser/asyncClocks.js +0 -3
  71. package/src/configuration/configuration.js +1 -1
  72. package/src/configuration/remoteConfiguration.js +0 -84
  73. package/src/configuration/transportConfiguration.js +0 -2
  74. package/src/dataMap.js +2 -2
  75. package/src/helper/deviceInfo.js +9 -37
  76. package/src/helper/mobileUtil.js +2 -2
  77. package/src/helper/serialisation/rowData.js +0 -1
  78. package/src/helper/tools.js +6 -23
  79. package/src/index.js +2 -1
  80. package/src/session/sessionConstants.js +4 -0
  81. package/src/session/sessionInCookie.js +3 -2
  82. package/src/session/sessionInLocalStorage.js +4 -2
  83. package/src/session/sessionStore.js +27 -8
  84. package/src/session/sessionStoreOperations.js +31 -13
  85. package/src/transport/batch.js +9 -11
  86. package/src/transport/httpRequest.js +53 -14
  87. package/types/index.d.ts +72 -58
@@ -1,5 +1,6 @@
1
1
  import { clearInterval, setInterval } from '../helper/timer'
2
2
  import { Observable } from '../helper/observable'
3
+ import { display } from '../helper/display'
3
4
  import { ONE_SECOND, dateNow, throttle, UUID, assign } from '../helper/tools'
4
5
  import { selectCookieStrategy, initCookieStrategy } from './sessionInCookie'
5
6
  import {
@@ -13,6 +14,7 @@ import {
13
14
  selectLocalStorageStrategy
14
15
  } from './sessionInLocalStorage'
15
16
  import { processSessionStoreOperations } from './sessionStoreOperations'
17
+ import { SessionPersistence } from './sessionConstants'
16
18
 
17
19
  /**
18
20
  * Every second, the storage will be polled to check for any change that can occur
@@ -26,14 +28,31 @@ export const STORAGE_POLL_DELAY = ONE_SECOND
26
28
  * Else, checks if LocalStorage is allowed and available
27
29
  */
28
30
  export function selectSessionStoreStrategyType(initConfiguration) {
29
- let sessionStoreStrategyType = selectCookieStrategy(initConfiguration)
30
- if (
31
- !sessionStoreStrategyType &&
32
- initConfiguration.allowFallbackToLocalStorage
33
- ) {
34
- sessionStoreStrategyType = selectLocalStorageStrategy()
31
+ switch (initConfiguration.sessionPersistence) {
32
+ case SessionPersistence.COOKIE:
33
+ return selectCookieStrategy(initConfiguration)
34
+
35
+ case SessionPersistence.LOCAL_STORAGE:
36
+ return selectLocalStorageStrategy()
37
+
38
+ case undefined: {
39
+ let sessionStoreStrategyType = selectCookieStrategy(initConfiguration)
40
+ if (
41
+ !sessionStoreStrategyType &&
42
+ initConfiguration.allowFallbackToLocalStorage
43
+ ) {
44
+ sessionStoreStrategyType = selectLocalStorageStrategy()
45
+ }
46
+ return sessionStoreStrategyType
47
+ }
48
+
49
+ default:
50
+ display.error(
51
+ `Invalid session persistence '${String(
52
+ initConfiguration.sessionPersistence
53
+ )}'`
54
+ )
35
55
  }
36
- return sessionStoreStrategyType
37
56
  }
38
57
 
39
58
  /**
@@ -51,7 +70,7 @@ export function startSessionStore(
51
70
  const expireObservable = new Observable()
52
71
  const sessionStateUpdateObservable = new Observable()
53
72
  const sessionStoreStrategy =
54
- sessionStoreStrategyType.type === 'Cookie'
73
+ sessionStoreStrategyType.type === SessionPersistence.COOKIE
55
74
  ? initCookieStrategy(sessionStoreStrategyType.cookieOptions)
56
75
  : initLocalStorageStrategy()
57
76
  const { expireSession } = sessionStoreStrategy
@@ -1,13 +1,20 @@
1
1
  import { setTimeout } from '../helper/timer'
2
- import { UUID, assign } from '../helper/tools'
3
2
  import {
4
- expandSessionState,
5
- isSessionInExpiredState,
6
- isSessionInNotStartedState
7
- } from './sessionState'
8
-
3
+ UUID,
4
+ assign,
5
+ ONE_SECOND,
6
+ timeStampNow,
7
+ elapsed
8
+ } from '../helper/tools'
9
+ import { expandSessionState, isSessionInExpiredState } from './sessionState'
10
+ import { addTelemetryDebug } from '../telemetry/telemetry'
9
11
  export const LOCK_RETRY_DELAY = 10
10
12
  export const LOCK_MAX_TRIES = 100
13
+
14
+ // Locks should be hold for a few milliseconds top, just the time it takes to read and write a
15
+ // cookie. Using one second should be enough in most situations.
16
+ export const LOCK_EXPIRATION_DELAY = ONE_SECOND
17
+ const LOCK_SEPARATOR = '--'
11
18
  const bufferedOperations = []
12
19
  let ongoingOperations
13
20
 
@@ -21,15 +28,11 @@ export function processSessionStoreOperations(
21
28
  return persistSession(assign({}, session, { lock: currentLock }))
22
29
  }
23
30
  const retrieveStore = function () {
24
- const session = sessionStoreStrategy.retrieveSession()
25
- const lock = session.lock
26
- if (session.lock) {
27
- delete session.lock
28
- }
31
+ const { lock, ...session } = sessionStoreStrategy.retrieveSession()
29
32
 
30
33
  return {
31
34
  session,
32
- lock
35
+ lock: lock && !isLockExpired(lock) ? lock : undefined
33
36
  }
34
37
  }
35
38
 
@@ -41,6 +44,9 @@ export function processSessionStoreOperations(
41
44
  return
42
45
  }
43
46
  if (isLockEnabled && numberOfRetries >= LOCK_MAX_TRIES) {
47
+ addTelemetryDebug('Aborted session operation after max lock retries', {
48
+ currentStore: retrieveStore()
49
+ })
44
50
  next(sessionStoreStrategy)
45
51
  return
46
52
  }
@@ -53,7 +59,7 @@ export function processSessionStoreOperations(
53
59
  return
54
60
  }
55
61
  // acquire lock
56
- currentLock = UUID()
62
+ currentLock = createLock()
57
63
  persistWithLock(currentStore.session)
58
64
  // if lock is not acquired, retry later
59
65
  currentStore = retrieveStore()
@@ -120,3 +126,15 @@ function next(sessionStore) {
120
126
  processSessionStoreOperations(nextOperations, sessionStore)
121
127
  }
122
128
  }
129
+
130
+ export function createLock() {
131
+ return UUID() + LOCK_SEPARATOR + timeStampNow()
132
+ }
133
+
134
+ function isLockExpired(lock) {
135
+ const [, timeStamp] = lock.split(LOCK_SEPARATOR)
136
+ return (
137
+ !timeStamp ||
138
+ elapsed(Number(timeStamp), timeStampNow()) > LOCK_EXPIRATION_DELAY
139
+ )
140
+ }
@@ -39,7 +39,7 @@ export var processedMessageByDataMap = function (message) {
39
39
  rowData.measurement = key
40
40
  var tagsStr = []
41
41
  var tags = extend({}, commonTags, value.tags)
42
- var filterFileds = ['date', 'type', CUSTOM_KEYS] // 已经在datamap中定义过的fields和tags
42
+ var filterFileds = ['date', 'type', CUSTOM_KEYS]
43
43
  each(tags, function (value_path, _key) {
44
44
  var _value = findByPath(message, value_path)
45
45
  filterFileds.push(_key)
@@ -57,7 +57,7 @@ export var processedMessageByDataMap = function (message) {
57
57
  var _valueData = findByPath(message, value_path)
58
58
  filterFileds.push(_key)
59
59
  if (_valueData !== undefined && _valueData !== null) {
60
- rowData.fields[_key] = escapeJsonValue(_valueData) // 这里不需要转译
60
+ rowData.fields[_key] = escapeJsonValue(_valueData)
61
61
  fieldsStr.push(
62
62
  escapeRowData(_key) + '=' + escapeRowField(_valueData)
63
63
  )
@@ -66,7 +66,7 @@ export var processedMessageByDataMap = function (message) {
66
66
  var _valueData = findByPath(message, _value)
67
67
  filterFileds.push(_key)
68
68
  if (_valueData !== undefined && _valueData !== null) {
69
- rowData.fields[_key] = escapeJsonValue(_valueData) // 这里不需要转译
69
+ rowData.fields[_key] = escapeJsonValue(_valueData)
70
70
  fieldsStr.push(
71
71
  escapeRowData(_key) + '=' + escapeRowField(_valueData)
72
72
  )
@@ -78,15 +78,13 @@ export var processedMessageByDataMap = function (message) {
78
78
  isObject(message.context) &&
79
79
  !isEmptyObject(message.context)
80
80
  ) {
81
- // 自定义tag, 存储成field
82
81
  var _tagKeys = []
83
82
  each(message.context, function (_value, _key) {
84
- // 如果和之前tag重名,则舍弃
85
83
  if (filterFileds.indexOf(_key) > -1) return
86
84
  filterFileds.push(_key)
87
85
  if (_value !== undefined && _value !== null) {
88
86
  _tagKeys.push(_key)
89
- rowData.fields[_key] = escapeJsonValue(_value) // 这里不需要转译
87
+ rowData.fields[_key] = escapeJsonValue(_value)
90
88
  fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_value))
91
89
  }
92
90
  })
@@ -98,14 +96,13 @@ export var processedMessageByDataMap = function (message) {
98
96
  }
99
97
  }
100
98
  if (message.type === RumEventType.LOGGER) {
101
- // 这里处理日志类型数据自定义字段
102
99
  each(message, function (value, key) {
103
100
  if (
104
101
  filterFileds.indexOf(key) === -1 &&
105
102
  value !== undefined &&
106
103
  value !== null
107
104
  ) {
108
- rowData.fields[key] = escapeJsonValue(value) // 这里不需要转译
105
+ rowData.fields[key] = escapeJsonValue(value)
109
106
  fieldsStr.push(escapeRowData(key) + '=' + escapeRowField(value))
110
107
  }
111
108
  })
@@ -119,7 +116,7 @@ export var processedMessageByDataMap = function (message) {
119
116
  hasFileds = true
120
117
  }
121
118
  rowStr = rowStr + ' ' + message.date
122
- rowData.time = message.date // 这里不需要转译
119
+ rowData.time = message.date
123
120
  }
124
121
  })
125
122
  return {
@@ -231,7 +228,6 @@ export function createBatch(options) {
231
228
  // it and always send a single request.
232
229
  encoder.isAsync
233
230
  ) {
234
- // 咱不支持json 模式
235
231
  var encoderResult = encoder.finishSync()
236
232
 
237
233
  // Send encoded messages
@@ -296,6 +292,8 @@ function formatPayloadFromEncoder(encoderResult, sendContentTypeByJson) {
296
292
  data: data,
297
293
  type: sendContentTypeByJson ? 'application/json;UTF-8' : undefined,
298
294
  bytesCount: encoderResult.outputBytesCount,
299
- encoding: encoderResult.encoding
295
+ encoding: encoderResult.encoding,
296
+ outputBase64Head: encoderResult.outputBase64Head,
297
+ outputBase64Tail: encoderResult.outputBase64Tail
300
298
  }
301
299
  }
@@ -104,22 +104,33 @@ export function fetchKeepAliveStrategy(
104
104
  keepalive: true,
105
105
  mode: 'cors'
106
106
  }
107
+ const headers = {}
108
+
107
109
  if (payload.type) {
108
- fetchOption.headers = {
109
- 'Content-Type': payload.type
110
- }
110
+ headers['Content-Type'] = payload.type
111
111
  }
112
- fetch(url, fetchOption).then(
113
- monitor(function (response) {
114
- if (typeof onResponse === 'function') {
115
- onResponse({ status: response.status, type: response.type })
116
- }
117
- }),
118
- monitor(function () {
119
- // failed to queue the request
120
- sendXHR(url, payload, onResponse)
121
- })
122
- )
112
+ if (payload.outputBase64Head) {
113
+ headers['x-base64-head'] = payload.outputBase64Head
114
+ }
115
+ if (payload.outputBase64Tail) {
116
+ headers['x-base64-tail'] = payload.outputBase64Tail
117
+ }
118
+ if (Object.keys(headers).length) {
119
+ fetchOption.headers = headers
120
+ }
121
+ fetch(url, fetchOption)
122
+ .then(
123
+ monitor(function (response) {
124
+ if (typeof onResponse === 'function') {
125
+ onResponse({ status: response.status, type: response.type })
126
+ }
127
+ })
128
+ )
129
+ .catch(
130
+ monitor(function () {
131
+ fetchStrategy(url, payload, onResponse)
132
+ })
133
+ )
123
134
  } else {
124
135
  sendXHR(url, payload, onResponse)
125
136
  }
@@ -158,3 +169,31 @@ function sendXHR(url, payload, onResponse) {
158
169
  )
159
170
  request.send(data)
160
171
  }
172
+ function fetchStrategy(url, payload, onResponse) {
173
+ const fetchOption = {
174
+ method: 'POST',
175
+ body: payload.data,
176
+ keepalive: true,
177
+ mode: 'cors'
178
+ }
179
+ if (payload.type) {
180
+ fetchOption.headers = {
181
+ 'Content-Type': payload.type
182
+ }
183
+ }
184
+ fetch(url, fetchOption)
185
+ .then(
186
+ monitor(function (response) {
187
+ if (typeof onResponse === 'function') {
188
+ onResponse({ status: response.status, type: response.type })
189
+ }
190
+ })
191
+ )
192
+ .catch(
193
+ monitor(function () {
194
+ if (typeof onResponse === 'function') {
195
+ onResponse({ status: 0 })
196
+ }
197
+ })
198
+ )
199
+ }
package/types/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export interface User {
7
7
  name?: string | undefined
8
8
  [key: string]: unknown
9
9
  }
10
+ export type SessionPersistence = 'cookie' | 'local-storage'
11
+
10
12
  export declare const ConsoleApiName: {
11
13
  readonly log: 'log'
12
14
  readonly debug: 'debug'
@@ -25,72 +27,79 @@ export type RawReportType = (typeof RawReportType)[keyof typeof RawReportType]
25
27
 
26
28
  export interface SiteInitConfiguration {
27
29
  /**
28
- * openway 方式上报数据令牌,从观测云控制台获取,必填
30
+ * Data reporting token in openway mode, obtained from the TrueWatch Cloud console. Required.
29
31
  */
30
32
  clientToken: string | undefined
31
33
 
32
34
  /**
33
- * 公共openway 方式上报数据地址,从观测云控制台获取,必填
35
+ * Data reporting address in public openway mode, obtained from the TrueWatch Cloud console. Required.
34
36
  */
35
37
  site: string | undefined
36
38
  }
37
39
  export interface DatakitInitConfiguration {
38
- /** DataKit 数据上报 Origin 注释:
39
- * 协议(包括://),域名(或IP地址)[和端口号]
40
- * 例如:
41
- * https://www.datakit.com
42
- * http://100.20.34.3:8088
40
+ /** DataKit data reporting Origin:
41
+ * Protocol (including ://), domain name (or IP address) [and port number]
42
+ * For example:
43
+ * https://www.datakit.com;
44
+ * http://100.20.34.3:8088.
43
45
  */
44
46
  datakitOrigin: string
45
47
  }
46
48
  export interface InitConfiguration {
47
49
  /**
48
- * 数据发送前的的拦截器
49
- * @param event 事件内容
50
- * @param context 事件额外属性
50
+ * Interceptor before sending data
51
+ * @param event Event content
52
+ * @param context Additional event properties
51
53
  * @returns
52
54
  */
53
55
  beforeSend?: (event: any, context?: any) => unknown | undefined
54
56
  /**
55
- * 数据上报采样率,100 表示全收集;0 表示不收集。默认 100
57
+ * Data reporting sample rate, 100 means collect all; 0 means do not collect. Default is 100
56
58
  */
57
59
  sessionSampleRate?: number | undefined
58
60
  telemetrySampleRate?: number | undefined
59
61
  silentMultipleInit?: boolean | undefined
60
62
 
61
63
  service?: string | undefined
62
- /** Web 应用当前环境,如 prod:线上环境;gray:灰度环境;pre:预发布环境;common:日常环境;local:本地环境。 */
64
+ /** Current environment of the web application, such as prod: production; gray: gray environment; pre: pre-release; common: daily; local: local environment. */
63
65
  env?: string | undefined
64
- /** Web 应用的版本号。 */
66
+ /** Version number of the web application. */
65
67
  version?: string | undefined
66
- /** 链路数据采样百分比:100 表示全收集;0 表示不收集。 */
68
+ /** Trace data sampling percentage: 100 means collect all; 0 means do not collect. */
67
69
  tracingSampleRate?: number | undefined
68
70
  /**
69
71
  * @deprecated use usePartitionedCrossSiteSessionCookie instead
70
72
  */
71
73
  useCrossSiteSessionCookie?: boolean | undefined
72
74
  /**
73
- * 是否使用跨域 cookie,开启第三方 cookie 跨分区实现。默认不允许跨域,例如嵌套跨域 iframe 的情况。
75
+ * Whether to use cross-site cookies, enabling third-party cookie partitioning. By default, cross-site is not allowed, such as nested cross-domain iframes.
74
76
  */
75
77
  usePartitionedCrossSiteSessionCookie?: boolean | undefined
76
78
  useSecureSessionCookie?: boolean | undefined
77
79
  trackSessionAcrossSubdomains?: boolean | undefined
78
80
  /**
79
- * 是否把公共数据存储到localstorage,默认不存储
81
+ * Whether to store public data in localStorage, default is not to store
80
82
  */
81
83
  storeContextsToLocal?: boolean | undefined
82
84
  /**
83
- * 定义存储到 localstorage key ,默认不填,自动生成, 该参数主要是为了区分在同一个域名下,不同子路径共用store 的问题
85
+ * Define the key for storing in localStorage. If not filled, it is automatically generated. This parameter is mainly to distinguish the problem of sharing store under different subpaths of the same domain.
84
86
  */
85
87
  storeContextsKey?: string | undefined
86
88
  /**
87
- * 数据以 application/json 的发送方式,默认text
89
+ * Send data as application/json, default is text
88
90
  */
89
91
  sendContentTypeByJson?: boolean | undefined
90
92
  /**
91
- * cookie 不可用的情况下,可以开启该选项,把数据储存到 localstorage
93
+ * When cookies are not available, you can enable this option to store data in localStorage
92
94
  */
93
95
  allowFallbackToLocalStorage?: boolean | undefined
96
+ /**
97
+ * Which storage strategy to use for persisting sessions. Can be either 'cookie' or 'local-storage'.
98
+ *
99
+ * Important: If you are using the RUM and Logs Browser SDKs, this option must be configured with identical values
100
+ * @default "cookie"
101
+ */
102
+ sessionPersistence?: SessionPersistence | undefined
94
103
  }
95
104
  export enum TraceType {
96
105
  DDTRACE = 'ddtrace',
@@ -118,7 +127,7 @@ export const NodePrivacyLevel = {
118
127
  } as const
119
128
  export type NodePrivacyLevel =
120
129
  (typeof NodePrivacyLevel)[keyof typeof NodePrivacyLevel]
121
-
130
+ export type OriginMatchOption = string | RegExp
122
131
  export type MatchOption = string | RegExp | ((value: string) => boolean)
123
132
  export type TracingOption = {
124
133
  match: MatchOption
@@ -138,93 +147,98 @@ export declare function matchList(
138
147
  ): boolean
139
148
 
140
149
  export interface RumBaseInitConfiguration extends InitConfiguration {
141
- /**从观测云创建的应用 ID */
150
+ /** Application ID created from TrueWatch Cloud */
142
151
  applicationId: string
143
152
  /**
144
- * 排除一些影响 loadingtime 的指标准确性的url,具体可参考下面文档
145
- * https://docs.guance.com/security/page-performance/#_3
153
+ * Exclude some URLs that affect the accuracy of loadingtime indicators. See the following documentation for details:
154
+ * https://docs.truewatch.com/security/page-performance/#_3
146
155
  */
147
156
  excludedActivityUrls?: MatchOption[] | undefined
148
157
  /**
149
- * 允许注入 trace 采集器所需 header 头部的所有请求列表。可以是请求的 origin,也可以是正则,origin: 协议(包括://),域名(或IP地址)[和端口号]。例如:
150
- ["https://api.example.com", /https:\\/\\/.*\\.my-api-domain\\.com/]
151
- */
158
+ * List of all requests allowed to inject trace collector required headers. For example:
159
+ ["https://api.example.com/test", /https:\\/\\/.*\\.my-api-domain\\.com/, (url) => { return true }].
160
+ */
152
161
  allowedTracingUrls?: Array<MatchOption | TracingOption> | undefined
162
+ /**
163
+ * List of all requests allowed to inject trace collector required headers. Can be the request origin or a regex. Origin: protocol (including ://), domain name (or IP address) [and port number]. For example:
164
+ ["https://api.example.com", /https:\\/\\/.*\\.my-api-domain\\.com/].
165
+ */
166
+ allowedTracingOrigins?: Array<OriginMatchOption> | undefined
153
167
  defaultPrivacyLevel?: DefaultPrivacyLevel | undefined
154
168
  /**
155
- * 错误会话补偿采样率:
156
- * - 当会话未被 `sessionSampleRate` 采样时,若会话期间发生错误,则按此比例采集
157
- * 此类会话将在错误发生时开始记录事件,并持续记录直到会话结束。
158
- * - 取值范围 0-100100 表示全采错误会话,0 表示忽略错误会话
169
+ * Error session compensation sample rate:
170
+ * - When the session is not sampled by `sessionSampleRate`, if an error occurs during the session, it will be collected according to this ratio.
171
+ * Such sessions will start recording events when an error occurs and continue until the session ends.
172
+ * - Value range 0-100, 100 means collect all error sessions, 0 means ignore error sessions
159
173
  */
160
174
  sessionOnErrorSampleRate?: number | undefined
161
175
 
162
176
  /**
163
- * Session Replay 全量采集采样率:
164
- * - 用于控制所有会话重放的全量数据采集比例
165
- * - 取值范围 0-100100 表示全量采集,0 表示不采集
177
+ * Session Replay full collection sample rate:
178
+ * - Used to control the proportion of full data collection for all session replays
179
+ * - Value range 0-100, 100 means full collection, 0 means no collection
166
180
  **/
167
181
  sessionReplaySampleRate?: number | undefined
168
182
 
169
- /** 错误会话重放补偿采样率:
170
- * - 当会话未被 `sessionReplaySampleRate` 采样时,若会话期间发生错误,则按此比例采集
171
- * 此类回放将记录错误发生前最多一分钟的事件,并持续记录直到会话结束。
172
- 100 表示全收集;0 表示不收集。
173
- */
183
+ /** Error session replay compensation sample rate:
184
+ * - When the session is not sampled by `sessionReplaySampleRate`, if an error occurs during the session, it will be collected according to this ratio.
185
+ * Such replays will record up to one minute of events before the error occurs and continue recording until the session ends.
186
+ * 100 means collect all; 0 means do not collect.
187
+ */
174
188
  sessionReplayOnErrorSampleRate?: number | undefined
175
189
  /**
176
- * 是否开启用户行为采集。
190
+ * Whether to enable user interaction collection.
177
191
  */
178
192
  trackUserInteractions?: boolean | undefined
179
193
  /**
180
- * 指定 action 数据 name 获取方式,默认自动获取,可以指定元素特定属性名称,alt,name,title,aria-labelledby,aria-label,data-guance-action-name 这些属性
194
+ * Specify how to get the action data name. By default, it is obtained automatically. You can specify the element's specific attribute name, such as alt, name, title, aria-labelledby, aria-label, data-truewatch-action-name, etc.
181
195
  */
182
196
  actionNameAttribute?: string | undefined
183
197
  trackViewsManually?: boolean | undefined
184
198
  /**
185
- * sessionReplay compressIntakeRequests数据压缩都是在 webwork 线程中完成,所以默认情况下,需要在开启csp 安全访问的情况下,允许 worker-src blob:; workerUrl 配置允许自行托管 worker 地址
199
+ * sessionReplay and compressIntakeRequests data compression are both done in the web worker thread, so by default, you need to allow worker-src blob: under CSP security access, or use workerUrl to host the worker address yourself
186
200
  */
187
201
  workerUrl?: string
188
202
  /**
189
- * 压缩 RUM 数据请求内容,以减少发送大量数据时的带宽使用量。压缩在 Worker 线程中完成。
203
+ * Compress RUM data request content to reduce bandwidth usage when sending large amounts of data. Compression is done in the Worker thread.
190
204
  */
191
205
  compressIntakeRequests?: boolean | undefined
192
206
  /**
193
- * 是否开启数据采集的远程配置功能,默认不开启
194
- * 远程配置功能可以在不发布新版本的情况下,动态修改数据采集的配置项
195
- * 例如:可以在远程配置中修改采样率、是否开启用户行为采集等
196
- * 远程配置功能需要在观测云控制台中开启
207
+ * Whether to enable remote configuration for data collection. Disabled by default.
208
+ * The remote configuration feature allows you to dynamically modify data collection configuration items without releasing a new version.
209
+ * For example: you can modify the sampling rate, whether to enable user interaction collection, etc. in the remote configuration.
210
+ * The remote configuration feature needs to be enabled in the TrueWatch Cloud console.
197
211
  *
198
212
  */
199
213
  remoteConfiguration?: boolean | undefined
200
214
  /**
201
- * 配置链路追踪工具类型,如果不配置默认为 ddtrace。目前支持 ddtracezipkinskywalking_v3jaegerzipkin_single_headerw3c_traceparent 6 种数据类型。
215
+ * Configure the type of trace tool. If not configured, ddtrace is used by default. Currently supports 6 types: ddtrace, zipkin, skywalking_v3, jaeger, zipkin_single_header, w3c_traceparent.
202
216
  */
203
217
  traceType?: TraceType
204
218
  /**
205
- * 是否以 128 字节的方式生成 traceID,与 traceType 对应,目前支持类型 zipkinjaeger
219
+ * Whether to generate traceID in 128-bit mode, corresponding to traceType. Currently supported types: zipkin, jaeger.
206
220
  */
207
221
  traceId128Bit?: boolean | undefined
208
222
  /**
209
- * Fetch/Xhr 拦截之后,往请求 header 添加额外 header-key,受 allowedTracingUrls 影响
210
- * @param context 请求附带额外信息,包括traceid spanid url 等内容
211
- * @returns 返回 key: value 对象, 请求添加的额外 key
223
+ * After Fetch/Xhr interception, add extra header-keys to the request header, affected by allowedTracingUrls
224
+ * @param context Additional information attached to the request, including traceid, spanid, url, etc.
225
+ * @returns Returns a key: value object, the extra keys to be added to the request
212
226
  */
213
227
  injectTraceHeader?: (content: any) => { [key: string]: string } | undefined
214
228
  /**
215
- * traceId 生成器,覆盖 SDK 内部traceId 实现,默认不配置。
216
- * @returns 返回对应 traceType 类型的traceId。
229
+ * traceId generator, overrides the SDK's internal traceId implementation. Default is not configured.
230
+ * @returns Returns the traceId corresponding to the traceType type.
217
231
  */
218
232
  generateTraceId?: () => string
219
233
  /**
220
- * 是否开启 longAnimationFrame 采集,覆盖 longtask 采集,目前调试阶段
234
+ * Whether to enable longAnimationFrame collection, overriding longtask collection. Currently in debugging stage.
221
235
  */
222
236
  enableLongAnimationFrame?: boolean | undefined
223
237
  /**
224
- * session replay 是否屏蔽某个节点数据,可用于实现对某些特定 node 屏蔽效果
225
- * @param node 节点对象
226
- * @param privacyLevel 当前隐私等级
227
- * @returns true 表示屏蔽该节点,false 表示不屏蔽节点 继续执行 privacyLevel 逻辑
238
+ * Whether to mask a node's data in session replay, can be used to implement masking for specific nodes
239
+ * @param node Node object
240
+ * @param privacyLevel Current privacy level
241
+ * @returns true means mask the node, false means do not mask and continue privacyLevel logic
228
242
  */
229
243
  shouldMaskNode?: (node: Node, privacyLevel: NodePrivacyLevel) => boolean
230
244
  }