@be-link/cls-logger 1.0.3 → 1.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/README.md +62 -8
- package/dist/ClsLogger.d.ts.map +1 -1
- package/dist/ClsLoggerCore.d.ts +1 -0
- package/dist/ClsLoggerCore.d.ts.map +1 -1
- package/dist/index.esm.js +25 -11
- package/dist/index.js +25 -11
- package/dist/index.umd.js +25 -11
- package/dist/mini.esm.js +23 -9
- package/dist/mini.js +23 -9
- package/dist/types.d.ts +19 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/web.esm.js +23 -9
- package/dist/web.js +23 -9
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -6,9 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
pnpm add @be-link/cls-logger
|
|
9
|
+
# H5/Web 项目还需要安装:
|
|
10
|
+
pnpm add tencentcloud-cls-sdk-js-web
|
|
11
|
+
# 小程序项目还需要安装:
|
|
12
|
+
pnpm add tencentcloud-cls-sdk-js-mini
|
|
9
13
|
```
|
|
10
14
|
|
|
11
|
-
>
|
|
15
|
+
> **注意**:从 v1.0.3 开始,为了减小小程序和 H5 项目的体积,腾讯云 SDK 已改为 `peerDependencies`。请根据你的运行环境手动安装对应的 SDK。 SDK 内部仍会自动根据运行环境加载对应的 SDK。
|
|
12
16
|
|
|
13
17
|
## 使用
|
|
14
18
|
|
|
@@ -19,16 +23,33 @@ import clsLogger from '@be-link/cls-logger';
|
|
|
19
23
|
|
|
20
24
|
// 1. 初始化(建议在应用入口处调用)
|
|
21
25
|
clsLogger.init({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
projectName: 'be-link-pandora',
|
|
27
|
+
appId: 'be-link-pandora',
|
|
28
|
+
appVersion: getCurrentVersion(),
|
|
29
|
+
envType: 'browser',
|
|
30
|
+
generateBaseFields: () => {
|
|
31
|
+
return {
|
|
32
|
+
userId: getUserInfo().id,
|
|
33
|
+
userName: getUserInfo().name,
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
performanceMonitor: {
|
|
38
|
+
ignoreUrls: ['http://localhost:3000'],
|
|
39
|
+
},
|
|
40
|
+
requestMonitor: {
|
|
41
|
+
ignoreUrls: ['http://localhost:3000'],
|
|
42
|
+
},
|
|
43
|
+
tencentCloud: {
|
|
44
|
+
endpoint: 'https://ap-shanghai.cls.tencentcs.com',
|
|
45
|
+
topicID: '17475bcd-6315-4b20-859c-e7b087fb3683',
|
|
46
|
+
retry_times: 3,
|
|
47
|
+
source: 'be-link-pandora',
|
|
48
|
+
},
|
|
26
49
|
});
|
|
27
50
|
|
|
28
|
-
//
|
|
29
|
-
// Info 日志
|
|
51
|
+
// 开发日志: info warn error 日志
|
|
30
52
|
clsLogger.info('应用启动', { startUpTime: 120 });
|
|
31
|
-
|
|
32
53
|
// Error 日志(支持直接传入 Error 对象,自动解析堆栈)
|
|
33
54
|
try {
|
|
34
55
|
doSomething();
|
|
@@ -82,6 +103,39 @@ clsLogger.init({
|
|
|
82
103
|
- 自动生成/持久化 UV ID。
|
|
83
104
|
- 支持点击事件自动上报(需配置)。
|
|
84
105
|
|
|
106
|
+
#### 自动上报点击事件(Click Tracking)
|
|
107
|
+
|
|
108
|
+
SDK 会自动监听点击事件,并上报带有 `track-id` 的元素点击。
|
|
109
|
+
|
|
110
|
+
**Web / H5**:
|
|
111
|
+
|
|
112
|
+
在需要追踪的元素上添加 `data-track-id` 属性即可。
|
|
113
|
+
|
|
114
|
+
```html
|
|
115
|
+
<button data-track-id="submit_order_btn">提交订单</button>
|
|
116
|
+
<div data-track-id="banner_ad">广告位</div>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**小程序 (Mini Program)**:
|
|
120
|
+
|
|
121
|
+
在组件上添加 `data-track-id` 属性。
|
|
122
|
+
|
|
123
|
+
```html
|
|
124
|
+
<view data-track-id="product_card" bindtap="onProductClick"> 商品卡片 </view>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
> **注意**:如果不设置 `data-track-id`,SDK 默认会忽略 `body`, `html` (Web) 或 `view`, `scroll-view` (小程序) 等容器标签的点击,避免产生大量无意义的点击日志。
|
|
128
|
+
|
|
129
|
+
你也可以自定义属性名(Web 默认为 `data-track-id`,小程序默认为 `data-trackId`):
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
clsLogger.init({
|
|
133
|
+
behaviorMonitor: {
|
|
134
|
+
clickTrackIdAttr: 'data-my-track-id', // Web 自定义属性名
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
85
139
|
## 高级用法
|
|
86
140
|
|
|
87
141
|
### 手动注入 SDK
|
package/dist/ClsLogger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClsLogger.d.ts","sourceRoot":"","sources":["../src/ClsLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGlD;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,aAAa;cAC1B,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"ClsLogger.d.ts","sourceRoot":"","sources":["../src/ClsLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGlD;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,aAAa;cAC1B,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC;CAwHjD"}
|
package/dist/ClsLoggerCore.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare abstract class ClsLoggerCore {
|
|
|
21
21
|
protected endpoint: string;
|
|
22
22
|
protected retryTimes: number;
|
|
23
23
|
protected source: string;
|
|
24
|
+
protected enabled: boolean;
|
|
24
25
|
protected projectId: string;
|
|
25
26
|
protected projectName: string;
|
|
26
27
|
protected appId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClsLoggerCore.d.ts","sourceRoot":"","sources":["../src/ClsLoggerCore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EAEpB,OAAO,EACP,UAAU,EAEV,UAAU,EACV,SAAS,EACT,SAAS,EAEV,MAAM,SAAS,CAAC;AAgBjB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAYlD;;;;;GAKG;AACH,8BAAsB,aAAa;IACjC,SAAS,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,CAAQ;IAC1C,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAQ;IAC1D,SAAS,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CAAQ;IAC7C,SAAS,CAAC,iBAAiB,EAAE,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAQ;IAC9E,SAAS,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAA;KAAE,GAAG,IAAI,CAAQ;IAC9F,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAA;KAAE,CAAC,GAAG,IAAI,CAAQ;IAC9G,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAQ;IACxC,SAAS,CAAC,QAAQ,SAAmC;IACrD,SAAS,CAAC,UAAU,SAAM;IAC1B,SAAS,CAAC,MAAM,SAAe;
|
|
1
|
+
{"version":3,"file":"ClsLoggerCore.d.ts","sourceRoot":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E,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,IAAI;CAcjG"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1886,6 +1886,7 @@ class ClsLoggerCore {
|
|
|
1886
1886
|
this.endpoint = 'ap-shanghai.cls.tencentcs.com';
|
|
1887
1887
|
this.retryTimes = 10;
|
|
1888
1888
|
this.source = '127.0.0.1';
|
|
1889
|
+
this.enabled = true;
|
|
1889
1890
|
this.projectId = '';
|
|
1890
1891
|
this.projectName = '';
|
|
1891
1892
|
this.appId = '';
|
|
@@ -1961,6 +1962,7 @@ class ClsLoggerCore {
|
|
|
1961
1962
|
this.appId = options.appId ?? this.appId;
|
|
1962
1963
|
this.appVersion = options.appVersion ?? this.appVersion;
|
|
1963
1964
|
this.envType = nextEnvType;
|
|
1965
|
+
this.enabled = options.enabled ?? true;
|
|
1964
1966
|
// 可选:外部注入 SDK(优先级:sdkLoader > sdk)
|
|
1965
1967
|
this.sdkLoaderOverride = options.sdkLoader ?? this.sdkLoaderOverride;
|
|
1966
1968
|
this.sdkOverride = options.sdk ?? this.sdkOverride;
|
|
@@ -1977,15 +1979,17 @@ class ClsLoggerCore {
|
|
|
1977
1979
|
void this.getInstance().catch(() => {
|
|
1978
1980
|
// ignore
|
|
1979
1981
|
});
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1982
|
+
if (this.enabled) {
|
|
1983
|
+
// 启动时尝试发送失败缓存
|
|
1984
|
+
this.flushFailed();
|
|
1985
|
+
// 初始化后立即启动请求监听
|
|
1986
|
+
this.startRequestMonitor(options.requestMonitor);
|
|
1987
|
+
// 初始化后立即启动错误监控/性能监控
|
|
1988
|
+
this.startErrorMonitor(options.errorMonitor);
|
|
1989
|
+
this.startPerformanceMonitor(options.performanceMonitor);
|
|
1990
|
+
// 初始化后立即启动行为埋点(PV/UV/点击)
|
|
1991
|
+
this.startBehaviorMonitor(options.behaviorMonitor);
|
|
1992
|
+
}
|
|
1989
1993
|
}
|
|
1990
1994
|
getBaseFields() {
|
|
1991
1995
|
let auto = undefined;
|
|
@@ -2110,6 +2114,8 @@ class ClsLoggerCore {
|
|
|
2110
2114
|
* - 最终会把 fields 展开成 CLS 的 content(key/value 都会转成 string)
|
|
2111
2115
|
*/
|
|
2112
2116
|
put(fields, options = {}) {
|
|
2117
|
+
if (!this.enabled)
|
|
2118
|
+
return;
|
|
2113
2119
|
if (!fields)
|
|
2114
2120
|
return;
|
|
2115
2121
|
if (!this.topicId) {
|
|
@@ -2168,6 +2174,8 @@ class ClsLoggerCore {
|
|
|
2168
2174
|
* - 埋点入参必须是一维(扁平)Object,非原始值会被 stringify
|
|
2169
2175
|
*/
|
|
2170
2176
|
enqueue(fields, options = {}) {
|
|
2177
|
+
if (!this.enabled)
|
|
2178
|
+
return;
|
|
2171
2179
|
if (!fields)
|
|
2172
2180
|
return;
|
|
2173
2181
|
const time = Date.now();
|
|
@@ -2206,6 +2214,8 @@ class ClsLoggerCore {
|
|
|
2206
2214
|
* 批量上报(每条 item.data 展开为 log content)
|
|
2207
2215
|
*/
|
|
2208
2216
|
putBatch(queue) {
|
|
2217
|
+
if (!this.enabled)
|
|
2218
|
+
return;
|
|
2209
2219
|
if (!queue || queue.length === 0)
|
|
2210
2220
|
return;
|
|
2211
2221
|
if (!this.topicId) {
|
|
@@ -2249,6 +2259,8 @@ class ClsLoggerCore {
|
|
|
2249
2259
|
* 参考《一、概述》:统一上报入口(内存队列 + 批量发送)
|
|
2250
2260
|
*/
|
|
2251
2261
|
report(log) {
|
|
2262
|
+
if (!this.enabled)
|
|
2263
|
+
return;
|
|
2252
2264
|
if (!log?.type)
|
|
2253
2265
|
return;
|
|
2254
2266
|
if (!this.topicId) {
|
|
@@ -2453,6 +2465,8 @@ class ClsLoggerCore {
|
|
|
2453
2465
|
writeStringStorage(this.failedCacheKey, JSON.stringify(next));
|
|
2454
2466
|
}
|
|
2455
2467
|
flushFailed() {
|
|
2468
|
+
if (!this.enabled)
|
|
2469
|
+
return;
|
|
2456
2470
|
const raw = readStringStorage(this.failedCacheKey);
|
|
2457
2471
|
if (!raw)
|
|
2458
2472
|
return;
|
|
@@ -2621,7 +2635,7 @@ class ClsLogger extends ClsLoggerCore {
|
|
|
2621
2635
|
})
|
|
2622
2636
|
.catch((err) => {
|
|
2623
2637
|
this.sdkPromise = null;
|
|
2624
|
-
console.error('[ClsLogger] Failed to load mini sdk
|
|
2638
|
+
console.error('[ClsLogger] Failed to load mini sdk. Please ensure "tencentcloud-cls-sdk-js-mini" is installed in your project.', err);
|
|
2625
2639
|
throw err;
|
|
2626
2640
|
});
|
|
2627
2641
|
}
|
|
@@ -2636,7 +2650,7 @@ class ClsLogger extends ClsLoggerCore {
|
|
|
2636
2650
|
})
|
|
2637
2651
|
.catch((err) => {
|
|
2638
2652
|
this.sdkPromise = null;
|
|
2639
|
-
console.error('[ClsLogger] Failed to load web sdk
|
|
2653
|
+
console.error('[ClsLogger] Failed to load web sdk. Please ensure "tencentcloud-cls-sdk-js-web" is installed in your project.', err);
|
|
2640
2654
|
throw err;
|
|
2641
2655
|
});
|
|
2642
2656
|
}
|
package/dist/index.js
CHANGED
|
@@ -1890,6 +1890,7 @@ class ClsLoggerCore {
|
|
|
1890
1890
|
this.endpoint = 'ap-shanghai.cls.tencentcs.com';
|
|
1891
1891
|
this.retryTimes = 10;
|
|
1892
1892
|
this.source = '127.0.0.1';
|
|
1893
|
+
this.enabled = true;
|
|
1893
1894
|
this.projectId = '';
|
|
1894
1895
|
this.projectName = '';
|
|
1895
1896
|
this.appId = '';
|
|
@@ -1965,6 +1966,7 @@ class ClsLoggerCore {
|
|
|
1965
1966
|
this.appId = options.appId ?? this.appId;
|
|
1966
1967
|
this.appVersion = options.appVersion ?? this.appVersion;
|
|
1967
1968
|
this.envType = nextEnvType;
|
|
1969
|
+
this.enabled = options.enabled ?? true;
|
|
1968
1970
|
// 可选:外部注入 SDK(优先级:sdkLoader > sdk)
|
|
1969
1971
|
this.sdkLoaderOverride = options.sdkLoader ?? this.sdkLoaderOverride;
|
|
1970
1972
|
this.sdkOverride = options.sdk ?? this.sdkOverride;
|
|
@@ -1981,15 +1983,17 @@ class ClsLoggerCore {
|
|
|
1981
1983
|
void this.getInstance().catch(() => {
|
|
1982
1984
|
// ignore
|
|
1983
1985
|
});
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1986
|
+
if (this.enabled) {
|
|
1987
|
+
// 启动时尝试发送失败缓存
|
|
1988
|
+
this.flushFailed();
|
|
1989
|
+
// 初始化后立即启动请求监听
|
|
1990
|
+
this.startRequestMonitor(options.requestMonitor);
|
|
1991
|
+
// 初始化后立即启动错误监控/性能监控
|
|
1992
|
+
this.startErrorMonitor(options.errorMonitor);
|
|
1993
|
+
this.startPerformanceMonitor(options.performanceMonitor);
|
|
1994
|
+
// 初始化后立即启动行为埋点(PV/UV/点击)
|
|
1995
|
+
this.startBehaviorMonitor(options.behaviorMonitor);
|
|
1996
|
+
}
|
|
1993
1997
|
}
|
|
1994
1998
|
getBaseFields() {
|
|
1995
1999
|
let auto = undefined;
|
|
@@ -2114,6 +2118,8 @@ class ClsLoggerCore {
|
|
|
2114
2118
|
* - 最终会把 fields 展开成 CLS 的 content(key/value 都会转成 string)
|
|
2115
2119
|
*/
|
|
2116
2120
|
put(fields, options = {}) {
|
|
2121
|
+
if (!this.enabled)
|
|
2122
|
+
return;
|
|
2117
2123
|
if (!fields)
|
|
2118
2124
|
return;
|
|
2119
2125
|
if (!this.topicId) {
|
|
@@ -2172,6 +2178,8 @@ class ClsLoggerCore {
|
|
|
2172
2178
|
* - 埋点入参必须是一维(扁平)Object,非原始值会被 stringify
|
|
2173
2179
|
*/
|
|
2174
2180
|
enqueue(fields, options = {}) {
|
|
2181
|
+
if (!this.enabled)
|
|
2182
|
+
return;
|
|
2175
2183
|
if (!fields)
|
|
2176
2184
|
return;
|
|
2177
2185
|
const time = Date.now();
|
|
@@ -2210,6 +2218,8 @@ class ClsLoggerCore {
|
|
|
2210
2218
|
* 批量上报(每条 item.data 展开为 log content)
|
|
2211
2219
|
*/
|
|
2212
2220
|
putBatch(queue) {
|
|
2221
|
+
if (!this.enabled)
|
|
2222
|
+
return;
|
|
2213
2223
|
if (!queue || queue.length === 0)
|
|
2214
2224
|
return;
|
|
2215
2225
|
if (!this.topicId) {
|
|
@@ -2253,6 +2263,8 @@ class ClsLoggerCore {
|
|
|
2253
2263
|
* 参考《一、概述》:统一上报入口(内存队列 + 批量发送)
|
|
2254
2264
|
*/
|
|
2255
2265
|
report(log) {
|
|
2266
|
+
if (!this.enabled)
|
|
2267
|
+
return;
|
|
2256
2268
|
if (!log?.type)
|
|
2257
2269
|
return;
|
|
2258
2270
|
if (!this.topicId) {
|
|
@@ -2457,6 +2469,8 @@ class ClsLoggerCore {
|
|
|
2457
2469
|
writeStringStorage(this.failedCacheKey, JSON.stringify(next));
|
|
2458
2470
|
}
|
|
2459
2471
|
flushFailed() {
|
|
2472
|
+
if (!this.enabled)
|
|
2473
|
+
return;
|
|
2460
2474
|
const raw = readStringStorage(this.failedCacheKey);
|
|
2461
2475
|
if (!raw)
|
|
2462
2476
|
return;
|
|
@@ -2625,7 +2639,7 @@ class ClsLogger extends ClsLoggerCore {
|
|
|
2625
2639
|
})
|
|
2626
2640
|
.catch((err) => {
|
|
2627
2641
|
this.sdkPromise = null;
|
|
2628
|
-
console.error('[ClsLogger] Failed to load mini sdk
|
|
2642
|
+
console.error('[ClsLogger] Failed to load mini sdk. Please ensure "tencentcloud-cls-sdk-js-mini" is installed in your project.', err);
|
|
2629
2643
|
throw err;
|
|
2630
2644
|
});
|
|
2631
2645
|
}
|
|
@@ -2640,7 +2654,7 @@ class ClsLogger extends ClsLoggerCore {
|
|
|
2640
2654
|
})
|
|
2641
2655
|
.catch((err) => {
|
|
2642
2656
|
this.sdkPromise = null;
|
|
2643
|
-
console.error('[ClsLogger] Failed to load web sdk
|
|
2657
|
+
console.error('[ClsLogger] Failed to load web sdk. Please ensure "tencentcloud-cls-sdk-js-web" is installed in your project.', err);
|
|
2644
2658
|
throw err;
|
|
2645
2659
|
});
|
|
2646
2660
|
}
|
package/dist/index.umd.js
CHANGED
|
@@ -1892,6 +1892,7 @@
|
|
|
1892
1892
|
this.endpoint = 'ap-shanghai.cls.tencentcs.com';
|
|
1893
1893
|
this.retryTimes = 10;
|
|
1894
1894
|
this.source = '127.0.0.1';
|
|
1895
|
+
this.enabled = true;
|
|
1895
1896
|
this.projectId = '';
|
|
1896
1897
|
this.projectName = '';
|
|
1897
1898
|
this.appId = '';
|
|
@@ -1967,6 +1968,7 @@
|
|
|
1967
1968
|
this.appId = options.appId ?? this.appId;
|
|
1968
1969
|
this.appVersion = options.appVersion ?? this.appVersion;
|
|
1969
1970
|
this.envType = nextEnvType;
|
|
1971
|
+
this.enabled = options.enabled ?? true;
|
|
1970
1972
|
// 可选:外部注入 SDK(优先级:sdkLoader > sdk)
|
|
1971
1973
|
this.sdkLoaderOverride = options.sdkLoader ?? this.sdkLoaderOverride;
|
|
1972
1974
|
this.sdkOverride = options.sdk ?? this.sdkOverride;
|
|
@@ -1983,15 +1985,17 @@
|
|
|
1983
1985
|
void this.getInstance().catch(() => {
|
|
1984
1986
|
// ignore
|
|
1985
1987
|
});
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1988
|
+
if (this.enabled) {
|
|
1989
|
+
// 启动时尝试发送失败缓存
|
|
1990
|
+
this.flushFailed();
|
|
1991
|
+
// 初始化后立即启动请求监听
|
|
1992
|
+
this.startRequestMonitor(options.requestMonitor);
|
|
1993
|
+
// 初始化后立即启动错误监控/性能监控
|
|
1994
|
+
this.startErrorMonitor(options.errorMonitor);
|
|
1995
|
+
this.startPerformanceMonitor(options.performanceMonitor);
|
|
1996
|
+
// 初始化后立即启动行为埋点(PV/UV/点击)
|
|
1997
|
+
this.startBehaviorMonitor(options.behaviorMonitor);
|
|
1998
|
+
}
|
|
1995
1999
|
}
|
|
1996
2000
|
getBaseFields() {
|
|
1997
2001
|
let auto = undefined;
|
|
@@ -2116,6 +2120,8 @@
|
|
|
2116
2120
|
* - 最终会把 fields 展开成 CLS 的 content(key/value 都会转成 string)
|
|
2117
2121
|
*/
|
|
2118
2122
|
put(fields, options = {}) {
|
|
2123
|
+
if (!this.enabled)
|
|
2124
|
+
return;
|
|
2119
2125
|
if (!fields)
|
|
2120
2126
|
return;
|
|
2121
2127
|
if (!this.topicId) {
|
|
@@ -2174,6 +2180,8 @@
|
|
|
2174
2180
|
* - 埋点入参必须是一维(扁平)Object,非原始值会被 stringify
|
|
2175
2181
|
*/
|
|
2176
2182
|
enqueue(fields, options = {}) {
|
|
2183
|
+
if (!this.enabled)
|
|
2184
|
+
return;
|
|
2177
2185
|
if (!fields)
|
|
2178
2186
|
return;
|
|
2179
2187
|
const time = Date.now();
|
|
@@ -2212,6 +2220,8 @@
|
|
|
2212
2220
|
* 批量上报(每条 item.data 展开为 log content)
|
|
2213
2221
|
*/
|
|
2214
2222
|
putBatch(queue) {
|
|
2223
|
+
if (!this.enabled)
|
|
2224
|
+
return;
|
|
2215
2225
|
if (!queue || queue.length === 0)
|
|
2216
2226
|
return;
|
|
2217
2227
|
if (!this.topicId) {
|
|
@@ -2255,6 +2265,8 @@
|
|
|
2255
2265
|
* 参考《一、概述》:统一上报入口(内存队列 + 批量发送)
|
|
2256
2266
|
*/
|
|
2257
2267
|
report(log) {
|
|
2268
|
+
if (!this.enabled)
|
|
2269
|
+
return;
|
|
2258
2270
|
if (!log?.type)
|
|
2259
2271
|
return;
|
|
2260
2272
|
if (!this.topicId) {
|
|
@@ -2459,6 +2471,8 @@
|
|
|
2459
2471
|
writeStringStorage(this.failedCacheKey, JSON.stringify(next));
|
|
2460
2472
|
}
|
|
2461
2473
|
flushFailed() {
|
|
2474
|
+
if (!this.enabled)
|
|
2475
|
+
return;
|
|
2462
2476
|
const raw = readStringStorage(this.failedCacheKey);
|
|
2463
2477
|
if (!raw)
|
|
2464
2478
|
return;
|
|
@@ -2627,7 +2641,7 @@
|
|
|
2627
2641
|
})
|
|
2628
2642
|
.catch((err) => {
|
|
2629
2643
|
this.sdkPromise = null;
|
|
2630
|
-
console.error('[ClsLogger] Failed to load mini sdk
|
|
2644
|
+
console.error('[ClsLogger] Failed to load mini sdk. Please ensure "tencentcloud-cls-sdk-js-mini" is installed in your project.', err);
|
|
2631
2645
|
throw err;
|
|
2632
2646
|
});
|
|
2633
2647
|
}
|
|
@@ -2642,7 +2656,7 @@
|
|
|
2642
2656
|
})
|
|
2643
2657
|
.catch((err) => {
|
|
2644
2658
|
this.sdkPromise = null;
|
|
2645
|
-
console.error('[ClsLogger] Failed to load web sdk
|
|
2659
|
+
console.error('[ClsLogger] Failed to load web sdk. Please ensure "tencentcloud-cls-sdk-js-web" is installed in your project.', err);
|
|
2646
2660
|
throw err;
|
|
2647
2661
|
});
|
|
2648
2662
|
}
|
package/dist/mini.esm.js
CHANGED
|
@@ -1888,6 +1888,7 @@ class ClsLoggerCore {
|
|
|
1888
1888
|
this.endpoint = 'ap-shanghai.cls.tencentcs.com';
|
|
1889
1889
|
this.retryTimes = 10;
|
|
1890
1890
|
this.source = '127.0.0.1';
|
|
1891
|
+
this.enabled = true;
|
|
1891
1892
|
this.projectId = '';
|
|
1892
1893
|
this.projectName = '';
|
|
1893
1894
|
this.appId = '';
|
|
@@ -1963,6 +1964,7 @@ class ClsLoggerCore {
|
|
|
1963
1964
|
this.appId = options.appId ?? this.appId;
|
|
1964
1965
|
this.appVersion = options.appVersion ?? this.appVersion;
|
|
1965
1966
|
this.envType = nextEnvType;
|
|
1967
|
+
this.enabled = options.enabled ?? true;
|
|
1966
1968
|
// 可选:外部注入 SDK(优先级:sdkLoader > sdk)
|
|
1967
1969
|
this.sdkLoaderOverride = options.sdkLoader ?? this.sdkLoaderOverride;
|
|
1968
1970
|
this.sdkOverride = options.sdk ?? this.sdkOverride;
|
|
@@ -1979,15 +1981,17 @@ class ClsLoggerCore {
|
|
|
1979
1981
|
void this.getInstance().catch(() => {
|
|
1980
1982
|
// ignore
|
|
1981
1983
|
});
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1984
|
+
if (this.enabled) {
|
|
1985
|
+
// 启动时尝试发送失败缓存
|
|
1986
|
+
this.flushFailed();
|
|
1987
|
+
// 初始化后立即启动请求监听
|
|
1988
|
+
this.startRequestMonitor(options.requestMonitor);
|
|
1989
|
+
// 初始化后立即启动错误监控/性能监控
|
|
1990
|
+
this.startErrorMonitor(options.errorMonitor);
|
|
1991
|
+
this.startPerformanceMonitor(options.performanceMonitor);
|
|
1992
|
+
// 初始化后立即启动行为埋点(PV/UV/点击)
|
|
1993
|
+
this.startBehaviorMonitor(options.behaviorMonitor);
|
|
1994
|
+
}
|
|
1991
1995
|
}
|
|
1992
1996
|
getBaseFields() {
|
|
1993
1997
|
let auto = undefined;
|
|
@@ -2112,6 +2116,8 @@ class ClsLoggerCore {
|
|
|
2112
2116
|
* - 最终会把 fields 展开成 CLS 的 content(key/value 都会转成 string)
|
|
2113
2117
|
*/
|
|
2114
2118
|
put(fields, options = {}) {
|
|
2119
|
+
if (!this.enabled)
|
|
2120
|
+
return;
|
|
2115
2121
|
if (!fields)
|
|
2116
2122
|
return;
|
|
2117
2123
|
if (!this.topicId) {
|
|
@@ -2170,6 +2176,8 @@ class ClsLoggerCore {
|
|
|
2170
2176
|
* - 埋点入参必须是一维(扁平)Object,非原始值会被 stringify
|
|
2171
2177
|
*/
|
|
2172
2178
|
enqueue(fields, options = {}) {
|
|
2179
|
+
if (!this.enabled)
|
|
2180
|
+
return;
|
|
2173
2181
|
if (!fields)
|
|
2174
2182
|
return;
|
|
2175
2183
|
const time = Date.now();
|
|
@@ -2208,6 +2216,8 @@ class ClsLoggerCore {
|
|
|
2208
2216
|
* 批量上报(每条 item.data 展开为 log content)
|
|
2209
2217
|
*/
|
|
2210
2218
|
putBatch(queue) {
|
|
2219
|
+
if (!this.enabled)
|
|
2220
|
+
return;
|
|
2211
2221
|
if (!queue || queue.length === 0)
|
|
2212
2222
|
return;
|
|
2213
2223
|
if (!this.topicId) {
|
|
@@ -2251,6 +2261,8 @@ class ClsLoggerCore {
|
|
|
2251
2261
|
* 参考《一、概述》:统一上报入口(内存队列 + 批量发送)
|
|
2252
2262
|
*/
|
|
2253
2263
|
report(log) {
|
|
2264
|
+
if (!this.enabled)
|
|
2265
|
+
return;
|
|
2254
2266
|
if (!log?.type)
|
|
2255
2267
|
return;
|
|
2256
2268
|
if (!this.topicId) {
|
|
@@ -2455,6 +2467,8 @@ class ClsLoggerCore {
|
|
|
2455
2467
|
writeStringStorage(this.failedCacheKey, JSON.stringify(next));
|
|
2456
2468
|
}
|
|
2457
2469
|
flushFailed() {
|
|
2470
|
+
if (!this.enabled)
|
|
2471
|
+
return;
|
|
2458
2472
|
const raw = readStringStorage(this.failedCacheKey);
|
|
2459
2473
|
if (!raw)
|
|
2460
2474
|
return;
|
package/dist/mini.js
CHANGED
|
@@ -1911,6 +1911,7 @@ class ClsLoggerCore {
|
|
|
1911
1911
|
this.endpoint = 'ap-shanghai.cls.tencentcs.com';
|
|
1912
1912
|
this.retryTimes = 10;
|
|
1913
1913
|
this.source = '127.0.0.1';
|
|
1914
|
+
this.enabled = true;
|
|
1914
1915
|
this.projectId = '';
|
|
1915
1916
|
this.projectName = '';
|
|
1916
1917
|
this.appId = '';
|
|
@@ -1986,6 +1987,7 @@ class ClsLoggerCore {
|
|
|
1986
1987
|
this.appId = options.appId ?? this.appId;
|
|
1987
1988
|
this.appVersion = options.appVersion ?? this.appVersion;
|
|
1988
1989
|
this.envType = nextEnvType;
|
|
1990
|
+
this.enabled = options.enabled ?? true;
|
|
1989
1991
|
// 可选:外部注入 SDK(优先级:sdkLoader > sdk)
|
|
1990
1992
|
this.sdkLoaderOverride = options.sdkLoader ?? this.sdkLoaderOverride;
|
|
1991
1993
|
this.sdkOverride = options.sdk ?? this.sdkOverride;
|
|
@@ -2002,15 +2004,17 @@ class ClsLoggerCore {
|
|
|
2002
2004
|
void this.getInstance().catch(() => {
|
|
2003
2005
|
// ignore
|
|
2004
2006
|
});
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2007
|
+
if (this.enabled) {
|
|
2008
|
+
// 启动时尝试发送失败缓存
|
|
2009
|
+
this.flushFailed();
|
|
2010
|
+
// 初始化后立即启动请求监听
|
|
2011
|
+
this.startRequestMonitor(options.requestMonitor);
|
|
2012
|
+
// 初始化后立即启动错误监控/性能监控
|
|
2013
|
+
this.startErrorMonitor(options.errorMonitor);
|
|
2014
|
+
this.startPerformanceMonitor(options.performanceMonitor);
|
|
2015
|
+
// 初始化后立即启动行为埋点(PV/UV/点击)
|
|
2016
|
+
this.startBehaviorMonitor(options.behaviorMonitor);
|
|
2017
|
+
}
|
|
2014
2018
|
}
|
|
2015
2019
|
getBaseFields() {
|
|
2016
2020
|
let auto = undefined;
|
|
@@ -2135,6 +2139,8 @@ class ClsLoggerCore {
|
|
|
2135
2139
|
* - 最终会把 fields 展开成 CLS 的 content(key/value 都会转成 string)
|
|
2136
2140
|
*/
|
|
2137
2141
|
put(fields, options = {}) {
|
|
2142
|
+
if (!this.enabled)
|
|
2143
|
+
return;
|
|
2138
2144
|
if (!fields)
|
|
2139
2145
|
return;
|
|
2140
2146
|
if (!this.topicId) {
|
|
@@ -2193,6 +2199,8 @@ class ClsLoggerCore {
|
|
|
2193
2199
|
* - 埋点入参必须是一维(扁平)Object,非原始值会被 stringify
|
|
2194
2200
|
*/
|
|
2195
2201
|
enqueue(fields, options = {}) {
|
|
2202
|
+
if (!this.enabled)
|
|
2203
|
+
return;
|
|
2196
2204
|
if (!fields)
|
|
2197
2205
|
return;
|
|
2198
2206
|
const time = Date.now();
|
|
@@ -2231,6 +2239,8 @@ class ClsLoggerCore {
|
|
|
2231
2239
|
* 批量上报(每条 item.data 展开为 log content)
|
|
2232
2240
|
*/
|
|
2233
2241
|
putBatch(queue) {
|
|
2242
|
+
if (!this.enabled)
|
|
2243
|
+
return;
|
|
2234
2244
|
if (!queue || queue.length === 0)
|
|
2235
2245
|
return;
|
|
2236
2246
|
if (!this.topicId) {
|
|
@@ -2274,6 +2284,8 @@ class ClsLoggerCore {
|
|
|
2274
2284
|
* 参考《一、概述》:统一上报入口(内存队列 + 批量发送)
|
|
2275
2285
|
*/
|
|
2276
2286
|
report(log) {
|
|
2287
|
+
if (!this.enabled)
|
|
2288
|
+
return;
|
|
2277
2289
|
if (!log?.type)
|
|
2278
2290
|
return;
|
|
2279
2291
|
if (!this.topicId) {
|
|
@@ -2478,6 +2490,8 @@ class ClsLoggerCore {
|
|
|
2478
2490
|
writeStringStorage(this.failedCacheKey, JSON.stringify(next));
|
|
2479
2491
|
}
|
|
2480
2492
|
flushFailed() {
|
|
2493
|
+
if (!this.enabled)
|
|
2494
|
+
return;
|
|
2481
2495
|
const raw = readStringStorage(this.failedCacheKey);
|
|
2482
2496
|
if (!raw)
|
|
2483
2497
|
return;
|
package/dist/types.d.ts
CHANGED
|
@@ -36,7 +36,12 @@ export interface BatchOptions {
|
|
|
36
36
|
*/
|
|
37
37
|
startupDelayMs?: number;
|
|
38
38
|
}
|
|
39
|
-
export interface
|
|
39
|
+
export interface ClsLoggerBaseOptions {
|
|
40
|
+
/**
|
|
41
|
+
* 全局开关:是否开启 SDK,默认 true
|
|
42
|
+
* - false: 彻底关闭 SDK(不采集、不写入队列、不发送)
|
|
43
|
+
*/
|
|
44
|
+
enabled?: boolean;
|
|
40
45
|
/**
|
|
41
46
|
* 参考《一、概述》:用于多项目日志隔离的项目标识
|
|
42
47
|
* - 推荐使用 projectId
|
|
@@ -45,12 +50,8 @@ export interface ClsLoggerInitOptions {
|
|
|
45
50
|
projectId?: string;
|
|
46
51
|
/** 兼容旧字段:项目名 */
|
|
47
52
|
projectName?: string;
|
|
48
|
-
/** 应用 ID */
|
|
49
|
-
appId?: string;
|
|
50
53
|
/** 应用版本 */
|
|
51
54
|
appVersion?: string;
|
|
52
|
-
/** 运行环境类型(不传则自动识别) */
|
|
53
|
-
envType?: EnvType;
|
|
54
55
|
/**
|
|
55
56
|
* 腾讯云 CLS 配置(推荐)
|
|
56
57
|
* - endpoint/topicID/retry_times/source
|
|
@@ -118,6 +119,19 @@ export interface ClsLoggerInitOptions {
|
|
|
118
119
|
*/
|
|
119
120
|
behaviorMonitor?: boolean | BehaviorMonitorOptions;
|
|
120
121
|
}
|
|
122
|
+
export interface ClsLoggerWebOptions extends ClsLoggerBaseOptions {
|
|
123
|
+
/** 运行环境类型(不传则自动识别,Web 环境下默认为 browser) */
|
|
124
|
+
envType?: 'browser';
|
|
125
|
+
/** 应用 ID(Web 环境可选) */
|
|
126
|
+
appId?: string;
|
|
127
|
+
}
|
|
128
|
+
export interface ClsLoggerMiniProgramOptions extends ClsLoggerBaseOptions {
|
|
129
|
+
/** 运行环境类型:小程序(此时 appId 必填) */
|
|
130
|
+
envType: 'miniprogram';
|
|
131
|
+
/** 应用 ID(小程序必填) */
|
|
132
|
+
appId: string;
|
|
133
|
+
}
|
|
134
|
+
export type ClsLoggerInitOptions = ClsLoggerWebOptions | ClsLoggerMiniProgramOptions;
|
|
121
135
|
export interface PutOptions {
|
|
122
136
|
/** 是否合并 init.generateBaseFields() 的结果,默认 true */
|
|
123
137
|
mergeBaseFields?: boolean;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAC7D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,SAAS,GAAG,MAAM,CAAC;AAEhE,sCAAsC;AACtC,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAExD,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC;AAEpC,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,aAAa,CAAC;AAEhD,MAAM,WAAW,qBAAqB;IACpC,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wBAAwB;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACnC
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAC7D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAA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,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,2DAA2D;IAC3D,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gCAAgC;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,MAAM,CAAC;IAE3B;;OAEG;IACH,YAAY,CAAC,EAAE;QACb;;;;WAIG;QACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;QAC1B,yBAAyB;QACzB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH"}
|
package/dist/web.esm.js
CHANGED
|
@@ -1888,6 +1888,7 @@ class ClsLoggerCore {
|
|
|
1888
1888
|
this.endpoint = 'ap-shanghai.cls.tencentcs.com';
|
|
1889
1889
|
this.retryTimes = 10;
|
|
1890
1890
|
this.source = '127.0.0.1';
|
|
1891
|
+
this.enabled = true;
|
|
1891
1892
|
this.projectId = '';
|
|
1892
1893
|
this.projectName = '';
|
|
1893
1894
|
this.appId = '';
|
|
@@ -1963,6 +1964,7 @@ class ClsLoggerCore {
|
|
|
1963
1964
|
this.appId = options.appId ?? this.appId;
|
|
1964
1965
|
this.appVersion = options.appVersion ?? this.appVersion;
|
|
1965
1966
|
this.envType = nextEnvType;
|
|
1967
|
+
this.enabled = options.enabled ?? true;
|
|
1966
1968
|
// 可选:外部注入 SDK(优先级:sdkLoader > sdk)
|
|
1967
1969
|
this.sdkLoaderOverride = options.sdkLoader ?? this.sdkLoaderOverride;
|
|
1968
1970
|
this.sdkOverride = options.sdk ?? this.sdkOverride;
|
|
@@ -1979,15 +1981,17 @@ class ClsLoggerCore {
|
|
|
1979
1981
|
void this.getInstance().catch(() => {
|
|
1980
1982
|
// ignore
|
|
1981
1983
|
});
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1984
|
+
if (this.enabled) {
|
|
1985
|
+
// 启动时尝试发送失败缓存
|
|
1986
|
+
this.flushFailed();
|
|
1987
|
+
// 初始化后立即启动请求监听
|
|
1988
|
+
this.startRequestMonitor(options.requestMonitor);
|
|
1989
|
+
// 初始化后立即启动错误监控/性能监控
|
|
1990
|
+
this.startErrorMonitor(options.errorMonitor);
|
|
1991
|
+
this.startPerformanceMonitor(options.performanceMonitor);
|
|
1992
|
+
// 初始化后立即启动行为埋点(PV/UV/点击)
|
|
1993
|
+
this.startBehaviorMonitor(options.behaviorMonitor);
|
|
1994
|
+
}
|
|
1991
1995
|
}
|
|
1992
1996
|
getBaseFields() {
|
|
1993
1997
|
let auto = undefined;
|
|
@@ -2112,6 +2116,8 @@ class ClsLoggerCore {
|
|
|
2112
2116
|
* - 最终会把 fields 展开成 CLS 的 content(key/value 都会转成 string)
|
|
2113
2117
|
*/
|
|
2114
2118
|
put(fields, options = {}) {
|
|
2119
|
+
if (!this.enabled)
|
|
2120
|
+
return;
|
|
2115
2121
|
if (!fields)
|
|
2116
2122
|
return;
|
|
2117
2123
|
if (!this.topicId) {
|
|
@@ -2170,6 +2176,8 @@ class ClsLoggerCore {
|
|
|
2170
2176
|
* - 埋点入参必须是一维(扁平)Object,非原始值会被 stringify
|
|
2171
2177
|
*/
|
|
2172
2178
|
enqueue(fields, options = {}) {
|
|
2179
|
+
if (!this.enabled)
|
|
2180
|
+
return;
|
|
2173
2181
|
if (!fields)
|
|
2174
2182
|
return;
|
|
2175
2183
|
const time = Date.now();
|
|
@@ -2208,6 +2216,8 @@ class ClsLoggerCore {
|
|
|
2208
2216
|
* 批量上报(每条 item.data 展开为 log content)
|
|
2209
2217
|
*/
|
|
2210
2218
|
putBatch(queue) {
|
|
2219
|
+
if (!this.enabled)
|
|
2220
|
+
return;
|
|
2211
2221
|
if (!queue || queue.length === 0)
|
|
2212
2222
|
return;
|
|
2213
2223
|
if (!this.topicId) {
|
|
@@ -2251,6 +2261,8 @@ class ClsLoggerCore {
|
|
|
2251
2261
|
* 参考《一、概述》:统一上报入口(内存队列 + 批量发送)
|
|
2252
2262
|
*/
|
|
2253
2263
|
report(log) {
|
|
2264
|
+
if (!this.enabled)
|
|
2265
|
+
return;
|
|
2254
2266
|
if (!log?.type)
|
|
2255
2267
|
return;
|
|
2256
2268
|
if (!this.topicId) {
|
|
@@ -2455,6 +2467,8 @@ class ClsLoggerCore {
|
|
|
2455
2467
|
writeStringStorage(this.failedCacheKey, JSON.stringify(next));
|
|
2456
2468
|
}
|
|
2457
2469
|
flushFailed() {
|
|
2470
|
+
if (!this.enabled)
|
|
2471
|
+
return;
|
|
2458
2472
|
const raw = readStringStorage(this.failedCacheKey);
|
|
2459
2473
|
if (!raw)
|
|
2460
2474
|
return;
|
package/dist/web.js
CHANGED
|
@@ -1911,6 +1911,7 @@ class ClsLoggerCore {
|
|
|
1911
1911
|
this.endpoint = 'ap-shanghai.cls.tencentcs.com';
|
|
1912
1912
|
this.retryTimes = 10;
|
|
1913
1913
|
this.source = '127.0.0.1';
|
|
1914
|
+
this.enabled = true;
|
|
1914
1915
|
this.projectId = '';
|
|
1915
1916
|
this.projectName = '';
|
|
1916
1917
|
this.appId = '';
|
|
@@ -1986,6 +1987,7 @@ class ClsLoggerCore {
|
|
|
1986
1987
|
this.appId = options.appId ?? this.appId;
|
|
1987
1988
|
this.appVersion = options.appVersion ?? this.appVersion;
|
|
1988
1989
|
this.envType = nextEnvType;
|
|
1990
|
+
this.enabled = options.enabled ?? true;
|
|
1989
1991
|
// 可选:外部注入 SDK(优先级:sdkLoader > sdk)
|
|
1990
1992
|
this.sdkLoaderOverride = options.sdkLoader ?? this.sdkLoaderOverride;
|
|
1991
1993
|
this.sdkOverride = options.sdk ?? this.sdkOverride;
|
|
@@ -2002,15 +2004,17 @@ class ClsLoggerCore {
|
|
|
2002
2004
|
void this.getInstance().catch(() => {
|
|
2003
2005
|
// ignore
|
|
2004
2006
|
});
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2007
|
+
if (this.enabled) {
|
|
2008
|
+
// 启动时尝试发送失败缓存
|
|
2009
|
+
this.flushFailed();
|
|
2010
|
+
// 初始化后立即启动请求监听
|
|
2011
|
+
this.startRequestMonitor(options.requestMonitor);
|
|
2012
|
+
// 初始化后立即启动错误监控/性能监控
|
|
2013
|
+
this.startErrorMonitor(options.errorMonitor);
|
|
2014
|
+
this.startPerformanceMonitor(options.performanceMonitor);
|
|
2015
|
+
// 初始化后立即启动行为埋点(PV/UV/点击)
|
|
2016
|
+
this.startBehaviorMonitor(options.behaviorMonitor);
|
|
2017
|
+
}
|
|
2014
2018
|
}
|
|
2015
2019
|
getBaseFields() {
|
|
2016
2020
|
let auto = undefined;
|
|
@@ -2135,6 +2139,8 @@ class ClsLoggerCore {
|
|
|
2135
2139
|
* - 最终会把 fields 展开成 CLS 的 content(key/value 都会转成 string)
|
|
2136
2140
|
*/
|
|
2137
2141
|
put(fields, options = {}) {
|
|
2142
|
+
if (!this.enabled)
|
|
2143
|
+
return;
|
|
2138
2144
|
if (!fields)
|
|
2139
2145
|
return;
|
|
2140
2146
|
if (!this.topicId) {
|
|
@@ -2193,6 +2199,8 @@ class ClsLoggerCore {
|
|
|
2193
2199
|
* - 埋点入参必须是一维(扁平)Object,非原始值会被 stringify
|
|
2194
2200
|
*/
|
|
2195
2201
|
enqueue(fields, options = {}) {
|
|
2202
|
+
if (!this.enabled)
|
|
2203
|
+
return;
|
|
2196
2204
|
if (!fields)
|
|
2197
2205
|
return;
|
|
2198
2206
|
const time = Date.now();
|
|
@@ -2231,6 +2239,8 @@ class ClsLoggerCore {
|
|
|
2231
2239
|
* 批量上报(每条 item.data 展开为 log content)
|
|
2232
2240
|
*/
|
|
2233
2241
|
putBatch(queue) {
|
|
2242
|
+
if (!this.enabled)
|
|
2243
|
+
return;
|
|
2234
2244
|
if (!queue || queue.length === 0)
|
|
2235
2245
|
return;
|
|
2236
2246
|
if (!this.topicId) {
|
|
@@ -2274,6 +2284,8 @@ class ClsLoggerCore {
|
|
|
2274
2284
|
* 参考《一、概述》:统一上报入口(内存队列 + 批量发送)
|
|
2275
2285
|
*/
|
|
2276
2286
|
report(log) {
|
|
2287
|
+
if (!this.enabled)
|
|
2288
|
+
return;
|
|
2277
2289
|
if (!log?.type)
|
|
2278
2290
|
return;
|
|
2279
2291
|
if (!this.topicId) {
|
|
@@ -2478,6 +2490,8 @@ class ClsLoggerCore {
|
|
|
2478
2490
|
writeStringStorage(this.failedCacheKey, JSON.stringify(next));
|
|
2479
2491
|
}
|
|
2480
2492
|
flushFailed() {
|
|
2493
|
+
if (!this.enabled)
|
|
2494
|
+
return;
|
|
2481
2495
|
const raw = readStringStorage(this.failedCacheKey);
|
|
2482
2496
|
if (!raw)
|
|
2483
2497
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@be-link/cls-logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "@be-link cls-logger - 腾讯云 CLS 日志上报封装",
|
|
5
5
|
"homepage": "https://github.com/snowmountain-top/be-link",
|
|
6
6
|
"author": "zhuiyi",
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"files": [
|
|
44
44
|
"dist"
|
|
45
45
|
],
|
|
46
|
-
"dependencies": {
|
|
46
|
+
"dependencies": {},
|
|
47
|
+
"devDependencies": {
|
|
47
48
|
"tencentcloud-cls-sdk-js-web": "^1.0.11",
|
|
48
49
|
"tencentcloud-cls-sdk-js-mini": "^1.0.3"
|
|
49
50
|
},
|