@cedarai/session-replay-sdk 0.2.0 → 0.3.0
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 +90 -0
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -422,6 +422,91 @@ var RecorderCapture = class {
|
|
|
422
422
|
}
|
|
423
423
|
};
|
|
424
424
|
|
|
425
|
+
// src/performance.ts
|
|
426
|
+
import { onLCP, onCLS, onINP } from "web-vitals";
|
|
427
|
+
var MEMORY_INTERVAL_MS = 3e4;
|
|
428
|
+
var PerformanceCapture = class {
|
|
429
|
+
onEvent;
|
|
430
|
+
started = false;
|
|
431
|
+
longTaskObserver = null;
|
|
432
|
+
memoryTimer = null;
|
|
433
|
+
constructor(onEvent2) {
|
|
434
|
+
this.onEvent = onEvent2;
|
|
435
|
+
}
|
|
436
|
+
start() {
|
|
437
|
+
if (this.started) return;
|
|
438
|
+
this.started = true;
|
|
439
|
+
this.startWebVitals();
|
|
440
|
+
this.startLongTaskObserver();
|
|
441
|
+
this.startMemorySnapshots();
|
|
442
|
+
}
|
|
443
|
+
stop() {
|
|
444
|
+
if (!this.started) return;
|
|
445
|
+
this.started = false;
|
|
446
|
+
this.longTaskObserver?.disconnect();
|
|
447
|
+
this.longTaskObserver = null;
|
|
448
|
+
if (this.memoryTimer) {
|
|
449
|
+
clearInterval(this.memoryTimer);
|
|
450
|
+
this.memoryTimer = null;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
emit(data) {
|
|
454
|
+
if (!this.started) return;
|
|
455
|
+
this.onEvent({
|
|
456
|
+
type: "performance",
|
|
457
|
+
timestamp: Date.now(),
|
|
458
|
+
data
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
startWebVitals() {
|
|
462
|
+
const handler = (metric) => {
|
|
463
|
+
this.emit({
|
|
464
|
+
metric: "web-vital",
|
|
465
|
+
name: metric.name,
|
|
466
|
+
value: metric.value,
|
|
467
|
+
rating: metric.rating
|
|
468
|
+
});
|
|
469
|
+
};
|
|
470
|
+
onLCP(handler);
|
|
471
|
+
onCLS(handler, { reportAllChanges: true });
|
|
472
|
+
onINP(handler, { reportAllChanges: true });
|
|
473
|
+
}
|
|
474
|
+
startLongTaskObserver() {
|
|
475
|
+
if (typeof globalThis.PerformanceObserver === "undefined") return;
|
|
476
|
+
try {
|
|
477
|
+
this.longTaskObserver = new globalThis.PerformanceObserver((list) => {
|
|
478
|
+
for (const entry of list.getEntries()) {
|
|
479
|
+
const attribution = entry.attribution?.[0]?.containerSrc;
|
|
480
|
+
this.emit({
|
|
481
|
+
metric: "long-task",
|
|
482
|
+
duration: entry.duration,
|
|
483
|
+
attribution
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
this.longTaskObserver.observe({ entryTypes: ["longtask"] });
|
|
488
|
+
} catch {
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
startMemorySnapshots() {
|
|
492
|
+
const memory = performance.memory;
|
|
493
|
+
if (!memory) return;
|
|
494
|
+
this.emitMemory(memory);
|
|
495
|
+
this.memoryTimer = setInterval(() => {
|
|
496
|
+
const mem = performance.memory;
|
|
497
|
+
if (mem) this.emitMemory(mem);
|
|
498
|
+
}, MEMORY_INTERVAL_MS);
|
|
499
|
+
}
|
|
500
|
+
emitMemory(memory) {
|
|
501
|
+
this.emit({
|
|
502
|
+
metric: "memory",
|
|
503
|
+
usedJSHeapSize: memory.usedJSHeapSize,
|
|
504
|
+
totalJSHeapSize: memory.totalJSHeapSize,
|
|
505
|
+
jsHeapSizeLimit: memory.jsHeapSizeLimit
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
|
|
425
510
|
// src/index.ts
|
|
426
511
|
var config = null;
|
|
427
512
|
var transport = null;
|
|
@@ -429,6 +514,7 @@ var consoleCapture = null;
|
|
|
429
514
|
var errorCapture = null;
|
|
430
515
|
var networkCapture = null;
|
|
431
516
|
var recorderCapture = null;
|
|
517
|
+
var performanceCapture = null;
|
|
432
518
|
var unloadHandler = null;
|
|
433
519
|
function onEvent(event) {
|
|
434
520
|
transport?.enqueue(event);
|
|
@@ -458,6 +544,8 @@ var CedarReplay = {
|
|
|
458
544
|
networkCapture.start();
|
|
459
545
|
recorderCapture = new RecorderCapture(onEvent, config.recorder);
|
|
460
546
|
recorderCapture.start();
|
|
547
|
+
performanceCapture = new PerformanceCapture(onEvent);
|
|
548
|
+
performanceCapture.start();
|
|
461
549
|
unloadHandler = () => transport?.flushOnUnload();
|
|
462
550
|
window.addEventListener("beforeunload", unloadHandler);
|
|
463
551
|
},
|
|
@@ -466,6 +554,8 @@ var CedarReplay = {
|
|
|
466
554
|
window.removeEventListener("beforeunload", unloadHandler);
|
|
467
555
|
unloadHandler = null;
|
|
468
556
|
}
|
|
557
|
+
performanceCapture?.stop();
|
|
558
|
+
performanceCapture = null;
|
|
469
559
|
recorderCapture?.stop();
|
|
470
560
|
recorderCapture = null;
|
|
471
561
|
networkCapture?.stop();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarai/session-replay-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"test:watch": "vitest"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"rrweb": "^2.0.0-alpha.4"
|
|
22
|
+
"rrweb": "^2.0.0-alpha.4",
|
|
23
|
+
"web-vitals": "^4.2.4"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@vitest/browser": "^4.0.18",
|