diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-animation-frame-enabled/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-animation-frame-enabled/test.ts index 5290251a2707..d2dc2e45571b 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-animation-frame-enabled/test.ts +++ b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-animation-frame-enabled/test.ts @@ -38,7 +38,6 @@ sentryTest( parent_span_id: eventData.contexts?.trace?.span_id, data: { 'code.filepath': 'https://example.com/path/to/script.js', - 'code.function': '', 'browser.script.source_char_position': 0, 'browser.script.invoker': 'https://example.com/path/to/script.js', 'browser.script.invoker_type': 'classic-script', @@ -92,9 +91,6 @@ sentryTest( description: 'Main UI thread blocked', parent_span_id: eventData.contexts?.trace?.span_id, data: { - 'code.filepath': '', - 'code.function': '', - 'browser.script.source_char_position': -1, 'browser.script.invoker': 'BUTTON#clickme.onclick', 'browser.script.invoker_type': 'event-listener', [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.long-animation-frame', diff --git a/packages/browser-utils/src/metrics/browserMetrics.ts b/packages/browser-utils/src/metrics/browserMetrics.ts index 88beb48c7060..4bb5041d7da3 100644 --- a/packages/browser-utils/src/metrics/browserMetrics.ts +++ b/packages/browser-utils/src/metrics/browserMetrics.ts @@ -147,11 +147,17 @@ export function startTrackingLongAnimationFrames(): void { startTime, attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics', - 'code.filepath': entry.scripts[0].sourceURL, - 'code.function': entry.scripts[0].sourceFunctionName, - 'browser.script.source_char_position': entry.scripts[0].sourceCharPosition, '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, + }), }, }); if (span) {