|
1 | 1 | --- |
2 | 2 | title: Angular |
3 | | -description: 'Angular is a web framework that empowers developers to build fast, reliable applications. Learn how to set it up with Sentry.' |
| 3 | +description: 'Learn how to set up Sentry in your Angular application and capture your first errors.' |
4 | 4 | sdk: sentry.javascript.angular |
5 | 5 | categories: |
6 | 6 | - javascript |
7 | 7 | - browser |
8 | 8 | --- |
9 | 9 |
|
10 | | -<PlatformContent includePath="getting-started-primer" /> |
| 10 | +## Prerequisites |
11 | 11 |
|
12 | | -<PlatformContent includePath="getting-started-prerequisites" /> |
| 12 | +You need: |
13 | 13 |
|
14 | | -## Features |
| 14 | +- A Sentry [account](https://sentry.io/signup/) and [project](/product/projects/) |
| 15 | +- Your application up and running |
| 16 | +- Angular version `17.0.0` or above |
15 | 17 |
|
16 | | -In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/). You can also get to the root of an error or performance issue faster, by watching a video-like reproduction of a user session with [session replay](/product/explore/session-replay/web/getting-started/). |
| 18 | +<Expandable level="warning" title="Are you using Angular 16 or older?"> |
17 | 19 |
|
18 | | -Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below. |
| 20 | +If you're using Angular 16 or older, install and <PlatformLink to="/manual-setup">Set Up the SDK Manually</PlatformLink>. The Sentry Angular SDK still works for Angular versions 14 and newer but the installation wizards requires |
| 21 | +at least Angular 17. |
19 | 22 |
|
20 | | -## Install |
| 23 | +</Expandable> |
21 | 24 |
|
22 | | -<OnboardingOptionButtons options={["error-monitoring", "performance", "session-replay"]} /> |
| 25 | +## Step 1: Install |
23 | 26 |
|
24 | | -Sentry captures data by using an SDK within your application’s runtime. |
| 27 | +To install Sentry, run the following command within your project: |
25 | 28 |
|
26 | | -```bash {tabTitle:npm} |
27 | | -npm install @sentry/angular --save |
| 29 | +```bash |
| 30 | +npx @sentry/wizard@latest -i angular |
28 | 31 | ``` |
29 | 32 |
|
30 | | -```bash {tabTitle:yarn} |
31 | | -yarn add @sentry/angular |
32 | | -``` |
| 33 | +The wizard then guides you through the setup process, asking you to enable additional (optional) Sentry features for your application beyond error monitoring. |
33 | 34 |
|
34 | | -```bash {tabTitle:pnpm} |
35 | | -pnpm add @sentry/angular |
36 | | -``` |
| 35 | +<PlatformContent includePath="getting-started-features-expandable" /> |
37 | 36 |
|
38 | | -### Angular Version Compatibility |
| 37 | +This guide assumes that you enable all features and allow the wizard to add an example component to your application. You can add or remove features at any time, but setting them up now will save you the effort of configuring them manually later. |
39 | 38 |
|
40 | | -In its current major version, the Sentry Angular SDK only supports Angular 14 and newer. |
| 39 | +<Expandable title="What does the installation wizard change inside your application?"> |
41 | 40 |
|
42 | | -If you're using an older version of Angular, you also need to use an older version of the SDK. See the table below for compatibility guidance: |
| 41 | +- Adds a `Sentry.init()` call into your `main.ts` file |
| 42 | +- Registers the Sentry `ErrorHandler` and `TraceService` in your `app.config.ts` file |
| 43 | +- Creates `.sentryclirc` with an auth token to upload source maps (this file is automatically added to `.gitignore`) |
| 44 | +- Walks you through enabling source maps upload when making a production build, locally as well as in CI |
| 45 | +- Adds an example component to your application to help verify your Sentry setup |
43 | 46 |
|
44 | | -| Angular version | Recommended Sentry SDK | |
45 | | -| --------------- | ------------------------------------------------------------------------------------------------------- | |
46 | | -| 14 and newer | `@sentry/angular` | |
47 | | -| 12 or 13 | `@sentry/angular-ivy@^7` (see [Note](#what-is-sentryangular-ivy)) \* | |
48 | | -| 10 or 11 | `@sentry/angular@^7` \* | |
49 | | -| 9 and below | `@sentry/angular@^6` \* | |
50 | | -| AngularJS/1.x | `@sentry/browser@^6` with the [AngularJS integration](/platforms/javascript/guides/angular/angular1) \* | |
| 47 | +</Expandable> |
51 | 48 |
|
52 | | -\* These versions of the SDK are no longer maintained or tested. Version 7 might still receive bug fixes but we don't guarantee support. |
| 49 | +## Step 2: Verify |
53 | 50 |
|
54 | | -#### What is `@sentry/angular-ivy`? |
| 51 | +If you haven't tested your Sentry configuration yet, let's do it now. You can confirm that the Sentry SDK is sending data to your Sentry project by using the example component created by the installation wizard: |
55 | 52 |
|
56 | | -The `@sentry/angular-ivy` package was an Ivy-compatible version of `@sentry/angular` in version 7 of the SDK. It's recommended to use this package if you're using Angular 12 or 13 to avoid build-time warnings. |
57 | | -Functionality-wise, it's identical to `@sentry/angular` and you can simply replace all imports of `@sentry/angular` with `@sentry/angular-ivy` in our docs. |
58 | | -Since version 8, `@sentry/angular-ivy` was [removed and merged](./migration/v7-to-v8/#supported-versions) with `@sentry/angular` which is now Ivy-compatible by default. |
| 53 | +1. Open the page you added the example component to in your browser. |
| 54 | +2. Click the "Throw error" button. This triggers an error. |
59 | 55 |
|
60 | | -## Configure |
| 56 | +Sentry captures this error for you. Additionally, the button click starts a trace to measure the time it takes for the error to be thrown. |
61 | 57 |
|
62 | | -Configuration should happen as early as possible in your application's lifecycle. |
| 58 | +<Alert level="success" title="Tip"> |
63 | 59 |
|
64 | | -<PlatformContent includePath="getting-started-config" /> |
| 60 | +Don't forget to explore the example component's code in your project to understand what's happening after your button click. |
65 | 61 |
|
66 | | -<PlatformContent includePath="getting-started-sourcemaps" /> |
| 62 | +</Alert> |
67 | 63 |
|
68 | | -## Verify |
| 64 | +### View Captured Data in Sentry |
69 | 65 |
|
70 | | -This snippet includes an intentional error, so you can test that everything is working as soon as you set it up. |
| 66 | +Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear). |
71 | 67 |
|
72 | | -<PlatformContent includePath="getting-started-verify" /> |
| 68 | +<PlatformContent includePath="getting-started-browser-sandbox-warning" /> |
73 | 69 |
|
74 | | -<Alert> |
| 70 | +<PlatformContent includePath="getting-started-verify-locate-data" /> |
75 | 71 |
|
76 | | -Learn more about manually capturing an error or message in our <PlatformLink to="/usage/">Usage documentation</PlatformLink>. |
| 72 | +## Next Steps |
77 | 73 |
|
78 | | -</Alert> |
| 74 | +At this point, you should have integrated Sentry into Angular application and should already be sending error and tracing data to your Sentry project. |
| 75 | + |
| 76 | +Now's a good time to customize your setup and look into more advanced topics. |
| 77 | +Our next recommended steps for you are: |
| 78 | + |
| 79 | +- Extend Sentry to your backend using one of our [SDKs](/) |
| 80 | +- Continue to <PlatformLink to="/configuration">customize your configuration</PlatformLink> |
| 81 | +- Make use of <PlatformLink to="/features">Angular-specific features</PlatformLink> |
| 82 | +- Learn how to <PlatformLink to="/usage">manually capture errors</PlatformLink> |
| 83 | + |
| 84 | +<Expandable permalink={false} title="Are you having problems setting up the SDK?"> |
| 85 | + |
| 86 | +- If you encountered issues with our installation wizard, try <PlatformLink to="/manual-setup">setting up Sentry manually</PlatformLink> |
| 87 | +- [Get support](https://sentry.zendesk.com/hc/en-us/) |
79 | 88 |
|
80 | | -To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved. |
| 89 | +</Expandable> |
0 commit comments