Skip to content

Commit

Permalink
Update browserMetrics.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
horochx authored Jul 26, 2024
1 parent 4d61a6d commit 9abdea5
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/browser-utils/src/metrics/browserMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ export function startTrackingWebVitals(): () => void {
*/
export function startTrackingLongTasks(): void {
addPerformanceInstrumentationHandler('longtask', ({ entries }) => {
if (!getActiveSpan()) {
return;
}
for (const entry of entries) {
if (!getActiveSpan()) {
return;
}
const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
const duration = msToSec(entry.duration);

Expand All @@ -129,12 +129,12 @@ export function startTrackingLongAnimationFrames(): void {
// we directly observe `long-animation-frame` events instead of through the web-vitals
// `observe` helper function.
const observer = new PerformanceObserver(list => {
if (!getActiveSpan()) {
return;
}
for (const entry of list.getEntries() as PerformanceLongAnimationFrameTiming[]) {
if (!getActiveSpan()) {
return;
}
if (!entry.scripts[0]) {
return;
break;
}

const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
Expand Down Expand Up @@ -179,11 +179,10 @@ export function startTrackingLongAnimationFrames(): void {
*/
export function startTrackingInteractions(): void {
addPerformanceInstrumentationHandler('event', ({ entries }) => {
if (!getActiveSpan()) {
return;
}
for (const entry of entries) {
if (!getActiveSpan()) {
return;
}

if (entry.name === 'click') {
const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
const duration = msToSec(entry.duration);
Expand Down

0 comments on commit 9abdea5

Please sign in to comment.