|
1 | 1 | --- |
2 | 2 | name: AngularJS |
3 | | -doc_link: https://docs.sentry.io/clients/javascript/integrations/angularjs/ |
| 3 | +doc_link: https://docs.sentry.io/platforms/javascript/guides/angular/angular1/ |
4 | 4 | support_level: production |
5 | 5 | type: framework |
6 | 6 | --- |
7 | 7 |
|
8 | | -### Installation |
| 8 | +Install our Browser Angular SDK using either `yarn` or `npm`: |
9 | 9 |
|
10 | | -Raven.js and the Raven.js Angular plugin are distributed using a few different methods. |
| 10 | +Add the Sentry SDK as a dependency using `yarn` or `npm`: |
11 | 11 |
|
12 | | -#### Using our CDN |
| 12 | +```bash |
| 13 | +# Using yarn |
| 14 | +yarn add @sentry/browser @sentry/integrations |
13 | 15 |
|
14 | | -For convenience, our CDN serves a single, minified JavaScript file containing both Raven.js and the Raven.js AngularJS plugin. It should be included **after** Angular, but **before** your application code. |
15 | | - |
16 | | -Example: |
17 | | - |
18 | | -```html |
19 | | -<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> |
20 | | -<script |
21 | | - src="https://cdn.ravenjs.com/3.26.4/angular/raven.min.js" |
22 | | - crossorigin="anonymous" |
23 | | -></script> |
24 | | -<script> |
25 | | - Raven.config("___PUBLIC_DSN___").install(); |
26 | | -</script> |
27 | | -``` |
28 | | - |
29 | | -Note that this CDN build auto-initializes the Angular plugin. |
30 | | - |
31 | | -#### Using package managers |
32 | | - |
33 | | -Pre-built distributions of Raven.js and the Raven.js AngularJS plugin are available via both Bower and npm. |
34 | | - |
35 | | -##### Bower |
36 | | - |
37 | | -```shell |
38 | | -bower install raven-js --save |
39 | | -``` |
40 | | - |
41 | | -```html |
42 | | -<script src="/bower_components/angular/angular.js"></script> |
43 | | -<script src="/bower_components/raven-js/dist/raven.js"></script> |
44 | | -<script src="/bower_components/raven-js/dist/plugins/angular.js"></script> |
45 | | -<script> |
46 | | - Raven.config("___PUBLIC_DSN___") |
47 | | - .addPlugin(Raven.Plugins.Angular) |
48 | | - .install(); |
49 | | -</script> |
50 | | -``` |
51 | | - |
52 | | -##### npm |
53 | | - |
54 | | -```shell |
55 | | -npm install raven-js --save |
56 | | -``` |
57 | | - |
58 | | -```html |
59 | | -<script src="/node_modules/angular/angular.js"></script> |
60 | | -<script src="/node_modules/raven-js/dist/raven.js"></script> |
61 | | -<script src="/node_modules/raven-js/dist/plugins/angular.js"></script> |
62 | | -<script> |
63 | | - Raven.config("___PUBLIC_DSN___") |
64 | | - .addPlugin(Raven.Plugins.Angular) |
65 | | - .install(); |
66 | | -</script> |
67 | | -``` |
68 | | - |
69 | | -These examples assume that AngularJS is exported globally as _window.angular_. You can alternatively pass a reference to the _angular_ object directly as the second argument to _addPlugin_: |
70 | | - |
71 | | -```javascript |
72 | | -Raven.addPlugin(Raven.Plugins.Angular, angular); |
73 | | -``` |
74 | | - |
75 | | -#### Module loaders (CommonJS) |
76 | | - |
77 | | -Raven and the Raven AngularJS plugin can be loaded using a module loader like Browserify or Webpack. |
78 | | - |
79 | | -```javascript |
80 | | -var angular = require("angular"); |
81 | | -var Raven = require("raven-js"); |
82 | | - |
83 | | -Raven.config("___PUBLIC_DSN___") |
84 | | - .addPlugin(require("raven-js/plugins/angular"), angular) |
85 | | - .install(); |
86 | | -``` |
87 | | - |
88 | | -Note that when using CommonJS-style imports, you must pass a reference to _angular_ as the second argument to _addPlugin_. |
89 | | - |
90 | | -### AngularJS Configuration |
91 | | - |
92 | | -Inside your main AngularJS application module, you need to declare _ngRaven_ as a module dependency: |
93 | | - |
94 | | -```javascript |
95 | | -var myApp = angular.module("myApp", [ |
96 | | - "ngRaven", |
97 | | - "ngRoute", |
98 | | - "myAppControllers", |
99 | | - "myAppFilters", |
100 | | -]); |
| 16 | +# Using npm |
| 17 | +npm install --save @sentry/browser @sentry/integrations |
101 | 18 | ``` |
102 | 19 |
|
103 | | -#### Module loaders (CommonJS) {#id1} |
104 | | - |
105 | | -The raven angular module can be loaded using a module loader like Browserify or Webpack. |
| 20 | +`init` the Sentry Browser SDK as soon as possible during your page load, before initializing Angular: |
106 | 21 |
|
107 | 22 | ```javascript |
108 | | -var angular = require("angular"); |
109 | | -var ngRaven = require("raven-js/plugins/angular").moduleName; |
110 | | -var ngRoute = require("angular-route"); |
111 | | - |
112 | | -var myAppFilters = require("./myAppFilters"); |
113 | | -var myAppControllers = require("./myAppControllers"); |
114 | | -var moduleName = "myApp"; |
115 | | - |
116 | | -angular.module(moduleName, [ngRaven, ngRoute, myAppControllers, myAppFilters]); |
117 | | - |
118 | | -module.exports = moduleName; |
| 23 | +import angular from "angular"; |
| 24 | +import * as Sentry from "@sentry/browser"; |
| 25 | +import { Integrations } from "@sentry/tracing"; |
| 26 | +import { Angular as AngularIntegration } from "@sentry/integrations"; |
| 27 | + |
| 28 | +Sentry.init({ |
| 29 | + dsn: "___PUBLIC_DSN___", |
| 30 | + autoSessionTracking: true, |
| 31 | + integrations: [ |
| 32 | + new AngularIntegration(), |
| 33 | + new Integrations.BrowserTracing({ |
| 34 | + tracingOrigins: ["localhost", "https://yourserver.io/api"], |
| 35 | + }), |
| 36 | + ], |
| 37 | + |
| 38 | + tracesSampleRate: 1.0, |
| 39 | +}); |
| 40 | + |
| 41 | +// Finally require ngSentry as a dependency in your application module. |
| 42 | +angular.module("yourApplicationModule", ["ngSentry"]); |
119 | 43 | ``` |
120 | | - |
121 | | -<!-- TODO-ADD-VERIFICATION-EXAMPLE --> |
0 commit comments