Skip to content

feat(angular): Log warning if SDK is used with an older Angular version than officially supported #4964

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 4 commits into from
Apr 22, 2022
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
6 changes: 5 additions & 1 deletion MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ The Sentry Angular SDK (`@sentry/angular`) is now compiled with the Angular comp

### Angular Version Compatibility

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.
As in v6, we continue to list Angular 10-13 in our peer dependencies, meaning that these are the Angular versions we officially support.
If you are using v7 with Angular <10 in your project and you experience problems, we recommend staying on the latest 6.x
version until you can upgrade your Angular version. As v7 of our SDK is compiled with the Angular 10 compiler and we upgraded
our Typescript version, the SDK will work with Angular 10 and above. Tests have shown that Angular 9 seems to work as well
(use at your own risk) but we recommend upgrading to a more recent Angular version.

### Import Changes

Expand Down
3 changes: 1 addition & 2 deletions packages/angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

## Angular Version Compatibility

For Angular 10-13 use the latest version of the Sentry Angular SDK. In case
you are using an Angular 9 or earlier, use version 6.x of the SDK as newer versions do not support Angular <10.
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.

## General

Expand Down
5 changes: 5 additions & 0 deletions packages/angular/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ export const ANGULAR_ROUTING_OP = 'ui.angular.routing';
export const ANGULAR_INIT_OP = 'ui.angular.init';

export const ANGULAR_OP = 'ui.angular';

/**
* Minimum Angular version this SDK supports
*/
export const ANGULAR_MINIMUM_VERSION = 10;
20 changes: 20 additions & 0 deletions packages/angular/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { VERSION } from '@angular/core';
import { BrowserOptions, init as browserInit, SDK_VERSION } from '@sentry/browser';
import { logger } from '@sentry/utils';

import { ANGULAR_MINIMUM_VERSION } from './constants';
import { IS_DEBUG_BUILD } from './flags';

/**
* Inits the Angular SDK
Expand All @@ -15,5 +20,20 @@ export function init(options: BrowserOptions): void {
],
version: SDK_VERSION,
};
checkAngularVersion();
browserInit(options);
}

function checkAngularVersion(): void {
if (VERSION && VERSION.major) {
const major = parseInt(VERSION.major, 10);
if (major < ANGULAR_MINIMUM_VERSION) {
IS_DEBUG_BUILD &&
logger.warn(
`The Sentry SDK does not officially support Angular ${major}.`,
`This version of the Sentry SDK supports Angular ${ANGULAR_MINIMUM_VERSION} and above.`,
'Please consider upgrading your Angular version or downgrading the Sentry SDK.',
);
}
}
}