Skip to content

feat(integrations): Mark errors caught from HttpClient and CaptureConsole integrations as unhandled #8891

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

Merged
merged 3 commits into from
Sep 5, 2023
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 @@ -38,7 +38,7 @@ sentryTest(
value: 'HTTP Client Error with status code: 500',
mechanism: {
type: 'http.client',
handled: true,
handled: false,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sentryTest(
value: 'HTTP Client Error with status code: 500',
mechanism: {
type: 'http.client',
handled: true,
handled: false,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ sentryTest('works with a Request passed in', async ({ getLocalTestPath, page })
value: 'HTTP Client Error with status code: 500',
mechanism: {
type: 'http.client',
handled: true,
handled: false,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sentryTest(
value: 'HTTP Client Error with status code: 500',
mechanism: {
type: 'http.client',
handled: true,
handled: false,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ sentryTest('works with a Request (without body) & options passed in', async ({ g
value: 'HTTP Client Error with status code: 500',
mechanism: {
type: 'http.client',
handled: true,
handled: false,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sentryTest(
value: 'HTTP Client Error with status code: 500',
mechanism: {
type: 'http.client',
handled: true,
handled: false,
},
},
],
Expand Down
7 changes: 7 additions & 0 deletions packages/integrations/src/captureconsole.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { EventProcessor, Hub, Integration } from '@sentry/types';
import {
addExceptionMechanism,
addInstrumentationHandler,
CONSOLE_LEVELS,
GLOBAL_OBJ,
Expand Down Expand Up @@ -64,6 +65,12 @@ function consoleHandler(hub: Hub, args: unknown[], level: string): void {
scope.setExtra('arguments', args);
scope.addEventProcessor(event => {
event.logger = 'console';

addExceptionMechanism(event, {
handled: false,
type: 'console',
});

return event;
});

Expand Down
1 change: 1 addition & 0 deletions packages/integrations/src/httpclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ export class HttpClient implements Integration {

addExceptionMechanism(event, {
type: 'http.client',
handled: false,
});

return event;
Expand Down
32 changes: 32 additions & 0 deletions packages/integrations/test/captureconsole.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,36 @@ describe('CaptureConsole setup', () => {
GLOBAL_OBJ.console.log('some message');
}).not.toThrow();
});

it("marks captured exception's mechanism as unhandled", () => {
// const addExceptionMechanismSpy = jest.spyOn(utils, 'addExceptionMechanism');

const captureConsoleIntegration = new CaptureConsole({ levels: ['error'] });
const mockHub = getMockHub(captureConsoleIntegration);
captureConsoleIntegration.setupOnce(
() => undefined,
() => mockHub,
);

const mockScope = mockHub.getScope();

const someError = new Error('some error');
GLOBAL_OBJ.console.error(someError);

const addedEventProcessor = (mockScope.addEventProcessor as jest.Mock).mock.calls[0][0];
const someEvent: Event = {
exception: {
values: [{}],
},
};
addedEventProcessor(someEvent);

expect(mockHub.captureException).toHaveBeenCalledTimes(1);
expect(mockScope.addEventProcessor).toHaveBeenCalledTimes(1);

expect(someEvent.exception?.values?.[0].mechanism).toEqual({
handled: false,
type: 'console',
});
});
});