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

feat(v8/browser): Rename TryCatch integration to browserApiErrorsIntegration #10755

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
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 @@ -25,7 +25,7 @@ sentryTest('logs debug messages correctly', async ({ getLocalTestUrl, page }) =>
? [
'Sentry Logger [log]: Integration installed: InboundFilters',
'Sentry Logger [log]: Integration installed: FunctionToString',
'Sentry Logger [log]: Integration installed: TryCatch',
'Sentry Logger [log]: Integration installed: BrowserApiErrors',
'Sentry Logger [log]: Integration installed: Breadcrumbs',
'Sentry Logger [log]: Global Handler attached: onerror',
'Sentry Logger [log]: Global Handler attached: onunhandledrejection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
integrations: [
'InboundFilters',
'FunctionToString',
'TryCatch',
'BrowserApiErrors',
'Breadcrumbs',
'GlobalHandlers',
'LinkedErrors',
Expand Down Expand Up @@ -82,7 +82,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
integrations: [
'InboundFilters',
'FunctionToString',
'TryCatch',
'BrowserApiErrors',
'Breadcrumbs',
'GlobalHandlers',
'LinkedErrors',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ sentryTest('should capture replays (@sentry/replay export)', async ({ getLocalTe
integrations: [
'InboundFilters',
'FunctionToString',
'TryCatch',
'BrowserApiErrors',
'Breadcrumbs',
'GlobalHandlers',
'LinkedErrors',
Expand Down Expand Up @@ -82,7 +82,7 @@ sentryTest('should capture replays (@sentry/replay export)', async ({ getLocalTe
integrations: [
'InboundFilters',
'FunctionToString',
'TryCatch',
'BrowserApiErrors',
'Breadcrumbs',
'GlobalHandlers',
'LinkedErrors',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DEFAULT_REPLAY_EVENT = {
integrations: [
'InboundFilters',
'FunctionToString',
'TryCatch',
'BrowserApiErrors',
'Breadcrumbs',
'GlobalHandlers',
'LinkedErrors',
Expand Down
6 changes: 3 additions & 3 deletions packages/angular-ivy/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { IS_DEBUG_BUILD } from './flags';
*/
export function init(options: BrowserOptions): void {
const opts = {
// Filter out TryCatch integration as it interferes with our Angular `ErrorHandler`:
// TryCatch would catch certain errors before they reach the `ErrorHandler` and thus provide a
// Filter out BrowserApiErrors integration as it interferes with our Angular `ErrorHandler`:
// BrowserApiErrors would catch certain errors before they reach the `ErrorHandler` and thus provide a
// lower fidelity error than what `SentryErrorHandler` (see errorhandler.ts) would provide.
// see:
// - https://github.com/getsentry/sentry-javascript/issues/5417#issuecomment-1453407097
// - https://github.com/getsentry/sentry-javascript/issues/2744
defaultIntegrations: getDefaultIntegrations(options).filter(integration => {
return integration.name !== 'TryCatch';
return integration.name !== 'BrowserApiErrors';
}),
...options,
};
Expand Down
6 changes: 3 additions & 3 deletions packages/angular/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { IS_DEBUG_BUILD } from './flags';
*/
export function init(options: BrowserOptions): void {
const opts = {
// Filter out TryCatch integration as it interferes with our Angular `ErrorHandler`:
// TryCatch would catch certain errors before they reach the `ErrorHandler` and thus provide a
// Filter out BrowserApiErrors integration as it interferes with our Angular `ErrorHandler`:
// BrowserApiErrors would catch certain errors before they reach the `ErrorHandler` and thus provide a
// lower fidelity error than what `SentryErrorHandler` (see errorhandler.ts) would provide.
// see:
// - https://github.com/getsentry/sentry-javascript/issues/5417#issuecomment-1453407097
// - https://github.com/getsentry/sentry-javascript/issues/2744
defaultIntegrations: getDefaultIntegrations(options).filter(integration => {
return integration.name !== 'TryCatch';
return integration.name !== 'BrowserApiErrors';
}),
...options,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('init', () => {
expect(setContextSpy).toHaveBeenCalledWith('angular', { version: 10 });
});

describe('filtering out the `TryCatch` integration', () => {
describe('filtering out the `BrowserApiErrors` integration', () => {
const browserInitSpy = jest.spyOn(SentryBrowser, 'init');

beforeEach(() => {
Expand All @@ -27,7 +27,7 @@ describe('init', () => {
expect(browserInitSpy).toHaveBeenCalledTimes(1);

const options = browserInitSpy.mock.calls[0][0] || {};
expect(options.defaultIntegrations).not.toContainEqual(expect.objectContaining({ name: 'TryCatch' }));
expect(options.defaultIntegrations).not.toContainEqual(expect.objectContaining({ name: 'BrowserApiErrors' }));
});

it("doesn't filter if `defaultIntegrations` is set to `false`", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export { dedupeIntegration } from './integrations/dedupe';
export { globalHandlersIntegration } from './integrations/globalhandlers';
export { httpContextIntegration } from './integrations/httpcontext';
export { linkedErrorsIntegration } from './integrations/linkederrors';
export { browserApiErrorsIntegration } from './integrations/trycatch';
export { browserApiErrorsIntegration } from './integrations/browserapierrors';

// eslint-disable-next-line deprecation/deprecation
export { TryCatch, Breadcrumbs, LinkedErrors, HttpContext, Dedupe } from './integrations';
export { Breadcrumbs, LinkedErrors, HttpContext, Dedupe } from './integrations';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
import type { Integration, IntegrationClass, IntegrationFn, WrappedFunction } from '@sentry/types';
import { defineIntegration } from '@sentry/core';
import type { IntegrationFn, WrappedFunction } from '@sentry/types';
import { fill, getFunctionName, getOriginalFunction } from '@sentry/utils';

import { WINDOW, wrap } from '../helpers';
Expand Down Expand Up @@ -38,19 +38,19 @@ const DEFAULT_EVENT_TARGET = [
'XMLHttpRequestUpload',
];

const INTEGRATION_NAME = 'TryCatch';
const INTEGRATION_NAME = 'BrowserApiErrors';

type XMLHttpRequestProp = 'onload' | 'onerror' | 'onprogress' | 'onreadystatechange';

interface TryCatchOptions {
interface BrowserApiErrorsOptions {
setTimeout: boolean;
setInterval: boolean;
requestAnimationFrame: boolean;
XMLHttpRequest: boolean;
eventTarget: boolean | string[];
}

const _browserApiErrorsIntegration = ((options: Partial<TryCatchOptions> = {}) => {
const _browserApiErrorsIntegration = ((options: Partial<BrowserApiErrorsOptions> = {}) => {
const _options = {
XMLHttpRequest: true,
eventTarget: true,
Expand Down Expand Up @@ -90,25 +90,10 @@ const _browserApiErrorsIntegration = ((options: Partial<TryCatchOptions> = {}) =
};
}) satisfies IntegrationFn;

export const browserApiErrorsIntegration = defineIntegration(_browserApiErrorsIntegration);

/**
* Wrap timer functions and event targets to catch errors and provide better meta data.
* @deprecated Use `browserApiErrorsIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const TryCatch = convertIntegrationFnToClass(
INTEGRATION_NAME,
browserApiErrorsIntegration,
) as IntegrationClass<Integration> & {
new (options?: {
setTimeout: boolean;
setInterval: boolean;
requestAnimationFrame: boolean;
XMLHttpRequest: boolean;
eventTarget: boolean | string[];
}): Integration;
};
export const browserApiErrorsIntegration = defineIntegration(_browserApiErrorsIntegration);

function _wrapTimeFunction(original: () => void): () => number {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -167,7 +152,7 @@ function _wrapXHR(originalSend: () => void): () => void {
},
};

// If Instrument integration has been called before TryCatch, get the name of original function
// If Instrument integration has been called before BrowserApiErrors, get the name of original function
const originalFunction = getOriginalFunction(original);
if (originalFunction) {
wrapOptions.mechanism.data.handler = getFunctionName(originalFunction);
Expand Down
1 change: 0 additions & 1 deletion packages/browser/src/integrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable deprecation/deprecation */
export { TryCatch } from './trycatch';
export { Breadcrumbs } from './breadcrumbs';
export { LinkedErrors } from './linkederrors';
export { HttpContext } from './httpcontext';
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import { BrowserClient } from './client';
import { DEBUG_BUILD } from './debug-build';
import { WINDOW, wrap as internalWrap } from './helpers';
import { breadcrumbsIntegration } from './integrations/breadcrumbs';
import { browserApiErrorsIntegration } from './integrations/browserapierrors';
import { dedupeIntegration } from './integrations/dedupe';
import { globalHandlersIntegration } from './integrations/globalhandlers';
import { httpContextIntegration } from './integrations/httpcontext';
import { linkedErrorsIntegration } from './integrations/linkederrors';
import { browserApiErrorsIntegration } from './integrations/trycatch';
import { defaultStackParser } from './stack-parsers';
import { makeFetchTransport } from './transports/fetch';

Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/fixtures/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function Error(obj?: Event): any {
integrations: [
'InboundFilters',
'FunctionToString',
'TryCatch',
'BrowserApiErrors',
'Breadcrumbs',
'GlobalHandlers',
'LinkedErrors',
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/fixtures/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export function Transaction(traceId?: string, obj?: Partial<Event>): any {
integrations: [
'InboundFilters',
'FunctionToString',
'TryCatch',
'BrowserApiErrors',
'Breadcrumbs',
'GlobalHandlers',
'LinkedErrors',
Expand Down
Loading