Skip to content

Commit

Permalink
fix enable loaf logic
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinL10 committed Jul 8, 2024
1 parent de91078 commit e8fc143
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 46 deletions.
78 changes: 38 additions & 40 deletions packages/browser-utils/src/metrics/browserMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,52 +128,50 @@ export function startTrackingLongAnimationFrames(): void {
// NOTE: the current web-vitals version (3.5.2) does not support long-animation-frame, so
// we directly observe `long-animation-frame` events instead of through the web-vitals
// `observe` helper function.
if (PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')) {
const observer = new PerformanceObserver(list => {
for (const entry of list.getEntries() as PerformanceLongAnimationFrameTiming[]) {
if (!getActiveSpan()) {
return;
}
if (!entry.scripts[0]) {
return;
}
const observer = new PerformanceObserver(list => {
for (const entry of list.getEntries() as PerformanceLongAnimationFrameTiming[]) {
if (!getActiveSpan()) {
return;
}
if (!entry.scripts[0]) {
return;
}

const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
const duration = msToSec(entry.duration);
const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
const duration = msToSec(entry.duration);

const attributes: SpanAttributes = {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',
};
const initialScript = entry.scripts[0];
if (initialScript) {
const { invoker, invokerType, sourceURL, sourceFunctionName, sourceCharPosition } = initialScript;
attributes['browser.script.invoker'] = invoker;
attributes['browser.script.invoker_type'] = invokerType;
if (sourceURL) {
attributes['code.filepath'] = sourceURL;
}
if (sourceFunctionName) {
attributes['code.function'] = sourceFunctionName;
}
if (sourceCharPosition !== -1) {
attributes['browser.script.source_char_position'] = sourceCharPosition;
}
const attributes: SpanAttributes = {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',
};
const initialScript = entry.scripts[0];
if (initialScript) {
const { invoker, invokerType, sourceURL, sourceFunctionName, sourceCharPosition } = initialScript;
attributes['browser.script.invoker'] = invoker;
attributes['browser.script.invoker_type'] = invokerType;
if (sourceURL) {
attributes['code.filepath'] = sourceURL;
}

const span = startInactiveSpan({
name: 'Main UI thread blocked',
op: 'ui.long-animation-frame',
startTime,
attributes,
});
if (span) {
span.end(startTime + duration);
if (sourceFunctionName) {
attributes['code.function'] = sourceFunctionName;
}
if (sourceCharPosition !== -1) {
attributes['browser.script.source_char_position'] = sourceCharPosition;
}
}
});

observer.observe({ type: 'long-animation-frame', buffered: true });
}
const span = startInactiveSpan({
name: 'Main UI thread blocked',
op: 'ui.long-animation-frame',
startTime,
attributes,
});
if (span) {
span.end(startTime + duration);
}
}
});

observer.observe({ type: 'long-animation-frame', buffered: true });
}

/**
Expand Down
9 changes: 3 additions & 6 deletions packages/browser/src/tracing/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,10 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
startTrackingINP();
}

if (enableLongTask) {
startTrackingLongTasks();
}

// At most one of long-task and long-animation-frames should be enabled, since they track the same events
if (!enableLongTask && enableLongAnimationFrame) {
if (enableLongAnimationFrame && PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')) {
startTrackingLongAnimationFrames();
} else if (enableLongTask) {
startTrackingLongTasks();
}

if (enableInteractions) {
Expand Down

0 comments on commit e8fc143

Please sign in to comment.