Skip to content

Commit 407862d

Browse files
committed
fix: browserMetrics.ts LoAF for loop
1 parent 36f62bb commit 407862d

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

packages/browser-utils/src/metrics/browserMetrics.ts

+22-24
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ export function startTrackingWebVitals(): () => void {
9999
*/
100100
export function startTrackingLongTasks(): void {
101101
addPerformanceInstrumentationHandler('longtask', ({ entries }) => {
102+
if (!getActiveSpan()) {
103+
return;
104+
}
102105
for (const entry of entries) {
103-
if (!getActiveSpan()) {
104-
return;
105-
}
106106
const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
107107
const duration = msToSec(entry.duration);
108108

@@ -129,12 +129,12 @@ export function startTrackingLongAnimationFrames(): void {
129129
// we directly observe `long-animation-frame` events instead of through the web-vitals
130130
// `observe` helper function.
131131
const observer = new PerformanceObserver(list => {
132+
if (!getActiveSpan()) {
133+
return;
134+
}
132135
for (const entry of list.getEntries() as PerformanceLongAnimationFrameTiming[]) {
133-
if (!getActiveSpan()) {
134-
return;
135-
}
136136
if (!entry.scripts[0]) {
137-
return;
137+
continue;
138138
}
139139

140140
const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
@@ -143,20 +143,19 @@ export function startTrackingLongAnimationFrames(): void {
143143
const attributes: SpanAttributes = {
144144
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',
145145
};
146+
146147
const initialScript = entry.scripts[0];
147-
if (initialScript) {
148-
const { invoker, invokerType, sourceURL, sourceFunctionName, sourceCharPosition } = initialScript;
149-
attributes['browser.script.invoker'] = invoker;
150-
attributes['browser.script.invoker_type'] = invokerType;
151-
if (sourceURL) {
152-
attributes['code.filepath'] = sourceURL;
153-
}
154-
if (sourceFunctionName) {
155-
attributes['code.function'] = sourceFunctionName;
156-
}
157-
if (sourceCharPosition !== -1) {
158-
attributes['browser.script.source_char_position'] = sourceCharPosition;
159-
}
148+
const { invoker, invokerType, sourceURL, sourceFunctionName, sourceCharPosition } = initialScript;
149+
attributes['browser.script.invoker'] = invoker;
150+
attributes['browser.script.invoker_type'] = invokerType;
151+
if (sourceURL) {
152+
attributes['code.filepath'] = sourceURL;
153+
}
154+
if (sourceFunctionName) {
155+
attributes['code.function'] = sourceFunctionName;
156+
}
157+
if (sourceCharPosition !== -1) {
158+
attributes['browser.script.source_char_position'] = sourceCharPosition;
160159
}
161160

162161
const span = startInactiveSpan({
@@ -179,11 +178,10 @@ export function startTrackingLongAnimationFrames(): void {
179178
*/
180179
export function startTrackingInteractions(): void {
181180
addPerformanceInstrumentationHandler('event', ({ entries }) => {
181+
if (!getActiveSpan()) {
182+
return;
183+
}
182184
for (const entry of entries) {
183-
if (!getActiveSpan()) {
184-
return;
185-
}
186-
187185
if (entry.name === 'click') {
188186
const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
189187
const duration = msToSec(entry.duration);

0 commit comments

Comments
 (0)