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(profiling): Guard from throwing if profiler constructor throws #7328

Merged
merged 2 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
lint
  • Loading branch information
JonasBa committed Mar 3, 2023
commit 5c0f0b54d936df449504fa47ba759420851f8d62
8 changes: 4 additions & 4 deletions packages/browser/src/profiling/hubextensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ function wrapTransactionWithProfiling(transaction: Transaction): Transaction {
if (__DEBUG_BUILD__) {
logger.log(
"[Profiling] Failed to initialize the Profiling constructor, this is likely due to a missing 'Document-Policy': 'js-profiling' header.",
);
logger.log('[Profiling] Disabling profiling for current user session.');
}
PROFILING_CONSTRUCTOR_FAILED = true;
);
logger.log('[Profiling] Disabling profiling for current user session.');
}
PROFILING_CONSTRUCTOR_FAILED = true;
}

// We failed to construct the profiler, fallback to original transaction - there is no need to log
Expand Down
10 changes: 5 additions & 5 deletions packages/browser/test/unit/profiling/hubextensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ describe('BrowserProfilingIntegration', () => {
},
getOptions() {
return {
profilesSampleRate: 1,
}
}
profilesSampleRate: 1,
};
},
};

hub.bindClient(client);
Expand All @@ -67,7 +67,7 @@ describe('BrowserProfilingIntegration', () => {
// @ts-ignore force api to be undefined
global.window.Profiler = undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to reset this like we do with document, window and location?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lforst I think this is already done in beforeEach where we override the global.window object with the new one from the fresh jsdom instance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. Didn't see that Profiler was on the window object. Sorry about that!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good :D always better to ask then to miss it :D

// set sampled to true so that profiling does not early return
const mockTransaction = {sampled: true} as Transaction
const mockTransaction = { sampled: true } as Transaction;
expect(() => onProfilingStartRouteTransaction(mockTransaction)).not.toThrow();
});
it('does not throw if constructor throws', () => {
Expand All @@ -81,7 +81,7 @@ describe('BrowserProfilingIntegration', () => {
}

// set sampled to true so that profiling does not early return
const mockTransaction = {sampled: true} as Transaction
const mockTransaction = { sampled: true } as Transaction;

// @ts-ignore override with our own constructor
global.window.Profiler = Profiler;
Expand Down