1 | <p align="center">
|
2 | <a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
|
3 | <img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
|
4 | </a>
|
5 | </p>
|
6 |
|
7 | # Official Sentry SDK for Browsers
|
8 |
|
9 | [![Sauce Test Status](https://saucelabs.com/buildstatus/sentryio)](https://saucelabs.com/u/sentryio)
|
10 | [![npm version](https://img.shields.io/npm/v/@sentry/browser.svg)](https://www.npmjs.com/package/@sentry/browser)
|
11 | [![npm dm](https://img.shields.io/npm/dm/@sentry/browser.svg)](https://www.npmjs.com/package/@sentry/browser)
|
12 | [![npm dt](https://img.shields.io/npm/dt/@sentry/browser.svg)](https://www.npmjs.com/package/@sentry/browser)
|
13 |
|
14 | ## Links
|
15 |
|
16 | - [Official SDK Docs](https://docs.sentry.io/quickstart/)
|
17 | - [TypeDoc](http://getsentry.github.io/sentry-javascript/)
|
18 |
|
19 | ## Usage
|
20 |
|
21 | To use this SDK, call `Sentry.init(options)` as early as possible after loading the page. This will initialize the SDK
|
22 | and hook into the environment. Note that you can turn off almost all side effects using the respective options.
|
23 |
|
24 | ```javascript
|
25 | import * as Sentry from '@sentry/browser';
|
26 |
|
27 | Sentry.init({
|
28 | dsn: '__DSN__',
|
29 | // ...
|
30 | });
|
31 | ```
|
32 |
|
33 | To set context information or send manual events, use the exported functions of `@sentry/browser`. Note that these
|
34 | functions will not perform any action before you have called `Sentry.init()`:
|
35 |
|
36 | ```javascript
|
37 | import * as Sentry from '@sentry/browser';
|
38 |
|
39 | // Set user information, as well as tags and further extras
|
40 | Sentry.configureScope(scope => {
|
41 | scope.setExtra('battery', 0.7);
|
42 | scope.setTag('user_mode', 'admin');
|
43 | scope.setUser({ id: '4711' });
|
44 | // scope.clear();
|
45 | });
|
46 |
|
47 | // Add a breadcrumb for future events
|
48 | Sentry.addBreadcrumb({
|
49 | message: 'My Breadcrumb',
|
50 | // ...
|
51 | });
|
52 |
|
53 | // Capture exceptions, messages or manual events
|
54 | Sentry.captureMessage('Hello, world!');
|
55 | Sentry.captureException(new Error('Good bye'));
|
56 | Sentry.captureEvent({
|
57 | message: 'Manual',
|
58 | stacktrace: [
|
59 | // ...
|
60 | ],
|
61 | });
|
62 | ```
|