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