From 5a0cb39a2890b8763e964c5c4e67d2a4db40bf7b Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Thu, 19 Dec 2024 12:05:15 +0100 Subject: [PATCH] fix for tests... --- .../src/tracing/browserTracingIntegration.ts | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/browser/src/tracing/browserTracingIntegration.ts b/packages/browser/src/tracing/browserTracingIntegration.ts index 7502c76ab847..85a9a0fa3616 100644 --- a/packages/browser/src/tracing/browserTracingIntegration.ts +++ b/packages/browser/src/tracing/browserTracingIntegration.ts @@ -38,12 +38,6 @@ import { defaultRequestInstrumentationOptions, instrumentOutgoingRequests } from export const BROWSER_TRACING_INTEGRATION_ID = 'BrowserTracing'; -/** - * This is just a small wrapper that makes `document` optional. - * We want to be extra-safe and always check that this exists, to ensure weird environments do not blow up. - */ -const optionalWindowDocument = WINDOW.document as (typeof WINDOW)['document'] | undefined; - interface RouteInfo { name: string | undefined; source: TransactionSource | undefined; @@ -195,6 +189,12 @@ const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = { * We explicitly export the proper type here, as this has to be extended in some cases. */ export const browserTracingIntegration = ((_options: Partial = {}) => { + /** + * This is just a small wrapper that makes `document` optional. + * We want to be extra-safe and always check that this exists, to ensure weird environments do not blow up. + */ + const optionalWindowDocument = WINDOW.document as (typeof WINDOW)['document'] | undefined; + registerSpanErrorInstrumentation(); const { @@ -467,6 +467,12 @@ export function startBrowserTracingNavigationSpan(client: Client, spanOptions: S /** Returns the value of a meta tag */ export function getMetaContent(metaName: string): string | undefined { + /** + * This is just a small wrapper that makes `document` optional. + * We want to be extra-safe and always check that this exists, to ensure weird environments do not blow up. + */ + const optionalWindowDocument = WINDOW.document as (typeof WINDOW)['document'] | undefined; + const metaTag = optionalWindowDocument && optionalWindowDocument.querySelector(`meta[name=${metaName}]`); return (metaTag && metaTag.getAttribute('content')) || undefined; } @@ -478,6 +484,12 @@ function registerInteractionListener( childSpanTimeout: BrowserTracingOptions['childSpanTimeout'], latestRoute: RouteInfo, ): void { + /** + * This is just a small wrapper that makes `document` optional. + * We want to be extra-safe and always check that this exists, to ensure weird environments do not blow up. + */ + const optionalWindowDocument = WINDOW.document as (typeof WINDOW)['document'] | undefined; + let inflightInteractionSpan: Span | undefined; const registerInteractionTransaction = (): void => { const op = 'ui.action.click';