@lark-apaas/observable-web 1.0.0-alpha.10 → 1.0.0-alpha.12

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.
@@ -48,13 +48,8 @@ class CustomWebDetector {
48
48
  const appId = window.appId || "";
49
49
  const tenantId = window.tenantId || "";
50
50
  const userId = window.userId || "";
51
- const appAttributes = {
52
- app_id: appId,
53
- tenant_id: tenantId,
54
- user_id: userId
55
- };
56
51
  return {
57
- attributes: __spreadValues(__spreadValues({}, browserAttributes), appAttributes)
52
+ attributes: __spreadValues({}, browserAttributes)
58
53
  };
59
54
  }
60
55
  }
@@ -24,6 +24,8 @@ declare class WebObservableSdk {
24
24
  private initLogs;
25
25
  private initMetrics;
26
26
  private initAutoPv;
27
+ private flushData;
28
+ private registerLifecycleListeners;
27
29
  log(level: 'INFO' | 'ERROR' | 'WARN', message: string, attributes?: Record<string, any>): void;
28
30
  addCount(name: string, value?: number, attributes?: Record<string, any>): void;
29
31
  shutdown(): Promise<void>;
@@ -70,6 +70,7 @@ class WebObservableSdk {
70
70
  this.initLogs();
71
71
  this.initMetrics();
72
72
  this.initAutoPv();
73
+ this.registerLifecycleListeners();
73
74
  this.isStarted = true;
74
75
  } catch (error) {
75
76
  console.error("Failed to start WebObservableSdk:", error);
@@ -123,6 +124,26 @@ class WebObservableSdk {
123
124
  const pvTracker = new import_PvInstrumentation.PvInstrumentation(meter);
124
125
  pvTracker.enable();
125
126
  }
127
+ flushData() {
128
+ const promises = [];
129
+ if (this.loggerProvider) {
130
+ promises.push(this.loggerProvider.forceFlush());
131
+ }
132
+ if (this.meterProvider) {
133
+ promises.push(this.meterProvider.forceFlush());
134
+ }
135
+ Promise.allSettled(promises);
136
+ }
137
+ registerLifecycleListeners() {
138
+ document.addEventListener("visibilitychange", () => {
139
+ if (document.visibilityState === "hidden") {
140
+ this.flushData();
141
+ }
142
+ });
143
+ window.addEventListener("pagehide", () => {
144
+ this.flushData();
145
+ });
146
+ }
126
147
  // --- 公开 API: 日志(Log) ---
127
148
  log(level, message, attributes = {}) {
128
149
  this.logger.emit({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/observable-web",
3
- "version": "1.0.0-alpha.10",
3
+ "version": "1.0.0-alpha.12",
4
4
  "description": "Observable SDK For Web",
5
5
  "main": "./dist/lib/index.js",
6
6
  "files": [