@lark-apaas/observable-web 1.0.1-alpha.1 → 1.0.1-alpha.3
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/dist/index.js +40 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -792,7 +792,7 @@ var trace = TraceAPI.getInstance();
|
|
|
792
792
|
|
|
793
793
|
// package.json
|
|
794
794
|
var package_default = {
|
|
795
|
-
version: "1.0.1-alpha.
|
|
795
|
+
version: "1.0.1-alpha.2"};
|
|
796
796
|
|
|
797
797
|
// src/const.ts
|
|
798
798
|
var defaultResourceAttr = {
|
|
@@ -1368,19 +1368,40 @@ var _WebObservableSdk = class _WebObservableSdk {
|
|
|
1368
1368
|
pvTracker.enable();
|
|
1369
1369
|
}
|
|
1370
1370
|
flushData() {
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1371
|
+
try {
|
|
1372
|
+
const promises = [];
|
|
1373
|
+
if (this.loggerProvider) {
|
|
1374
|
+
promises.push(this.loggerProvider.forceFlush());
|
|
1375
|
+
}
|
|
1376
|
+
if (this.meterProvider) {
|
|
1377
|
+
promises.push(this.meterProvider.forceFlush());
|
|
1378
|
+
}
|
|
1379
|
+
if (this.tracerProvider) {
|
|
1380
|
+
promises.push(this.tracerProvider.forceFlush());
|
|
1381
|
+
}
|
|
1382
|
+
Promise.allSettled(promises);
|
|
1383
|
+
} catch (error) {
|
|
1384
|
+
console.error("Failed to flush data:", error);
|
|
1380
1385
|
}
|
|
1381
|
-
Promise.allSettled(promises);
|
|
1382
1386
|
}
|
|
1383
1387
|
registerLifecycleListeners() {
|
|
1388
|
+
const patchWindowClose = () => {
|
|
1389
|
+
if (window.close.__isPatched) return;
|
|
1390
|
+
const sdkInstance = this;
|
|
1391
|
+
const originalClose = window.close;
|
|
1392
|
+
window.close = function(...args) {
|
|
1393
|
+
try {
|
|
1394
|
+
sdkInstance.flushData();
|
|
1395
|
+
} catch (e) {
|
|
1396
|
+
console.error("Patch window close: flushData error");
|
|
1397
|
+
}
|
|
1398
|
+
if (typeof originalClose === "function") {
|
|
1399
|
+
return originalClose.apply(window, args);
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1402
|
+
window.close.__isPatched = true;
|
|
1403
|
+
};
|
|
1404
|
+
patchWindowClose();
|
|
1384
1405
|
document.addEventListener("visibilitychange", () => {
|
|
1385
1406
|
if (document.visibilityState === "hidden") {
|
|
1386
1407
|
this.flushData();
|
|
@@ -1411,11 +1432,16 @@ var _WebObservableSdk = class _WebObservableSdk {
|
|
|
1411
1432
|
counter.add(value, attributes);
|
|
1412
1433
|
}
|
|
1413
1434
|
startSpan(name, options, spanContext) {
|
|
1414
|
-
|
|
1435
|
+
try {
|
|
1436
|
+
if (!this.tracer) {
|
|
1437
|
+
return _WebObservableSdk.EmptySpan;
|
|
1438
|
+
}
|
|
1439
|
+
const ctx = spanContext || context.active();
|
|
1440
|
+
return this.tracer.startSpan(name, options, ctx);
|
|
1441
|
+
} catch (error) {
|
|
1442
|
+
console.error("Failed to start span:", error);
|
|
1415
1443
|
return _WebObservableSdk.EmptySpan;
|
|
1416
1444
|
}
|
|
1417
|
-
const ctx = spanContext || context.active();
|
|
1418
|
-
return this.tracer.startSpan(name, options, ctx);
|
|
1419
1445
|
}
|
|
1420
1446
|
// --- 公开 API: 链路追踪 (Trace) ---
|
|
1421
1447
|
trace(name, fn, options) {
|