Skip to content

Commit

Permalink
fix(core): Silently fail maybeInstrument (#14140)
Browse files Browse the repository at this point in the history
Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
  • Loading branch information
chargome and mydea authored Nov 4, 2024
1 parent 738870d commit 6729214
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ module.exports = [
import: createImport('init'),
ignore: ['next/router', 'next/constants'],
gzip: true,
limit: '39.1 KB',
limit: '40 KB',
},
// SvelteKit SDK (ESM)
{
Expand Down
6 changes: 5 additions & 1 deletion packages/utils/src/instrument/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ export function resetInstrumentationHandlers(): void {
/** Maybe run an instrumentation function, unless it was already called. */
export function maybeInstrument(type: InstrumentHandlerType, instrumentFn: () => void): void {
if (!instrumented[type]) {
instrumentFn();
instrumented[type] = true;
try {
instrumentFn();
} catch (e) {
DEBUG_BUILD && logger.error(`Error while instrumenting ${type}`, e);
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions packages/utils/test/instrument.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { maybeInstrument } from '../src';

describe('maybeInstrument', () => {
test('does not throw when instrumenting fails', () => {
maybeInstrument('xhr', () => {
throw new Error('test');
});
});

test('does not throw when instrumenting fn is not a function', () => {
maybeInstrument('xhr', undefined as any);
});
});

0 comments on commit 6729214

Please sign in to comment.