Skip to content

Commit d198721

Browse files
authored
ref(angular): Adjust ErrorHandler event mechanism (#17608)
Adjusts the mechanism of errors captured in Angular to follow the trace origin naming scheme closes #17609
1 parent 50e9471 commit d198721

File tree

6 files changed

+38
-20
lines changed

6 files changed

+38
-20
lines changed

dev-packages/e2e-tests/test-applications/angular-17/tests/errors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test('sends an error', async ({ page }) => {
1919
type: 'Error',
2020
value: 'Error thrown from Angular 17 E2E test app',
2121
mechanism: {
22-
type: 'angular',
22+
type: 'auto.function.angular.error_handler',
2323
handled: false,
2424
},
2525
},
@@ -54,7 +54,7 @@ test('assigns the correct transaction value after a navigation', async ({ page }
5454
type: 'Error',
5555
value: 'Error thrown from user page',
5656
mechanism: {
57-
type: 'angular',
57+
type: 'auto.function.angular.error_handler',
5858
handled: false,
5959
},
6060
},

dev-packages/e2e-tests/test-applications/angular-18/tests/errors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test('sends an error', async ({ page }) => {
1919
type: 'Error',
2020
value: 'Error thrown from Angular 18 E2E test app',
2121
mechanism: {
22-
type: 'angular',
22+
type: 'auto.function.angular.error_handler',
2323
handled: false,
2424
},
2525
},
@@ -54,7 +54,7 @@ test('assigns the correct transaction value after a navigation', async ({ page }
5454
type: 'Error',
5555
value: 'Error thrown from user page',
5656
mechanism: {
57-
type: 'angular',
57+
type: 'auto.function.angular.error_handler',
5858
handled: false,
5959
},
6060
},

dev-packages/e2e-tests/test-applications/angular-19/tests/errors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test('sends an error', async ({ page }) => {
1919
type: 'Error',
2020
value: 'Error thrown from Angular 18 E2E test app',
2121
mechanism: {
22-
type: 'angular',
22+
type: 'auto.function.angular.error_handler',
2323
handled: false,
2424
},
2525
},
@@ -54,7 +54,7 @@ test('assigns the correct transaction value after a navigation', async ({ page }
5454
type: 'Error',
5555
value: 'Error thrown from user page',
5656
mechanism: {
57-
type: 'angular',
57+
type: 'auto.function.angular.error_handler',
5858
handled: false,
5959
},
6060
},

dev-packages/e2e-tests/test-applications/angular-20/tests/errors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test('sends an error', async ({ page }) => {
1919
type: 'Error',
2020
value: 'Error thrown from Angular 20 E2E test app',
2121
mechanism: {
22-
type: 'angular',
22+
type: 'auto.function.angular.error_handler',
2323
handled: false,
2424
},
2525
},
@@ -54,7 +54,7 @@ test('assigns the correct transaction value after a navigation', async ({ page }
5454
type: 'Error',
5555
value: 'Error thrown from user page',
5656
mechanism: {
57-
type: 'angular',
57+
type: 'auto.function.angular.error_handler',
5858
handled: false,
5959
},
6060
},

packages/angular/src/errorhandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class SentryErrorHandler implements AngularErrorHandler, OnDestroy {
111111
// Capture handled exception and send it to Sentry.
112112
const eventId = runOutsideAngular(() =>
113113
Sentry.captureException(extractedError, {
114-
mechanism: { type: 'angular', handled: false },
114+
mechanism: { type: 'auto.function.angular.error_handler', handled: false },
115115
}),
116116
);
117117

packages/angular/test/errorhandler.test.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { HttpErrorResponse } from '@angular/common/http';
22
import * as SentryBrowser from '@sentry/browser';
33
import type { Client, Event } from '@sentry/core';
4-
import { vi } from 'vitest';
4+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
55
import { createErrorHandler, SentryErrorHandler } from '../src/errorhandler';
66

77
const captureExceptionSpy = vi.spyOn(SentryBrowser, 'captureException');
88

99
vi.spyOn(console, 'error').mockImplementation(() => {});
1010

1111
const captureExceptionEventHint = {
12-
mechanism: { handled: false, type: 'angular' },
12+
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
1313
};
1414

1515
class CustomError extends Error {
@@ -71,15 +71,19 @@ describe('SentryErrorHandler', () => {
7171
createErrorHandler().handleError(str);
7272

7373
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
74-
expect(captureExceptionSpy).toHaveBeenCalledWith(str, { mechanism: { handled: false, type: 'angular' } });
74+
expect(captureExceptionSpy).toHaveBeenCalledWith(str, {
75+
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
76+
});
7577
});
7678

7779
it('extracts an empty Error', () => {
7880
const err = new Error();
7981
createErrorHandler().handleError(err);
8082

8183
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
82-
expect(captureExceptionSpy).toHaveBeenCalledWith(err, { mechanism: { handled: false, type: 'angular' } });
84+
expect(captureExceptionSpy).toHaveBeenCalledWith(err, {
85+
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
86+
});
8387
});
8488

8589
it('extracts a non-empty Error', () => {
@@ -88,7 +92,9 @@ describe('SentryErrorHandler', () => {
8892
createErrorHandler().handleError(err);
8993

9094
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
91-
expect(captureExceptionSpy).toHaveBeenCalledWith(err, { mechanism: { handled: false, type: 'angular' } });
95+
expect(captureExceptionSpy).toHaveBeenCalledWith(err, {
96+
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
97+
});
9298
});
9399

94100
it('extracts an error-like object without stack', () => {
@@ -169,7 +175,9 @@ describe('SentryErrorHandler', () => {
169175
createErrorHandler().handleError(err);
170176

171177
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
172-
expect(captureExceptionSpy).toHaveBeenCalledWith(err, { mechanism: { handled: false, type: 'angular' } });
178+
expect(captureExceptionSpy).toHaveBeenCalledWith(err, {
179+
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
180+
});
173181
});
174182

175183
it('extracts an instance of class not extending Error but that has an error-like shape', () => {
@@ -178,7 +186,9 @@ describe('SentryErrorHandler', () => {
178186
createErrorHandler().handleError(err);
179187

180188
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
181-
expect(captureExceptionSpy).toHaveBeenCalledWith(err, { mechanism: { handled: false, type: 'angular' } });
189+
expect(captureExceptionSpy).toHaveBeenCalledWith(err, {
190+
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
191+
});
182192
});
183193

184194
it('extracts an instance of a class that does not extend Error and does not have an error-like shape', () => {
@@ -251,7 +261,9 @@ describe('SentryErrorHandler', () => {
251261
createErrorHandler().handleError(err);
252262

253263
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
254-
expect(captureExceptionSpy).toHaveBeenCalledWith(ngErr, { mechanism: { handled: false, type: 'angular' } });
264+
expect(captureExceptionSpy).toHaveBeenCalledWith(ngErr, {
265+
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
266+
});
255267
});
256268

257269
it('extracts an `HttpErrorResponse` with `Error`', () => {
@@ -261,7 +273,9 @@ describe('SentryErrorHandler', () => {
261273
createErrorHandler().handleError(err);
262274

263275
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
264-
expect(captureExceptionSpy).toHaveBeenCalledWith(httpErr, { mechanism: { handled: false, type: 'angular' } });
276+
expect(captureExceptionSpy).toHaveBeenCalledWith(httpErr, {
277+
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
278+
});
265279
});
266280

267281
it('extracts an `HttpErrorResponse` with `ErrorEvent`', () => {
@@ -431,7 +445,9 @@ describe('SentryErrorHandler', () => {
431445
createErrorHandler().handleError(err);
432446

433447
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
434-
expect(captureExceptionSpy).toHaveBeenCalledWith(err, { mechanism: { handled: false, type: 'angular' } });
448+
expect(captureExceptionSpy).toHaveBeenCalledWith(err, {
449+
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
450+
});
435451
});
436452

437453
it('extracts an `HttpErrorResponse` with an instance of class not extending Error but that has an error-like shape', () => {
@@ -441,7 +457,9 @@ describe('SentryErrorHandler', () => {
441457
createErrorHandler().handleError(err);
442458

443459
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
444-
expect(captureExceptionSpy).toHaveBeenCalledWith(innerErr, { mechanism: { handled: false, type: 'angular' } });
460+
expect(captureExceptionSpy).toHaveBeenCalledWith(innerErr, {
461+
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
462+
});
445463
});
446464

447465
it('extracts an `HttpErrorResponse` with an instance of a class that does not extend Error and does not have an error-like shape', () => {

0 commit comments

Comments
 (0)