Skip to content

Commit b5ad491

Browse files
Lms24lforst
andcommitted
feat(angular): Log warning if SDK is used with an older Angular version than officially supported (#4964)
introduces a check in the Angular SDK's init function to check if the Angular version it is used with is older than our minimum supported version (Angular 10). In case it is, a warning will be logged. adjusts the migration and readme docs to reflect better our officially supported Angular versions and what to do if users are using an older Angular version if they experience problems (i.e. stay on v6). Co-authored-by: Luca Forstner <[email protected]>
1 parent 9ded65e commit b5ad491

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

MIGRATION.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ The Sentry Angular SDK (`@sentry/angular`) is now compiled with the Angular comp
129129

130130
### Angular Version Compatibility
131131

132-
Given the forward compatibility of the Angular compiler, v7 of our SDK will only work with Angular 10 and above. Previously, it was possible to use the SDK with versions <10, although we officially only supported Angular 10-13 as peer dependencies. If you are using Angular <10 in your project, we recommend staying on the latest 6.x version until you can upgrade your Angular version.
132+
As in v6, we continue to list Angular 10-13 in our peer dependencies, meaning that these are the Angular versions we officially support.
133+
If you are using v7 with Angular <10 in your project and you experience problems, we recommend staying on the latest 6.x
134+
version until you can upgrade your Angular version. As v7 of our SDK is compiled with the Angular 10 compiler and we upgraded
135+
our Typescript version, the SDK will work with Angular 10 and above. Tests have shown that Angular 9 seems to work as well
136+
(use at your own risk) but we recommend upgrading to a more recent Angular version.
133137

134138
### Import Changes
135139

packages/angular/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
## Angular Version Compatibility
1616

17-
For Angular 10-13 use the latest version of the Sentry Angular SDK. In case
18-
you are using an Angular 9 or earlier, use version 6.x of the SDK as newer versions do not support Angular <10.
17+
The latest version of this SDK officially supports Angular 10-13. If you are using an older version of Angular and experience problems with the Angular SDK, we recommend downgrading the SDK to version 6.x.
1918

2019
## General
2120

packages/angular/src/constants.ts

+5
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ export const ANGULAR_ROUTING_OP = 'ui.angular.routing';
33
export const ANGULAR_INIT_OP = 'ui.angular.init';
44

55
export const ANGULAR_OP = 'ui.angular';
6+
7+
/**
8+
* Minimum Angular version this SDK supports
9+
*/
10+
export const ANGULAR_MINIMUM_VERSION = 10;

packages/angular/src/sdk.ts

+20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import { VERSION } from '@angular/core';
12
import { BrowserOptions, init as browserInit, SDK_VERSION } from '@sentry/browser';
3+
import { logger } from '@sentry/utils';
4+
5+
import { ANGULAR_MINIMUM_VERSION } from './constants';
6+
import { IS_DEBUG_BUILD } from './flags';
27

38
/**
49
* Inits the Angular SDK
@@ -15,5 +20,20 @@ export function init(options: BrowserOptions): void {
1520
],
1621
version: SDK_VERSION,
1722
};
23+
checkAngularVersion();
1824
browserInit(options);
1925
}
26+
27+
function checkAngularVersion(): void {
28+
if (VERSION && VERSION.major) {
29+
const major = parseInt(VERSION.major, 10);
30+
if (major < ANGULAR_MINIMUM_VERSION) {
31+
IS_DEBUG_BUILD &&
32+
logger.warn(
33+
`The Sentry SDK does not officially support Angular ${major}.`,
34+
`This version of the Sentry SDK supports Angular ${ANGULAR_MINIMUM_VERSION} and above.`,
35+
'Please consider upgrading your Angular version or downgrading the Sentry SDK.',
36+
);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)