Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tracing): Guard against missing window.location #10659

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
isPageloadTransaction, // should wait for finish signal if it's a pageload transaction
);

if (isPageloadTransaction) {
if (isPageloadTransaction && WINDOW.document) {
WINDOW.document.addEventListener('readystatechange', () => {
if (['interactive', 'complete'].includes(WINDOW.document.readyState)) {
idleTransaction.sendAutoFinishSignal();
Expand Down Expand Up @@ -295,7 +295,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
options;

let activeSpan: Span | undefined;
let startingUrl: string | undefined = WINDOW.location.href;
let startingUrl: string | undefined = WINDOW.location && WINDOW.location.href;

client.on('startNavigationSpan', (context: StartSpanOptions) => {
if (activeSpan) {
Expand All @@ -321,7 +321,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
});
});

if (options.instrumentPageLoad) {
if (options.instrumentPageLoad && WINDOW.location) {
const context: StartSpanOptions = {
name: WINDOW.location.pathname,
// pageload should always start at timeOrigin (and needs to be in s, not ms)
Expand All @@ -334,7 +334,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
startBrowserTracingPageLoadSpan(client, context);
}

if (options.instrumentNavigation) {
if (options.instrumentNavigation && WINDOW.location) {
addHistoryInstrumentationHandler(({ to, from }) => {
/**
* This early return is there to account for some cases where a navigation transaction starts right after
Expand Down
Loading