Skip to content

Commit 6957209

Browse files
PeloWriterdcramerHazAT
authored
Global Getting Started (#2336)
* Update JS index page and JS includes * Create common page for Getting Started * Add Angular includes and remove Angular getting ststarted index page * Update src/platforms/common/usage/index.mdx Co-authored-by: David Cramer <[email protected]> * fix: Dont error in GuideGrid when using a guide itself * create test content, apply code review comments * update angular includes * move content into troubleshooting * Update src/includes/getting-started-config/javascript.angular.mdx Co-authored-by: Daniel Griesser <[email protected]> * fix heading * Create tabs to allow selection of errors or errors and performance * Add sample rate configuration note * update configuration of sample rate * Remove tab idea as the design won't scale * fix: Angular verify * edits to clarify * edits to enable next step page display * edits from review * Update src/includes/getting-started-config/javascript.angular.mdx Co-authored-by: Daniel Griesser <[email protected]> Co-authored-by: David Cramer <[email protected]> Co-authored-by: David Cramer <[email protected]> Co-authored-by: Daniel Griesser <[email protected]>
1 parent 35c345e commit 6957209

File tree

20 files changed

+220
-344
lines changed

20 files changed

+220
-344
lines changed

src/components/guideGrid.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ type Props = {
1010

1111
export default ({ platform }: Props): JSX.Element => {
1212
const currentPlatform = getPlatform(platform) as Platform;
13+
// platform might actually not be a platform, so lets handle that case gracefully
14+
if (!currentPlatform.guides) {
15+
return null;
16+
}
1317

1418
return (
1519
<ul>

src/includes/capture-error/javascript.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ try {
99
Sentry.captureException(err);
1010
}
1111
```
12+
13+
Learn more about how to manually capture errors or enable message capture with Sentry's SDK in <PlatformLink to="/usage/">our documentation on Usage</PlatformLink>.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<GuideGrid />
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Using a framework? Take a look at our specific guides to get started.
2+
3+
<GuideGrid platform="javascript" />
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
This snippet includes automatic instrumentation to [monitor the performance](/platforms/javascript/performance/) of your application, which registers and configures the Tracing integration, including custom Angular routing instrumentation.
2+
3+
**Note:** To reduce the volume of performance data captured, or disable it entirely, change `tracesSampleRate` to a value between 0 and 1 in production.
4+
5+
```javascript
6+
import { enableProdMode } from "@angular/core";
7+
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
8+
import * as Sentry from "@sentry/angular";
9+
import { Integrations } from "@sentry/tracing";
10+
import { AppModule } from "./app/app.module";
11+
12+
Sentry.init({
13+
dsn: "___PUBLIC_DSN___" ,
14+
integrations: [
15+
new Integrations.BrowserTracing({
16+
tracingOrigins: ["localhost", "https://yourserver.io/api"],
17+
routingInstrumentation: Sentry.routingInstrumentation,
18+
}),
19+
],
20+
tracesSampleRate: 1.0, // We recommend adjusting this in production
21+
});
22+
23+
24+
platformBrowserDynamic()
25+
.bootstrapModule(AppModule)
26+
.then(success => console.log(`Bootstrap success`))
27+
.catch(err => console.error(err));
28+
```
29+
30+
You can also configure `@sentry/angular` to catch any Angular-specific exceptions reported through the [@angular/core/ErrorHandler](https://angular.io/api/core/ErrorHandler) provider.
31+
32+
`@sentry/angular` exports a Trace Service, Directive, and Decorators that leverages the `@sentry/tracing`, Sentry's Tracing integration, to add Angular-related spans to transactions. The service itself tracks route changes and durations, where directive and decorators are tracking component initializations.
33+
34+
### Automatically Send Errors with `ErrorHandler`
35+
36+
`@sentry/angular` exports a function to instantiate an `ErrorHandler` provider that will automatically send JavaScript errors captured by the Angular's error handler.
37+
38+
```javascript
39+
import { NgModule, ErrorHandler } from "@angular/core";
40+
import * as Sentry from "@sentry/angular";
41+
42+
@NgModule({
43+
// ...
44+
providers: [
45+
{
46+
provide: ErrorHandler,
47+
useValue: Sentry.createErrorHandler({
48+
showDialog: true,
49+
}),
50+
},
51+
],
52+
// ...
53+
})
54+
export class AppModule {}
55+
```
56+
57+
You can configure the behavior of `createErrorHandler`. For more details see the `ErrorHandlerOptions` interface in [our repository](https://github.com/getsentry/sentry-javascript/blob/master/packages/angular/src/errorhandler.ts).
58+
59+
### Register `TraceService`
60+
61+
In Angular's DI system, register `TraceService` as a provider with a `Router` as its dependency:
62+
63+
```javascript
64+
import { NgModule } from "@angular/core";
65+
import { Router } from "@angular/router";
66+
import * as Sentry from "@sentry/angular";
67+
68+
@NgModule({
69+
// ...
70+
providers: [
71+
{
72+
provide: Sentry.TraceService,
73+
deps: [Router],
74+
},
75+
],
76+
// ...
77+
})
78+
export class AppModule {}
79+
```
80+
Then, either require the `TraceService` from inside `AppModule` or use `APP_INITIALIZER` to force instantiate Tracing.
81+
```javascript
82+
@NgModule({
83+
// ...
84+
})
85+
export class AppModule {
86+
constructor(trace: Sentry.TraceService) {}
87+
}
88+
```
89+
90+
or
91+
92+
```javascript
93+
import { APP_INITIALIZER } from "@angular/core";
94+
@NgModule({
95+
// ...
96+
providers: [
97+
{
98+
provide: APP_INITIALIZER,
99+
useFactory: () => () => {},
100+
deps: [Sentry.TraceService],
101+
multi: true,
102+
},
103+
],
104+
// ...
105+
})
106+
export class AppModule {}
107+
```
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
You should `init` the Sentry Browser SDK as soon as possible during your page load:
1+
This snippet:
2+
- Uses `process.env.npm_package_version` to configure the version of your application. Learn more about [releases](/product/releases/) and how they are used with [source maps](/platforms/javascript/sourcemaps/).
3+
- Instruments your SDK to [monitor the performance](/platforms/javascript/performance/) of browser applications.
24

3-
```javascript {tabTitle:ESM}
4-
import * as Sentry from "@sentry/browser";
5+
<Note>
6+
<markdown>
57

6-
Sentry.init({
7-
dsn: "___PUBLIC_DSN___",
8-
});
9-
```
8+
To reduce the volume of performance data captured, or disable it entirely, change `tracesSampleRate` to a value between 0 and 1 in production.
9+
10+
</markdown>
11+
</Note>
1012

11-
```javascript {tabTitle:CDN}
13+
```javascript {tabTitle: ESM}
14+
import * as Sentry from "@sentry/browser";
15+
import { Integrations } from "@sentry/tracing";
1216
Sentry.init({
1317
dsn: "___PUBLIC_DSN___",
18+
release: "my-project-name@" + process.env.npm_package_version, // To set your release version
19+
integrations: [new Integrations.BrowserTracing()],
20+
tracesSampleRate: 1.0, // We recommend adjusting this in production
1421
});
1522
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```bash {tabTitle:npm}
2+
npm install --save @sentry/angular
3+
```
4+
5+
```bash {tabTitle:Yarn}
6+
yarn add @sentry/angular
7+
```
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
Add the `@sentry/browser` dependency:
2-
31
```bash {tabTitle: ESM}
42
# Using yarn
5-
$ yarn add @sentry/browser
6-
3+
$ yarn add @sentry/browser @sentry/tracing
74
# Using npm
8-
$ npm install @sentry/browser
5+
$ npm install --save @sentry/browser @sentry/tracing
96
```
107

11-
```html {tabTitle: CDN}
12-
<script
13-
src="https://browser.sentry-cdn.com/{{ packages.version('sentry.javascript.browser') }}/bundle.min.js"
14-
integrity="sha384-{{ packages.checksum('sentry.javascript.browser', 'bundle.min.js', 'sha384-base64') }}"
15-
crossorigin="anonymous"
16-
></script>
17-
```
8+
<Note>
9+
<markdown>
10+
11+
We also support alternate [installation methods](/platforms/javascript/install/).
12+
13+
</markdown>
14+
</Note>

src/includes/getting-started-next-steps/javascript.mdx

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
One way to verify your setup is by intentionally causing an error that breaks your application.
2-
3-
Calling an undefined function will throw an exception:
4-
5-
```js
1+
```javascript
62
myUndefinedFunction();
73
```
8-
9-
You can verify the function caused an error by checking your browser console.

0 commit comments

Comments
 (0)