Skip to content

Commit

Permalink
move undefined check later
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinL10 committed Jul 8, 2024
1 parent 5b9ba4b commit 10091d8
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions packages/browser-utils/src/metrics/browserMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,27 @@ export function startTrackingLongAnimationFrames(): void {
const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
const duration = msToSec(entry.duration);

const attributes: SpanAttributes = { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics' };
if (entry.scripts[0]) {
attributes['browser.script.invoker'] = entry.scripts[0].invoker;
attributes['browser.script.invoker_type'] = entry.scripts[0].invokerType;

if (entry.scripts[0].sourceURL.length > 0) {
attributes['code.filepath'] = entry.scripts[0].sourceURL;
}
if (entry.scripts[0].sourceFunctionName.length > 0) {
attributes['code.function'] = entry.scripts[0].sourceFunctionName;
}
if (entry.scripts[0].sourceCharPosition !== -1) {
attributes['browser.script.source_char_position'] = entry.scripts[0].sourceCharPosition;
}
}

const span = startInactiveSpan({
name: 'Main UI thread blocked',
op: 'ui.long-animation-frame',
startTime,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',
'browser.script.invoker': entry.scripts[0].invoker,
'browser.script.invoker_type': entry.scripts[0].invokerType,
...(entry.scripts[0].sourceURL && {
'code.filepath': entry.scripts[0].sourceURL,
}),
...(entry.scripts[0].sourceFunctionName && {
'code.function': entry.scripts[0].sourceFunctionName,
}),
...(entry.scripts[0].sourceCharPosition !== -1 && {
'browser.script.source_char_position': entry.scripts[0].sourceCharPosition,
}),
},
attributes,
});
if (span) {
span.end(startTime + duration);
Expand Down

0 comments on commit 10091d8

Please sign in to comment.