Skip to content

Commit

Permalink
feat(integrations): Mark errors caught from HttpClient and `Capture…
Browse files Browse the repository at this point in the history
…Console` integrations as unhandled (#8891)

Mark errors caught from optional integrations

* `HttpClient`
* `CaptureConsole`

as unhandled. 

For more details see #8890, #6073
  • Loading branch information
Lms24 authored Sep 5, 2023
1 parent 39401f0 commit 29ef20e
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 6 deletions.
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',
});
});
});

0 comments on commit 29ef20e

Please sign in to comment.