From 10091d8f1e42d5b6f519147edab1f2f2bc762971 Mon Sep 17 00:00:00 2001 From: KevinL10 Date: Mon, 8 Jul 2024 15:02:33 -0400 Subject: [PATCH] move undefined check later --- .../src/metrics/browserMetrics.ts | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/browser-utils/src/metrics/browserMetrics.ts b/packages/browser-utils/src/metrics/browserMetrics.ts index 4bb5041d7da3..ac4ef1be3871 100644 --- a/packages/browser-utils/src/metrics/browserMetrics.ts +++ b/packages/browser-utils/src/metrics/browserMetrics.ts @@ -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);