Repository navigation
Expand file tree
/
Copy pathsdk.ts
More file actions
executable file
·48 lines (41 loc) · 1.76 KB
/
Copy pathsdk.ts
File metadata and controls
executable file
·48 lines (41 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { VERSION } from '@angular/core';
import type { BrowserOptions } from '@sentry/browser';
import { getDefaultIntegrations, init as browserInit, setContext } from '@sentry/browser';
import { applySdkMetadata } from '@sentry/core';
import { logger } from '@sentry/utils';
import { IS_DEBUG_BUILD } from './flags';
/**
* Inits the Angular SDK
*/
export function init(options: BrowserOptions): void {
const opts = {
// 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 !== 'BrowserApiErrors';
}),
...options,
};
applySdkMetadata(opts, 'angular');
checkAndSetAngularVersion();
browserInit(opts);
}
function checkAndSetAngularVersion(): void {
const ANGULAR_MINIMUM_VERSION = 10;
const angularVersion = VERSION && VERSION.major ? parseInt(VERSION.major, 10) : undefined;
if (angularVersion) {
if (angularVersion < ANGULAR_MINIMUM_VERSION) {
IS_DEBUG_BUILD &&
logger.warn(
`The Sentry SDK does not officially support Angular ${angularVersion}.`,
`This version of the Sentry SDK supports Angular ${ANGULAR_MINIMUM_VERSION} and above.`,
'Please consider upgrading your Angular version or downgrading the Sentry SDK.',
);
}
setContext('angular', { version: angularVersion });
}
}