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

ref(core): Ensure we use captureException() from @sentry/core where possible #6546

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 2 additions & 1 deletion packages/angular/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"entryFile": "src/index.ts",
"umdModuleIds": {
"@sentry/browser": "Sentry",
"@sentry/core": "Sentry.core",
"@sentry/utils": "Sentry.util"
}
},
"whitelistedNonPeerDependencies": ["@sentry/browser", "@sentry/utils", "@sentry/types", "tslib"],
"whitelistedNonPeerDependencies": ["@sentry/browser", "@sentry/core", "@sentry/utils", "@sentry/types", "tslib"],
"assets": ["README.md", "LICENSE"]
}
1 change: 1 addition & 0 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"dependencies": {
"@sentry/browser": "7.26.0",
"@sentry/core": "7.26.0",
"@sentry/types": "7.26.0",
"@sentry/utils": "7.26.0",
"tslib": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/errorhandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpErrorResponse } from '@angular/common/http';
import { ErrorHandler as AngularErrorHandler, Inject, Injectable } from '@angular/core';
import * as Sentry from '@sentry/browser';
import { captureException } from '@sentry/browser';
import { captureException } from '@sentry/core';
import { addExceptionMechanism } from '@sentry/utils';

import { runOutsideAngular } from './zone';
Expand Down
10 changes: 5 additions & 5 deletions packages/angular/test/errorhandler.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { HttpErrorResponse } from '@angular/common/http';
import * as SentryBrowser from '@sentry/browser';
import { Scope } from '@sentry/browser';
import * as SentryCore from '@sentry/core';
import * as SentryUtils from '@sentry/utils';

import { createErrorHandler, SentryErrorHandler } from '../src/errorhandler';

const FakeScope = new Scope();
const FakeScope = new SentryBrowser.Scope();

jest.mock('@sentry/browser', () => {
const original = jest.requireActual('@sentry/browser');
jest.mock('@sentry/core', () => {
const original = jest.requireActual('@sentry/core');
return {
...original,
captureException: (err: unknown, cb: (arg0?: unknown) => unknown) => {
Expand All @@ -18,7 +18,7 @@ jest.mock('@sentry/browser', () => {
};
});

const captureExceptionSpy = jest.spyOn(SentryBrowser, 'captureException');
const captureExceptionSpy = jest.spyOn(SentryCore, 'captureException');

jest.spyOn(console, 'error').mockImplementation();

Expand Down
1 change: 1 addition & 0 deletions packages/integrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"module": "build/npm/esm/index.js",
"types": "build/npm/types/index.d.ts",
"dependencies": {
"@sentry/core": "7.26.0",
"@sentry/types": "7.26.0",
"@sentry/utils": "7.26.0",
"localforage": "^1.8.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/integrations/src/captureconsole.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { captureException } from '@sentry/core';
import { EventProcessor, Hub, Integration } from '@sentry/types';
import { CONSOLE_LEVELS, fill, GLOBAL_OBJ, safeJoin, severityLevelFromString } from '@sentry/utils';

Expand Down Expand Up @@ -62,7 +63,7 @@ export class CaptureConsole implements Integration {
hub.captureMessage(message);
}
} else if (level === 'error' && args[0] instanceof Error) {
hub.captureException(args[0]);
captureException(args[0]);
} else {
hub.captureMessage(message);
}
Expand Down
13 changes: 8 additions & 5 deletions packages/integrations/test/captureconsole.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/unbound-method */
import * as SentryCore from '@sentry/core';
import { Event, Hub, Integration } from '@sentry/types';

import { CaptureConsole } from '../src/captureconsole';
Expand Down Expand Up @@ -32,6 +33,8 @@ const getMockHubWithIntegration = (integration: Integration) =>
getIntegration: jest.fn(() => integration),
} as unknown as Hub);

const mockCaptureException = jest.spyOn(SentryCore, 'captureException');

// We're using this to un-monkey patch the console after each test.
const originalConsole = Object.assign({}, global.console);

Expand Down Expand Up @@ -225,8 +228,8 @@ describe('CaptureConsole setup', () => {
const someError = new Error('some error');
global.console.error(someError);

expect(mockHub.captureException).toHaveBeenCalledTimes(1);
expect(mockHub.captureException).toHaveBeenCalledWith(someError);
expect(mockCaptureException).toHaveBeenCalledTimes(1);
expect(mockCaptureException).toHaveBeenCalledWith(someError);
});

it('should capture exception on `console.error` when no levels are provided in constructor', () => {
Expand All @@ -239,8 +242,8 @@ describe('CaptureConsole setup', () => {
const someError = new Error('some error');
global.console.error(someError);

expect(mockHub.captureException).toHaveBeenCalledTimes(1);
expect(mockHub.captureException).toHaveBeenCalledWith(someError);
expect(mockCaptureException).toHaveBeenCalledTimes(1);
expect(mockCaptureException).toHaveBeenCalledWith(someError);
});

it('should capture message on `console.log` when no levels are provided in constructor', () => {
Expand All @@ -267,7 +270,7 @@ describe('CaptureConsole setup', () => {

expect(mockHub.captureMessage).toHaveBeenCalledTimes(1);
expect(mockHub.captureMessage).toHaveBeenCalledWith('some non-error message');
expect(mockHub.captureException).not.toHaveBeenCalled();
expect(mockCaptureException).not.toHaveBeenCalled();
});

it('should capture a message for non-error log levels', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/vue/src/errorhandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getCurrentHub } from '@sentry/browser';
import { captureException } from '@sentry/core';

import { formatComponentName, generateComponentTrace } from './components';
import { Options, ViewModel, Vue } from './types';
Expand Down Expand Up @@ -31,7 +32,7 @@ export const attachErrorHandler = (app: Vue, options: Options): void => {
setTimeout(() => {
getCurrentHub().withScope(scope => {
scope.setContext('vue', metadata);
getCurrentHub().captureException(error);
captureException(error);
});
});

Expand Down
7 changes: 4 additions & 3 deletions scenarios/browser/basic-capture-exception/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { init, captureException } from "@sentry/browser";
import { init } from '@sentry/browser';
import { captureException } from '@sentry/core';

init({
dsn: "https://[email protected]/0000000",
dsn: 'https://[email protected]/0000000',
});

captureException(new Error("error here!"));
captureException(new Error('error here!'));